Changes in / [332e93a:985ff5f]
- Files:
-
- 3 deleted
- 19 edited
-
libcfa/src/parseargs.cfa (modified) (2 diffs)
-
src/AST/Decl.cpp (modified) (1 diff)
-
src/AST/Decl.hpp (modified) (3 diffs)
-
src/AST/Util.cpp (modified) (2 diffs)
-
src/CodeGen/CodeGenerator.cpp (modified) (4 diffs)
-
src/CodeGen/CodeGenerator.hpp (modified) (1 diff)
-
src/CodeGen/GenType.cpp (modified) (2 diffs)
-
src/CodeGen/Generate.cpp (modified) (2 diffs)
-
src/Concurrency/Actors.cpp (modified) (15 diffs)
-
src/InitTweak/GenInit.cpp (modified) (1 diff)
-
src/Parser/TypeData.cpp (modified) (1 diff)
-
src/ResolvExpr/CastCost.cpp (modified) (1 diff)
-
src/ResolvExpr/CommonType.cpp (modified) (2 diffs)
-
src/ResolvExpr/ConversionCost.cpp (modified) (8 diffs)
-
src/ResolvExpr/ResolveTypeof.cpp (modified) (2 diffs)
-
src/Validate/ImplementEnumFunc.cpp (modified) (4 diffs)
-
tests/.expect/zero_one-ERR1.txt (deleted)
-
tests/.expect/zero_one.txt (modified) (1 diff)
-
tests/Makefile.am (modified) (1 diff)
-
tests/bugs/238.cfa (deleted)
-
tests/bugs/50.cfa (deleted)
-
tests/zero_one.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseargs.cfa
r332e93a r985ff5f 73 73 //----------------------------------------------------------------------------- 74 74 // Parsing args 75 forall([opt_count]) 76 void parse_args( const array( cfa_option, opt_count ) & options, const char * usage, char ** & left ) { 77 if ( 0p != &cfa_args_argc ) { 78 parse_args( cfa_args_argc, cfa_args_argv, options, usage, left ); 79 } else { 80 char * temp[1] = { 0p }; 81 parse_args(0, temp, options, usage, left ); 82 } 83 } 84 85 forall([opt_count]) 86 void parse_args( 87 int argc, 88 char * argv[], 89 const array( cfa_option, opt_count ) & options, 90 const char * usage, 91 char ** & left 92 ) { 93 check_args( options ); 94 95 int maxv = 'h'; 96 char optstring[(opt_count * 3) + 2] = { '\0' }; 97 { 98 int idx = 0; 99 for ( i; opt_count ) { 100 if ( options[i].short_name ) { 101 maxv = max( options[i].short_name, maxv ); 102 optstring[idx] = options[i].short_name; 103 idx++; 104 if ( (intptr_t)options[i].parse != (intptr_t)parse_settrue 105 && ((intptr_t)options[i].parse) != ((intptr_t)parse_setfalse) ) { 106 optstring[idx] = ':'; 75 forall([opt_count]) { 76 void parse_args( const array( cfa_option, opt_count ) & options, const char * usage, char ** & left ) { 77 if ( 0p != &cfa_args_argc ) { 78 parse_args( cfa_args_argc, cfa_args_argv, options, usage, left ); 79 } else { 80 char * temp[1] = { 0p }; 81 parse_args(0, temp, options, usage, left ); 82 } 83 } 84 85 void parse_args( 86 int argc, 87 char * argv[], 88 const array( cfa_option, opt_count ) & options, 89 const char * usage, 90 char ** & left 91 ) { 92 check_args( options ); 93 94 int maxv = 'h'; 95 char optstring[(opt_count * 3) + 2] = { '\0' }; 96 { 97 int idx = 0; 98 for ( i; opt_count ) { 99 if ( options[i].short_name ) { 100 maxv = max( options[i].short_name, maxv ); 101 optstring[idx] = options[i].short_name; 102 idx++; 103 if ( (intptr_t)options[i].parse != (intptr_t)parse_settrue 104 && ((intptr_t)options[i].parse) != ((intptr_t)parse_setfalse) ) { 105 optstring[idx] = ':'; 106 idx++; 107 } 108 } 109 } 110 optstring[idx+0] = 'h'; 111 optstring[idx+1] = '\0'; 112 } 113 114 struct option optarr[opt_count + 2]; 115 { 116 int idx = 0; 117 for ( i; opt_count ) { 118 if ( options[i].long_name ) { 119 // we don't have the mutable keyword here, which is really what we would want 120 int & val_ref = (int &)(const int &)options[i].val; 121 val_ref = (options[i].short_name != '\0') ? ((int)options[i].short_name) : ++maxv; 122 123 optarr[idx].name = options[i].long_name; 124 optarr[idx].flag = 0p; 125 optarr[idx].val = options[i].val; 126 if ( ((intptr_t)options[i].parse) == ((intptr_t)parse_settrue) 127 || ((intptr_t)options[i].parse) == ((intptr_t)parse_setfalse) ) { 128 optarr[idx].has_arg = no_argument; 129 } else { 130 optarr[idx].has_arg = required_argument; 131 } 107 132 idx++; 108 133 } 109 134 } 110 } 111 optstring[idx+0] = 'h'; 112 optstring[idx+1] = '\0'; 113 } 114 115 struct option optarr[opt_count + 2]; 116 { 117 int idx = 0; 118 for ( i; opt_count ) { 119 if ( options[i].long_name ) { 120 // we don't have the mutable keyword here, which is really what we would want 121 int & val_ref = (int &)(const int &)options[i].val; 122 val_ref = (options[i].short_name != '\0') ? ((int)options[i].short_name) : ++maxv; 123 124 optarr[idx].name = options[i].long_name; 125 optarr[idx].flag = 0p; 126 optarr[idx].val = options[i].val; 127 if ( ((intptr_t)options[i].parse) == ((intptr_t)parse_settrue) 128 || ((intptr_t)options[i].parse) == ((intptr_t)parse_setfalse) ) { 129 optarr[idx].has_arg = no_argument; 130 } else { 131 optarr[idx].has_arg = required_argument; 132 } 133 idx++; 135 optarr[idx+0].[name, has_arg, flag, val] = ["help", no_argument, 0, 'h']; 136 optarr[idx+1].[name, has_arg, flag, val] = [0, no_argument, 0, 0]; 137 } 138 139 FILE * out = stderr; 140 NEXT_ARG: 141 for () { 142 int idx = 0; 143 int opt = getopt_long( argc, argv, optstring, optarr, &idx ); 144 switch( opt ) { 145 case -1: 146 if ( &left != 0p ) left = argv + optind; 147 return; 148 case 'h': 149 out = stdout; 150 case '?': 151 usage( argv[0], options, usage, out ); 152 default: 153 for ( i; opt_count ) { 154 if ( opt == options[i].val ) { 155 const char * arg = optarg ? optarg : ""; 156 if ( arg[0] == '=' ) { arg++; } 157 // work around for some weird bug 158 void * variable = options[i].variable; 159 bool (*parse_func)(const char *, void * ) = options[i].parse; 160 bool success = parse_func( arg, variable ); 161 if ( success ) continue NEXT_ARG; 162 163 fprintf( out, "Argument '%s' for option %c could not be parsed\n\n", arg, (char)opt ); 164 usage( argv[0], options, usage, out ); 165 } 166 } 167 abort( "Internal parse arg error\n" ); 134 168 } 135 } 136 optarr[idx+0].[name, has_arg, flag, val] = ["help", no_argument, 0, 'h']; 137 optarr[idx+1].[name, has_arg, flag, val] = [0, no_argument, 0, 0]; 138 } 139 140 FILE * out = stderr; 141 NEXT_ARG: 142 for () { 143 int idx = 0; 144 int opt = getopt_long( argc, argv, optstring, optarr, &idx ); 145 switch( opt ) { 146 case -1: 147 if ( &left != 0p ) left = argv + optind; 148 return; 149 case 'h': 150 out = stdout; 151 case '?': 152 usage( argv[0], options, usage, out ); 153 default: 154 for ( i; opt_count ) { 155 if ( opt == options[i].val ) { 156 const char * arg = optarg ? optarg : ""; 157 if ( arg[0] == '=' ) { arg++; } 158 // work around for some weird bug 159 void * variable = options[i].variable; 160 bool (*parse_func)(const char *, void * ) = options[i].parse; 161 bool success = parse_func( arg, variable ); 162 if ( success ) continue NEXT_ARG; 163 164 fprintf( out, "Argument '%s' for option %c could not be parsed\n\n", arg, (char)opt ); 165 usage( argv[0], options, usage, out ); 166 } 167 } 168 abort( "Internal parse arg error\n" ); 169 169 170 } 170 171 } … … 239 240 } 240 241 241 forall( [N])242 void print_args_usage( const array(cfa_option, N ) & options, const char * usage, bool error ) {243 usage( cfa_args_argv[0], options, usage, error ? stderr : stdout );244 }245 246 forall([N]) 247 void print_args_usage( int argc, char * argv[], const array( cfa_option, N ) & options, const char * usage, bool error ) { 248 usage( argv[0], options, usage, error ? stderr : stdout );242 forall( [N] ) { 243 void print_args_usage( const array(cfa_option, N ) & options, const char * usage, bool error ) { 244 usage( cfa_args_argv[0], options, usage, error ? stderr : stdout ); 245 } 246 247 void print_args_usage( int argc, char * argv[], const array( cfa_option, N ) & options, const char * usage, bool error ) { 248 usage( argv[0], options, usage, error ? stderr : stdout ); 249 } 249 250 } 250 251 -
src/AST/Decl.cpp
r332e93a r985ff5f 169 169 } 170 170 171 bool EnumDecl::isTyped() const { return base; } 172 173 bool EnumDecl::isOpaque() const { return isCfa && !isTyped(); } 174 171 175 } 172 176 -
src/AST/Decl.hpp
r332e93a r985ff5f 306 306 enum class EnumAttribute{ Value, Posn, Label }; 307 307 308 /// enum declaration `enum Foo { ... };` or `enum(...) Foo { ... };`308 /// enum declaration `enum Foo { ... };` 309 309 class EnumDecl final : public AggregateDecl { 310 310 public: … … 317 317 std::vector< ast::ptr<ast::EnumInstType>> inlinedDecl; // child enums 318 318 319 bool is_c_enum () const { return !isCfa; }320 bool is_opaque_enum() const { return isCfa && nullptr == base; }321 bool is_typed_enum () const { return isCfa && nullptr != base; }322 323 319 EnumDecl( const CodeLocation& loc, const std::string& name, bool isCfa = false, 324 320 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, … … 335 331 const char * typeString() const override { return aggrString( Enum ); } 336 332 333 bool isTyped() const; 334 bool isOpaque() const; 337 335 private: 338 336 EnumDecl * clone() const override { return new EnumDecl{ *this }; } -
src/AST/Util.cpp
r332e93a r985ff5f 85 85 // Check that `type->returns` corresponds with `decl->returns`. 86 86 assert( type->returns.size() == decl->returns.size() ); 87 }88 89 /// Check that an enumeration has not been made with an inconsistent spec.90 void isEnumerationConsistent( const EnumDecl * node ) {91 if ( node->is_c_enum() ) {92 assert( nullptr == node->base );93 }94 87 } 95 88 … … 142 135 previsit( (const ParseNode *)node ); 143 136 functionDeclMatchesType( node ); 144 }145 146 void previsit( const EnumDecl * node ) {147 previsit( (const ParseNode *)node );148 isEnumerationConsistent( node );149 137 } 150 138 -
src/CodeGen/CodeGenerator.cpp
r332e93a r985ff5f 130 130 // TODO: Which means the ast::Pass is just providing a default no visit? 131 131 visit_children = false; 132 changeState_ArgToIntrinsic(false);133 132 } 134 133 … … 467 466 if ( var->var->linkage == ast::Linkage::Intrinsic && 468 467 ( opInfo = operatorLookup( var->var->name ) ) ) { 469 changeState_ArgToIntrinsic(true);470 468 auto arg = expr->args.begin(); 471 469 switch ( opInfo->type ) { … … 560 558 if ( auto name = expr->func.as<ast::NameExpr>() ) { 561 559 if ( const OperatorInfo * opInfo = operatorLookup( name->name ) ) { 562 changeState_ArgToIntrinsic(true);563 560 auto arg = expr->args.begin(); 564 561 switch ( opInfo->type ) { … … 746 743 extension( expr ); 747 744 const OperatorInfo * opInfo; 748 if ( visitingArgToIntrinsic 749 && options.genC 750 && dynamic_cast<ast::ZeroType const *>( expr->var->get_type() ) ) { 751 // int * p; p = 0; ==> ?=?( p, (zero_t){} ); ==> p = 0; 752 // void f( zero_t z ) { g(z); } ==> g(z); ==> g(z); 753 // (we are at the last '==>') 754 output << "0"; 755 } else if ( expr->var->linkage == ast::Linkage::Intrinsic 745 if ( expr->var->linkage == ast::Linkage::Intrinsic 756 746 && ( opInfo = operatorLookup( expr->var->name ) ) 757 747 && opInfo->type == OT_CONSTANT ) { -
src/CodeGen/CodeGenerator.hpp
r332e93a r985ff5f 181 181 void handleTypedef( ast::NamedTypeDecl const * type ); 182 182 std::string mangleName( ast::DeclWithType const * decl ); 183 184 bool nextVisitedNodeIsArgToIntrinsic = false;185 bool visitingArgToIntrinsic = false;186 void changeState_ArgToIntrinsic( bool newValue ) {187 GuardValue( visitingArgToIntrinsic ) = nextVisitedNodeIsArgToIntrinsic;188 GuardValue( nextVisitedNodeIsArgToIntrinsic ) = newValue;189 }190 183 }; 191 184 -
src/CodeGen/GenType.cpp
r332e93a r985ff5f 268 268 void GenType::postvisit( ast::ZeroType const * type ) { 269 269 // Ideally these wouldn't hit codegen at all, but should be safe to make them ints. 270 result = ( options.genC ? "long int /*zero_t*/ " : "zero_t ") + result;270 result = (options.pretty ? "zero_t " : "long int ") + result; 271 271 handleQualifiers( type ); 272 272 } … … 274 274 void GenType::postvisit( ast::OneType const * type ) { 275 275 // Ideally these wouldn't hit codegen at all, but should be safe to make them ints. 276 result = ( options.genC ? "long int /*one_t*/ " : "one_t ") + result;276 result = (options.pretty ? "one_t " : "long int ") + result; 277 277 handleQualifiers( type ); 278 278 } -
src/CodeGen/Generate.cpp
r332e93a r985ff5f 46 46 } 47 47 }; 48 49 struct ZeroOneObjectHider final {50 ast::ObjectDecl const * postvisit( ast::ObjectDecl const * decl ) {51 if ( decl->type.as<ast::ZeroType>() || decl->type.as<ast::OneType>() ) {52 ast::ObjectDecl * mutDecl = ast::mutate( decl );53 mutDecl->attributes.push_back( new ast::Attribute( "unused" ) );54 return mutDecl;55 }56 return decl;57 }58 };59 48 } // namespace 60 49 … … 63 52 erase_if( translationUnit.decls, shouldClean ); 64 53 ast::Pass<TreeCleaner>::run( translationUnit ); 65 ast::Pass<ZeroOneObjectHider>::run( translationUnit );66 54 67 55 ast::Pass<CodeGenerator> cgv( os, -
src/Concurrency/Actors.cpp
r332e93a r985ff5f 29 29 struct CollectactorStructDecls : public ast::WithGuards { 30 30 unordered_set<const StructDecl *> & actorStructDecls; 31 unordered_set<const StructDecl *> & messageStructDecls;32 const StructDecl * &requestDecl;33 const EnumDecl * &allocationDecl;34 const StructDecl * &actorDecl;35 const StructDecl * &msgDecl;31 unordered_set<const StructDecl *> & messageStructDecls; 32 const StructDecl ** requestDecl; 33 const EnumDecl ** allocationDecl; 34 const StructDecl ** actorDecl; 35 const StructDecl ** msgDecl; 36 36 StructDecl * parentDecl; 37 37 bool insideStruct = false; … … 40 40 // finds and sets a ptr to the allocation enum, which is needed in the next pass 41 41 void previsit( const EnumDecl * decl ) { 42 if( decl->name == "allocation" ) allocationDecl = decl;42 if( decl->name == "allocation" ) *allocationDecl = decl; 43 43 } 44 44 … … 48 48 if ( decl->name == "actor" ) { 49 49 actorStructDecls.insert( decl ); // skip inserting fwd decl 50 actorDecl = decl;50 *actorDecl = decl; 51 51 } else if( decl->name == "message" ) { 52 52 messageStructDecls.insert( decl ); // skip inserting fwd decl 53 msgDecl = decl; 54 } else if( decl->name == "request" ) { 55 requestDecl = decl; 56 } else { 53 *msgDecl = decl; 54 } else if( decl->name == "request" ) *requestDecl = decl; 55 else { 57 56 GuardValue(insideStruct); 58 57 insideStruct = true; … … 74 73 // this collects the derived actor and message struct decl ptrs 75 74 void postvisit( const StructInstType * node ) { 76 if ( ! actorDecl || !msgDecl ) return;75 if ( ! *actorDecl || ! *msgDecl ) return; 77 76 if ( insideStruct && !namedDecl ) { 78 77 auto actorIter = actorStructDecls.find( node->aggr() ); … … 90 89 public: 91 90 CollectactorStructDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls, 92 const StructDecl * & requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *&msgDecl )91 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl ) 93 92 : actorStructDecls( actorStructDecls ), messageStructDecls( messageStructDecls ), requestDecl( requestDecl ), 94 93 allocationDecl( allocationDecl ), actorDecl(actorDecl), msgDecl(msgDecl) {} … … 197 196 struct GenFuncsCreateTables : public ast::WithDeclsToAdd { 198 197 unordered_set<const StructDecl *> & actorStructDecls; 199 unordered_set<const StructDecl *> & messageStructDecls;200 const StructDecl * &requestDecl;201 const EnumDecl * &allocationDecl;202 const StructDecl * &actorDecl;203 const StructDecl * &msgDecl;198 unordered_set<const StructDecl *> & messageStructDecls; 199 const StructDecl ** requestDecl; 200 const EnumDecl ** allocationDecl; 201 const StructDecl ** actorDecl; 202 const StructDecl ** msgDecl; 204 203 FwdDeclTable & forwardDecls; 205 204 … … 280 279 decl->location, 281 280 "base_actor", 282 new PointerType( new PointerType( new StructInstType( actorDecl ) ) )281 new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) 283 282 ), 284 283 new ObjectDecl( 285 284 decl->location, 286 285 "base_msg", 287 new PointerType( new PointerType( new StructInstType( msgDecl ) ) )286 new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) 288 287 ) 289 288 }, // params … … 292 291 decl->location, 293 292 "__CFA_receive_wrap_ret", 294 new EnumInstType( allocationDecl )293 new EnumInstType( *allocationDecl ) 295 294 ) 296 295 }, … … 324 323 decl->location, 325 324 "new_req", 326 new StructInstType( requestDecl )325 new StructInstType( *requestDecl ) 327 326 ) 328 327 )); … … 332 331 derivedReceive->params.push_back( ast::deepCopy( derivedActorRef ) ); 333 332 derivedReceive->params.push_back( ast::deepCopy( derivedMsgRef ) ); 334 derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( actorDecl ) ) ) );335 derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( msgDecl ) ) ) );336 derivedReceive->returns.push_back( new EnumInstType( allocationDecl ) );333 derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) ); 334 derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) ); 335 derivedReceive->returns.push_back( new EnumInstType( *allocationDecl ) ); 337 336 338 337 // Generates: allocation (*my_work_fn)( derived_actor &, derived_msg &, actor **, message ** ) = receive; … … 349 348 // Function type is: allocation (*)( actor &, message & ) 350 349 FunctionType * genericReceive = new FunctionType(); 351 genericReceive->params.push_back( new ReferenceType( new StructInstType( actorDecl ) ) );352 genericReceive->params.push_back( new ReferenceType( new StructInstType( msgDecl ) ) );353 genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( actorDecl ) ) ) );354 genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( msgDecl ) ) ) );355 genericReceive->returns.push_back( new EnumInstType( allocationDecl ) );350 genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) ); 351 genericReceive->params.push_back( new ReferenceType( new StructInstType( *msgDecl ) ) ); 352 genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) ); 353 genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) ); 354 genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) ); 356 355 357 356 // Generates: allocation (*fn)( actor &, message & ) = (allocation (*)( actor &, message & ))my_work_fn; … … 379 378 { 380 379 new NameExpr( decl->location, "new_req" ), 381 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( actorDecl ) ), ExplicitCast ),382 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( msgDecl ) ), ExplicitCast ),380 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( *actorDecl ) ), ExplicitCast ), 381 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( *msgDecl ) ), ExplicitCast ), 383 382 new NameExpr( decl->location, "fn" ) 384 383 } … … 444 443 public: 445 444 GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls, 446 const StructDecl * & requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *&msgDecl,445 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl, 447 446 FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), 448 447 requestDecl(requestDecl), allocationDecl(allocationDecl), actorDecl(actorDecl), msgDecl(msgDecl), forwardDecls(forwardDecls) {} … … 454 453 struct FwdDeclOperator : public ast::WithDeclsToAdd { 455 454 unordered_set<const StructDecl *> & actorStructDecls; 456 unordered_set<const StructDecl *> & messageStructDecls;455 unordered_set<const StructDecl *> & messageStructDecls; 457 456 FwdDeclTable & forwardDecls; 458 457 … … 496 495 // for storing through the passes 497 496 // these are populated with various important struct decls 498 const StructDecl * requestDecl = nullptr; 499 const EnumDecl * allocationDecl = nullptr; 500 const StructDecl * actorDecl = nullptr; 501 const StructDecl * msgDecl = nullptr; 497 const StructDecl * requestDeclPtr = nullptr; 498 const EnumDecl * allocationDeclPtr = nullptr; 499 const StructDecl * actorDeclPtr = nullptr; 500 const StructDecl * msgDeclPtr = nullptr; 501 502 // double pointer to modify local ptrs above 503 const StructDecl ** requestDecl = &requestDeclPtr; 504 const EnumDecl ** allocationDecl = &allocationDeclPtr; 505 const StructDecl ** actorDecl = &actorDeclPtr; 506 const StructDecl ** msgDecl = &msgDeclPtr; 502 507 503 508 // first pass collects ptrs to allocation enum, request type, and generic receive fn typedef 504 509 // also populates maps of all derived actors and messages 505 Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, 506 requestDecl,allocationDecl, actorDecl, msgDecl );510 Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl, 511 allocationDecl, actorDecl, msgDecl ); 507 512 508 513 // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass 509 if ( !allocationDecl || !requestDecl || !actorDecl || !msgDecl)514 if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr ) 510 515 return; 511 516 512 517 // second pass locates all receive() routines that overload the generic receive fn 513 518 // it then generates the appropriate operator '|' send routines for the receive routines 514 Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, 515 requestDecl,allocationDecl, actorDecl, msgDecl, forwardDecls );519 Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl, 520 allocationDecl, actorDecl, msgDecl, forwardDecls ); 516 521 517 522 // The third pass forward declares operator '|' send routines -
src/InitTweak/GenInit.cpp
r332e93a r985ff5f 164 164 ast::ObjectDecl * arrayDimension = nullptr; 165 165 166 if ( auto ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() ) ) { 166 const ast::TypeExpr * ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() ); 167 if ( ty ) { 167 168 auto inst = ty->type.as<ast::EnumInstType>(); 168 if ( inst && !inst->base->is_c_enum() ) { 169 arrayDimension = new ast::ObjectDecl( 170 arrayType->dimension->location, 171 dimensionName.newName(), 172 new ast::BasicType( ast::BasicKind::UnsignedChar ), 173 new ast::SingleInit( 169 if ( inst ) { 170 if ( inst->base->isCfa ) { 171 arrayDimension = new ast::ObjectDecl( 174 172 arrayType->dimension->location, 175 ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() ) 176 ) 177 ); 173 dimensionName.newName(), 174 new ast::BasicType( ast::BasicKind::UnsignedChar ), 175 new ast::SingleInit( 176 arrayType->dimension->location, 177 ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() ) 178 ) 179 ); 180 // return arrayType; 181 } 178 182 } 179 183 } -
src/Parser/TypeData.cpp
r332e93a r985ff5f 1482 1482 object->isHidden = ast::EnumDecl::EnumHiding::Hide == ret->hide; 1483 1483 object->isMember = true; 1484 if ( ret->is _opaque_enum() && cur->has_enumeratorValue() ) {1484 if ( ret->isOpaque() && cur->has_enumeratorValue() ) { 1485 1485 SemanticError( td->location, "Opague cannot have an explicit initializer value." ); 1486 1486 } else if ( cur->has_enumeratorValue() ) { 1487 1487 ast::Expr * initValue; 1488 if ( ret->is _typed_enum()) {1488 if ( ret->isCfa && ret->base ) { 1489 1489 CodeLocation location = cur->enumeratorValue->location; 1490 1490 initValue = new ast::CastExpr( location, maybeMoveBuild( cur->consume_enumeratorValue() ), ret->base ); -
src/ResolvExpr/CastCost.cpp
r332e93a r985ff5f 53 53 void postvisit( const ast::EnumInstType * enumInst ) { 54 54 cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env ); 55 if ( enumInst->base->is _typed_enum() ) {56 auto baseConversionCost = 55 if ( enumInst->base->isTyped() ) { 56 auto baseConversionCost = 57 57 castCost( enumInst->base->base, dst, srcIsLvalue, symtab, env ); 58 cost = baseConversionCost < cost ? baseConversionCost: cost;58 cost = baseConversionCost < cost? baseConversionCost: cost; 59 59 } 60 60 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 61 61 Cost intCost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 62 62 intCost.incSafe(); 63 cost = intCost < cost ? intCost: cost;63 cost = intCost < cost? intCost: cost; 64 64 } 65 65 -
src/ResolvExpr/CommonType.cpp
r332e93a r985ff5f 386 386 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 387 387 const ast::EnumDecl* enumDecl = enumInst->base; 388 if ( enumDecl->is_c_enum()) {388 if ( !enumDecl->isCfa ) { 389 389 ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ]; 390 390 if ( … … 654 654 result = param; 655 655 } 656 } else if ( param->base && param->base->is_c_enum()) {656 } else if ( param->base && !param->base->isCfa ) { 657 657 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt ); 658 658 result = commonType( basicType, type2, tenv, need, have, open, widen); -
src/ResolvExpr/ConversionCost.cpp
r332e93a r985ff5f 246 246 } 247 247 if (const ast::EnumInstType * srcAsInst = dynamic_cast< const ast::EnumInstType * >( src )) { 248 if ( srcAsInst->base && srcAsInst->base->is_c_enum()) {248 if (srcAsInst->base && !srcAsInst->base->isCfa) { 249 249 static const ast::BasicType* integer = new ast::BasicType( ast::BasicKind::UnsignedInt ); 250 250 return ast::Pass<ConversionCost>::read( integer, dst, srcIsLvalue, symtab, env, conversionCost ); … … 324 324 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 325 325 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 326 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum()) {326 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 327 327 cost = Cost::safe; 328 328 } … … 405 405 if ( auto dstInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 406 406 cost = enumCastCost(inst, dstInst, symtab, env); 407 } else if ( inst->base->is_c_enum()) {407 } else if ( !inst->base->isCfa ) { 408 408 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 409 409 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); … … 455 455 } 456 456 457 void ConversionCost::postvisit( const ast::VarArgsType * ) { 457 void ConversionCost::postvisit( const ast::VarArgsType * varArgsType ) { 458 (void)varArgsType; 458 459 if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) { 459 460 cost = Cost::zero; … … 461 462 } 462 463 463 void ConversionCost::postvisit( const ast::ZeroType * ) { 464 void ConversionCost::postvisit( const ast::ZeroType * zeroType ) { 465 (void)zeroType; 464 466 if ( dynamic_cast< const ast::ZeroType * >( dst ) ) { 465 467 cost = Cost::zero; … … 485 487 // assuming 0p is supposed to be used for pointers? 486 488 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 487 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum()) {489 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 488 490 cost = Cost::safe; 489 491 } … … 491 493 } 492 494 493 void ConversionCost::postvisit( const ast::OneType * ) { 495 void ConversionCost::postvisit( const ast::OneType * oneType ) { 496 (void)oneType; 494 497 if ( dynamic_cast< const ast::OneType * >( dst ) ) { 495 498 cost = Cost::zero; … … 505 508 } 506 509 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 507 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum()) {510 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 508 511 cost = Cost::safe; 509 512 } -
src/ResolvExpr/ResolveTypeof.cpp
r332e93a r985ff5f 62 62 // replace basetypeof(<enum>) by int 63 63 auto enumInst = newType.as< ast::EnumInstType >(); 64 if ( enumInst && (!enumInst->base || enumInst->base->is_c_enum()) ) {64 if ( enumInst && (!enumInst->base || !enumInst->base->isCfa) ) { 65 65 newType = new ast::BasicType( 66 66 ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) ); … … 144 144 145 145 auto enumInst = decl->type.as<ast::EnumInstType>(); 146 if ( enumInst && !enumInst->base->is_c_enum()) {146 if ( enumInst && enumInst->base->isCfa ) { 147 147 if ( auto init = decl->init.as<ast::SingleInit>() ) { 148 148 if ( auto initExpr = init->value.as<ast::ConstantExpr>() ) { 149 149 if ( initExpr->result.as<ast::ZeroType>() ) { 150 auto newInit = new ast::SingleInit( init->location, 150 auto newInit = new ast::SingleInit( init->location, 151 151 ast::UntypedExpr::createCall( init->location, "lowerBound", {} ) 152 152 ); -
src/Validate/ImplementEnumFunc.cpp
r332e93a r985ff5f 61 61 ast::FunctionDecl* genLabelProto() const; 62 62 ast::FunctionDecl* genValueProto() const; 63 ast::FunctionDecl* genQuasiValueProto() const; 63 64 ast::FunctionDecl* genTypeNameProto() const; 64 65 … … 205 206 206 207 ast::FunctionDecl* EnumAttrFuncGenerator::genValueProto() const { 207 assert ( decl->is_typed_enum());208 assert (decl->isTyped()); 208 209 return genProto( 209 210 "value", … … 413 414 void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) { 414 415 if (attr == ast::EnumAttribute::Value) { 415 if ( !decl->is _typed_enum() ) return;416 if ( !decl->isTyped() ) return; 416 417 std::vector<ast::ptr<ast::Init>> inits = genValueInit(); 417 418 ast::ObjectDecl* arrayProto = … … 482 483 483 484 void ImplementEnumFunc::previsit(const ast::EnumDecl* enumDecl) { 484 if ( !enumDecl->body || enumDecl->is_c_enum()) return;485 if (!enumDecl->body || !enumDecl->isCfa) return; 485 486 ast::EnumInstType enumInst(enumDecl->name); 486 487 enumInst.base = enumDecl; -
tests/.expect/zero_one.txt
r332e93a r985ff5f 3 3 It's a Number! 4 4 2 2 5 0 06 42 427 0 08 1 19 42 4210 1 111 zero true12 zero true13 one false14 one false -
tests/Makefile.am
r332e93a r985ff5f 354 354 -cp ${test} ${abspath ${@}} 355 355 356 zero_one-ERR1 : zero_one.cfa ${CFACCBIN}357 ${CFACOMPILE_SYNTAX} -DERR1358 -cp ${test} ${abspath ${@}}359 360 356 ctrl-flow/loop_else : ctrl-flow/loop_else.cfa ${CFACCBIN} 361 357 ${CC} ${AM_CFLAGS} -Wno-superfluous-else $< -o $@ -
tests/zero_one.cfa
r332e93a r985ff5f 39 39 } 40 40 41 void testCompats() {42 zero_t zero = 0;43 one_t one = 1;44 45 int x = 0;46 int xx = zero;47 48 sout | x | xx;49 50 x = xx = 42;51 sout | x | xx;52 53 x = 0;54 xx = zero;55 sout | x | xx;56 57 int y = 1;58 int yy = one;59 60 sout | y | yy;61 62 y = yy = 42;63 sout | y | yy;64 65 y = 1;66 yy = one;67 sout | y | yy;68 69 void z_helper( int * p, zero_t z ) {70 p = z; // expect z not reported unused here; expect no missing cast from -Wint-conversion71 sout | "zero" | (bool) (p == 0);72 }73 74 void z_call( int * p, zero_t z ) {75 z_helper(p, z);76 }77 78 void o_helper( int * p, one_t o ) {79 #ifdef ERR180 p = o;81 #else82 (void) x; (void) o;83 #endif84 sout | "one" | (bool) (p == 0);85 }86 87 void o_call( int * p, one_t o ) {88 o_helper(p, o);89 }90 91 z_call( &x, 0 );92 z_call( &x, zero );93 94 o_call( &x, 1 );95 o_call( &x, one );96 }97 98 41 int main() { 99 42 testOverloads(); 100 43 testInitAssignQueryIncrement(); 101 testCompats();102 44 return 0; 103 45 }
Note:
See TracChangeset
for help on using the changeset viewer.