Changes in / [39cf5cc:793eb2f]
- Files:
-
- 4 edited
-
libcfa/src/enum.cfa (modified) (2 diffs)
-
src/ControlStruct/TranslateEnumRange.cpp (modified) (6 diffs)
-
src/Parser/StatementNode.cpp (modified) (1 diff)
-
src/Parser/parser.yy (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r39cf5cc r793eb2f 1 1 #include "enum.hfa" 2 2 #include "fstream.hfa" 3 #include <string.h>4 3 5 4 #pragma GCC visibility push(default) … … 11 10 int args = fmt( is, "%255s", val ); 12 11 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 13 for ( s; E ) {14 if ( strcmp(val, label( s )) == 0) { e = s; break; }15 } else {16 fprintf( stderr, "invalid enumeration constant\n" );17 abort(); // cannot use abort stream18 } // for12 // for ( s; E ) { 13 // if ( val == label( s ) ) { e = s; break; } 14 // } else { 15 // fprintf( stderr, "invalid enumeration constant\n" ); 16 // abort(); // cannot use abort stream 17 // } // for 19 18 return is; 20 19 } -
src/ControlStruct/TranslateEnumRange.cpp
r39cf5cc r793eb2f 22 22 auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>(); 23 23 auto type = typeExpr->type; 24 auto inits = stmt->inits; 25 auto enumInst = type.strict_as<ast::EnumInstType>(); 26 auto enumDecl = enumInst->base; 24 27 25 28 auto objInit = stmt->inits.front(); 29 auto initLocation = objInit->location; 30 auto rangeLocation = stmt->range_over->location; 26 31 assert( stmt->inits.size() == 1 ); 27 32 … … 42 47 const ast::Stmt* addInit::postvisit( const ast::ForStmt * stmt ) { 43 48 if ( stmt->range_over ) { 49 auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>(); 50 auto type = typeExpr->type; 44 51 auto inits = stmt->inits; 52 auto enumInst = type.strict_as<ast::EnumInstType>(); 53 auto enumDecl = enumInst->base; 54 45 55 auto init = stmt->inits.front(); 46 56 … … 50 60 if ( !objDecl->init ) { 51 61 auto location = stmt->location; 62 // auto newInit = new ast::SingleInit( location, new ast::NameExpr( location, enumDecl->members.front()->name ) ); 52 63 ast::SingleInit * newInit = new ast::SingleInit( location, 53 stmt->is_inc? 54 ast::UntypedExpr::createCall( location, "lowerBound", {} ): 55 ast::UntypedExpr::createCall( location, "upperBound", {} ), 56 ast::ConstructFlag::MaybeConstruct 57 ); 64 new ast::NameExpr( location, 65 stmt->is_inc? enumDecl->members.front()->name: enumDecl->members.back()->name ) ); 58 66 auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit ); 59 67 auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit ); … … 72 80 auto initDecl = declStmt->decl.strict_as<ast::ObjectDecl>(); 73 81 auto indexName = initDecl->name; 82 83 auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>(); 84 auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>(); 85 auto enumDecl = enumInst->base; 74 86 75 87 // Both inc and dec check if the current posn less than the number of enumerator … … 78 90 ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location, 79 91 "?<=?", 80 { new ast::NameExpr( location, indexName ), 81 ast::UntypedExpr::createCall( location, "upperBound", {} ) }); 92 {new ast::CastExpr(location, 93 new ast::NameExpr( location, indexName ), 94 new ast::BasicType( ast::BasicKind::UnsignedInt 95 ),ast::GeneratedFlag::ExplicitCast), 96 ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 ) }); 82 97 auto increment = ast::UntypedExpr::createCall( location, 83 stmt->is_inc? "succ": "pred", 84 { new ast::NameExpr( location, indexName ) }); 98 stmt->is_inc? "succ": "pred",{ 99 new ast::NameExpr( location, indexName ) 100 }); 85 101 auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment ); 86 102 auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition ); … … 90 106 91 107 void translateEnumRange( ast::TranslationUnit & translationUnit ) { 108 ast::Pass<addInitType>::run( translationUnit ); 92 109 ast::Pass<addInit>::run( translationUnit ); 93 110 ast::Pass<translateEnumRangeCore>::run( translationUnit ); -
src/Parser/StatementNode.cpp
r39cf5cc r793eb2f 216 216 return new ast::ForStmt( location, 217 217 std::move( astinit ), 218 range_over, forctl->kind == OperKinds::L EThan,218 range_over, forctl->kind == OperKinds::LThan, 219 219 buildMoveSingle( stmt ), 220 220 buildMoveOptional( else_ ) -
src/Parser/parser.yy
r39cf5cc r793eb2f 275 275 } // forCtrl 276 276 277 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, OperKinds compop, ExpressionNode * range_over_expr, DeclarationNode * type ) { 278 assert( compop == OperKinds::LEThan || compop == OperKinds::GEThan ); 277 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, __attribute__((unused)) OperKinds compop, ExpressionNode * range_over_expr ) { 279 278 if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) { 280 DeclarationNode * indexDecl = 281 DeclarationNode::newName( new std::string(identifier->name) )->addType( type);279 DeclarationNode * indexDecl = DeclarationNode::newName( new std::string(identifier->name) ); 280 assert( range_over_expr ); 282 281 return new ForCtrl( new StatementNode( indexDecl ), range_over_expr, compop ); 283 282 } else { … … 1606 1605 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; } 1607 1606 1608 | comma_expression ';' type_type_specifier// CFA, enum type1609 { 1610 $$ = enumRangeCtrl( $1, OperKinds::LEThan, new ExpressionNode( new ast::TypeExpr( yylloc, $3-> clone()->buildType() ) ), $3);1607 | comma_expression ';' enum_key // CFA, enum type 1608 { 1609 $$ = enumRangeCtrl( $1, OperKinds::LEThan, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) ); 1611 1610 } 1612 1611 | comma_expression ';' downupdowneq enum_key // CFA, enum type, reverse direction … … 1616 1615 $3 = OperKinds::GEThan; 1617 1616 } // if 1618 $$ = enumRangeCtrl( $1, $3, new ExpressionNode( new ast::TypeExpr( yylloc, $4-> clone()->buildType() ) ), $4);1617 $$ = enumRangeCtrl( $1, $3, new ExpressionNode( new ast::TypeExpr( yylloc, $4->buildType() ) ) ); 1619 1618 } 1620 1619 ; … … 1622 1621 enum_key: 1623 1622 type_name 1624 { typedefTable.makeTypedef( *$1->symbolic.name, "enum_type_nobody 1" ); 1625 $$ = DeclarationNode::newEnum( $1->symbolic.name, nullptr, false, false ); } 1623 { $$ = DeclarationNode::newEnum( $1->symbolic.name, nullptr, false, false ); } 1626 1624 | ENUM identifier 1627 { typedefTable.makeTypedef( *$2, "enum_type_nobody 2" ); 1628 $$ = DeclarationNode::newEnum( $2, nullptr, false, false ); } 1625 { $$ = DeclarationNode::newEnum( $2, nullptr, false, false ); } 1629 1626 | ENUM type_name 1630 { typedefTable.makeTypedef( *$2->symbolic.name, "enum_type_nobody 3" ); 1631 $$ = DeclarationNode::newEnum( $2->symbolic.name, nullptr, false, false ); } 1627 { $$ = DeclarationNode::newEnum( $2->symbolic.name, nullptr, false, false ); } 1632 1628 ; 1633 1629
Note:
See TracChangeset
for help on using the changeset viewer.