- Timestamp:
- Feb 21, 2020, 3:36:36 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c7a900a
- Parents:
- 8c50aed (diff), c744563a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:13:28 201913 // Update Count : 5 0812 // Last Modified On : Sun Feb 16 08:32:48 2020 13 // Update Count : 532 14 14 // 15 15 #include "CodeGenerator.h" … … 39 39 int CodeGenerator::tabsize = 4; 40 40 41 // the kinds of statements that would ideally be followed by whitespace41 // The kinds of statements that would ideally be followed by whitespace. 42 42 bool wantSpacing( Statement * stmt) { 43 43 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || … … 78 78 } 79 79 80 /* Using updateLocation at the beginning of a node and endl 81 * within a node should become the method of formating. 82 */ 80 // Using updateLocation at the beginning of a node and endl within a node should become the method of formating. 83 81 void CodeGenerator::updateLocation( CodeLocation const & to ) { 84 82 // skip if linemarks shouldn't appear or if codelocation is unset … … 95 93 } else { 96 94 output << "\n# " << to.first_line << " \"" << to.filename 97 95 << "\"\n" << indent; 98 96 currentLocation = to; 99 97 } … … 131 129 132 130 void CodeGenerator::genAttributes( list< Attribute * > & attributes ) { 133 131 if ( attributes.empty() ) return; 134 132 output << "__attribute__ (("; 135 133 for ( list< Attribute * >::iterator attr( attributes.begin() );; ) { … … 140 138 output << ")"; 141 139 } // if 142 140 if ( ++attr == attributes.end() ) break; 143 141 output << ","; // separator 144 142 } // for … … 165 163 previsit( (BaseSyntaxNode *)node ); 166 164 GuardAction( [this, node](){ 167 if ( options.printExprTypes && node->result ) {168 output << " /* " << genType( node->result, "", options ) << " */ ";169 }170 } );165 if ( options.printExprTypes && node->result ) { 166 output << " /* " << genType( node->result, "", options ) << " */ "; 167 } 168 } ); 171 169 } 172 170 … … 399 397 extension( applicationExpr ); 400 398 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) { 401 OperatorInfoopInfo;402 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo) ) {399 const OperatorInfo * opInfo; 400 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && ( opInfo = operatorLookup( varExpr->get_var()->get_name() ) ) ) { 403 401 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 404 switch ( opInfo .type ) {402 switch ( opInfo->type ) { 405 403 case OT_INDEX: 406 404 assert( applicationExpr->get_args().size() == 2 ); … … 423 421 output << "("; 424 422 (*arg++)->accept( *visitor ); 425 output << ") /* " << opInfo .inputName << " */";423 output << ") /* " << opInfo->inputName << " */"; 426 424 } else if ( applicationExpr->get_args().size() == 2 ) { 427 425 // intrinsic two parameter constructors are essentially bitwise assignment 428 426 output << "("; 429 427 (*arg++)->accept( *visitor ); 430 output << opInfo .symbol;428 output << opInfo->symbol; 431 429 (*arg)->accept( *visitor ); 432 output << ") /* " << opInfo .inputName << " */";430 output << ") /* " << opInfo->inputName << " */"; 433 431 } else { 434 432 // no constructors with 0 or more than 2 parameters … … 441 439 assert( applicationExpr->get_args().size() == 1 ); 442 440 output << "("; 443 output << opInfo .symbol;441 output << opInfo->symbol; 444 442 (*arg)->accept( *visitor ); 445 443 output << ")"; … … 450 448 assert( applicationExpr->get_args().size() == 1 ); 451 449 (*arg)->accept( *visitor ); 452 output << opInfo .symbol;450 output << opInfo->symbol; 453 451 break; 454 452 … … 459 457 output << "("; 460 458 (*arg++)->accept( *visitor ); 461 output << opInfo .symbol;459 output << opInfo->symbol; 462 460 (*arg)->accept( *visitor ); 463 461 output << ")"; … … 486 484 extension( untypedExpr ); 487 485 if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) { 488 OperatorInfo opInfo;489 if ( op eratorLookup( nameExpr->name, opInfo )) {486 const OperatorInfo * opInfo = operatorLookup( nameExpr->name ); 487 if ( opInfo ) { 490 488 std::list< Expression* >::iterator arg = untypedExpr->args.begin(); 491 switch ( opInfo .type ) {489 switch ( opInfo->type ) { 492 490 case OT_INDEX: 493 491 assert( untypedExpr->args.size() == 2 ); … … 508 506 output << "("; 509 507 (*arg++)->accept( *visitor ); 510 output << ") /* " << opInfo .inputName << " */";508 output << ") /* " << opInfo->inputName << " */"; 511 509 } else if ( untypedExpr->get_args().size() == 2 ) { 512 510 // intrinsic two parameter constructors are essentially bitwise assignment 513 511 output << "("; 514 512 (*arg++)->accept( *visitor ); 515 output << opInfo .symbol;513 output << opInfo->symbol; 516 514 (*arg)->accept( *visitor ); 517 output << ") /* " << opInfo .inputName << " */";515 output << ") /* " << opInfo->inputName << " */"; 518 516 } else { 519 517 // no constructors with 0 or more than 2 parameters … … 521 519 output << "("; 522 520 (*arg++)->accept( *visitor ); 523 output << opInfo .symbol << "{ ";521 output << opInfo->symbol << "{ "; 524 522 genCommaList( arg, untypedExpr->args.end() ); 525 output << "}) /* " << opInfo .inputName << " */";523 output << "}) /* " << opInfo->inputName << " */"; 526 524 } // if 527 525 break; … … 532 530 assert( untypedExpr->args.size() == 1 ); 533 531 output << "("; 534 output << opInfo .symbol;532 output << opInfo->symbol; 535 533 (*arg)->accept( *visitor ); 536 534 output << ")"; … … 541 539 assert( untypedExpr->args.size() == 1 ); 542 540 (*arg)->accept( *visitor ); 543 output << opInfo .symbol;541 output << opInfo->symbol; 544 542 break; 545 543 … … 549 547 output << "("; 550 548 (*arg++)->accept( *visitor ); 551 output << opInfo .symbol;549 output << opInfo->symbol; 552 550 (*arg)->accept( *visitor ); 553 551 output << ")"; … … 581 579 void CodeGenerator::postvisit( NameExpr * nameExpr ) { 582 580 extension( nameExpr ); 583 OperatorInfo opInfo;584 if ( op eratorLookup( nameExpr->name, opInfo )) {585 if ( opInfo .type == OT_CONSTANT ) {586 output << opInfo .symbol;581 const OperatorInfo * opInfo = operatorLookup( nameExpr->name ); 582 if ( opInfo ) { 583 if ( opInfo->type == OT_CONSTANT ) { 584 output << opInfo->symbol; 587 585 } else { 588 output << opInfo .outputName;586 output << opInfo->outputName; 589 587 } 590 588 } else { … … 654 652 void CodeGenerator::postvisit( VariableExpr * variableExpr ) { 655 653 extension( variableExpr ); 656 OperatorInfoopInfo;657 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {658 output << opInfo .symbol;654 const OperatorInfo * opInfo; 655 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && (opInfo = operatorLookup( variableExpr->get_var()->get_name() )) && opInfo->type == OT_CONSTANT ) { 656 output << opInfo->symbol; 659 657 } else { 660 658 output << mangleName( variableExpr->get_var() ); … … 1011 1009 case BranchStmt::FallThroughDefault: 1012 1010 assertf( ! options.genC, "fallthru should not reach code generation." ); 1013 1011 output << "fallthru"; 1014 1012 break; 1015 1013 } // switch … … 1035 1033 1036 1034 output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ? 1037 1035 "throw" : "throwResume"); 1038 1036 if (throwStmt->get_expr()) { 1039 1037 output << " "; … … 1050 1048 1051 1049 output << ((stmt->get_kind() == CatchStmt::Terminate) ? 1052 "catch" : "catchResume");1050 "catch" : "catchResume"); 1053 1051 output << "( "; 1054 1052 stmt->decl->accept( *visitor ); … … 1187 1185 1188 1186 std::string genName( DeclarationWithType * decl ) { 1189 CodeGen::OperatorInfo opInfo;1190 if ( op eratorLookup( decl->get_name(), opInfo )) {1191 return opInfo .outputName;1187 const OperatorInfo * opInfo = operatorLookup( decl->get_name() ); 1188 if ( opInfo ) { 1189 return opInfo->outputName; 1192 1190 } else { 1193 1191 return decl->get_name(); -
src/CodeGen/CodeGenerator.h
r8c50aed ra505021 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue Apr 30 12:01:00 201913 // Update Count : 5711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 16 03:58:31 2020 13 // Update Count : 62 14 14 // 15 15 … … 29 29 namespace CodeGen { 30 30 struct CodeGenerator : public WithShortCircuiting, public WithGuards, public WithVisitorRef<CodeGenerator> { 31 31 static int tabsize; 32 32 33 33 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false ); … … 104 104 void postvisit( AsmStmt * ); 105 105 void postvisit( DirectiveStmt * ); 106 void postvisit( AsmDecl * ); // special: statement in declaration context106 void postvisit( AsmDecl * ); // special: statement in declaration context 107 107 void postvisit( IfStmt * ); 108 108 void postvisit( SwitchStmt * ); … … 147 147 LabelPrinter printLabels; 148 148 Options options; 149 public:149 public: 150 150 LineEnder endl; 151 private:151 private: 152 152 153 153 CodeLocation currentLocation; … … 162 162 template< class Iterator > 163 163 void CodeGenerator::genCommaList( Iterator begin, Iterator end ) { 164 164 if ( begin == end ) return; 165 165 for ( ;; ) { 166 166 (*begin++)->accept( *visitor ); 167 167 if ( begin == end ) break; 168 168 output << ", "; // separator 169 169 } // for -
src/CodeGen/FixMain.h
r8c50aed ra505021 10 10 // Created On : Thr Jan 12 14:11:09 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:12:21 201913 // Update Count : 312 // Last Modified On : Sun Feb 16 03:24:32 2020 13 // Update Count : 5 14 14 // 15 15 … … 42 42 static std::unique_ptr<FunctionDecl> main_signature; 43 43 }; 44 } ;44 } // namespace CodeGen -
src/CodeGen/GenType.h
r8c50aed ra505021 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue Apr 30 11:47:00 201913 // Update Count : 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 16 04:11:40 2020 13 // Update Count : 5 14 14 // 15 15 … … 25 25 std::string genType( Type *type, const std::string &baseString, const Options &options ); 26 26 std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false ); 27 27 std::string genPrettyType( Type * type, const std::string & baseString ); 28 28 } // namespace CodeGen 29 29 -
src/CodeGen/Generate.cc
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:38:56 201913 // Update Count : 812 // Last Modified On : Sun Feb 16 03:01:51 2020 13 // Update Count : 9 14 14 // 15 15 #include "Generate.h" … … 64 64 void generate( BaseSyntaxNode * node, std::ostream & os ) { 65 65 if ( Type * type = dynamic_cast< Type * >( node ) ) { 66 os << CodeGen::genPrettyType( type, "" );66 os << genPrettyType( type, "" ); 67 67 } else { 68 68 PassVisitor<CodeGenerator> cgv( os, true, false, false, false ); -
src/CodeGen/OperatorTable.cc
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 15 17:12:22 201713 // Update Count : 1512 // Last Modified On : Tue Feb 18 15:55:01 2020 13 // Update Count : 55 14 14 // 15 15 … … 17 17 #include <map> // for map, _Rb_tree_const_iterator, map<>::const_iterator 18 18 #include <utility> // for pair 19 using namespace std; 19 20 20 21 #include "OperatorTable.h" … … 22 23 23 24 namespace CodeGen { 24 namespace{25 const OperatorInfo tableValues[] = {26 { "?[?]", "", "_operator_index", OT_INDEX},27 { "?{}", "=", "_constructor", OT_CTOR},28 { "^?{}", "", "_destructor", OT_DTOR},29 { "?()", "", "_operator_call", OT_CALL},30 { "?++", "++", "_operator_postincr", OT_POSTFIXASSIGN},31 { "?--", "--", "_operator_postdecr", OT_POSTFIXASSIGN},32 { "*?", "*", "_operator_deref", OT_PREFIX},33 { "+?", "+", "_operator_unaryplus", OT_PREFIX},34 { "-?", "-", "_operator_unaryminus", OT_PREFIX},35 { "~?", "~", "_operator_bitnot", OT_PREFIX},36 { "!?", "!", "_operator_lognot", OT_PREFIX},37 { "++?", "++", "_operator_preincr", OT_PREFIXASSIGN},38 { "--?", "--", "_operator_predecr", OT_PREFIXASSIGN},39 { "?\\?", "\\", "_operator_exponential", OT_INFIX},40 { "?*?", "*", "_operator_multiply", OT_INFIX},41 { "?/?", "/", "_operator_divide", OT_INFIX},42 { "?%?", "%", "_operator_modulus", OT_INFIX},43 { "?+?", "+", "_operator_add", OT_INFIX},44 { "?-?", "-", "_operator_subtract", OT_INFIX},45 { "?<<?", "<<", "_operator_shiftleft", OT_INFIX},46 { "?>>?", ">>", "_operator_shiftright", OT_INFIX},47 { "?<?", "<", "_operator_less", OT_INFIX},48 { "?>?", ">", "_operator_greater", OT_INFIX},49 { "?<=?", "<=", "_operator_lessequal", OT_INFIX},50 { "?>=?", ">=", "_operator_greaterequal", OT_INFIX},51 { "?==?", "==", "_operator_equal", OT_INFIX},52 { "?!=?", "!=", "_operator_notequal", OT_INFIX},53 { "?&?", "&", "_operator_bitand", OT_INFIX},54 { "?^?", "^", "_operator_bitxor", OT_INFIX},55 { "?|?", "|", "_operator_bitor", OT_INFIX},56 { "?=?", "=", "_operator_assign", OT_INFIXASSIGN},57 { "?\\=?", "\\=", "_operator_expassign", OT_INFIXASSIGN},58 { "?*=?", "*=", "_operator_multassign", OT_INFIXASSIGN},59 { "?/=?", "/=", "_operator_divassign", OT_INFIXASSIGN},60 { "?%=?", "%=", "_operator_modassign", OT_INFIXASSIGN},61 { "?+=?", "+=", "_operator_addassign", OT_INFIXASSIGN},62 { "?-=?", "-=", "_operator_subassign", OT_INFIXASSIGN},63 { "?<<=?", "<<=", "_operator_shiftleftassign", OT_INFIXASSIGN},64 { "?>>=?", ">>=", "_operator_shiftrightassign", OT_INFIXASSIGN},65 { "?&=?", "&=", "_operator_bitandassign", OT_INFIXASSIGN},66 { "?^=?", "^=", "_operator_bitxorassign", OT_INFIXASSIGN},67 { "?|=?", "|=", "_operator_bitorassign", OT_INFIXASSIGN},68 };25 const OperatorInfo CodeGen::tableValues[] = { 26 // inputName symbol outputName friendlyName type 27 { "?[?]", "", "_operator_index", "Index", OT_INDEX }, 28 { "?{}", "=", "_constructor", "Constructor", OT_CTOR }, 29 { "^?{}", "", "_destructor", "Destructor", OT_DTOR }, 30 { "?()", "", "_operator_call", "Call Operator", OT_CALL }, 31 { "?++", "++", "_operator_postincr", "Postfix Increment", OT_POSTFIXASSIGN }, 32 { "?--", "--", "_operator_postdecr", "Postfix Decrement", OT_POSTFIXASSIGN }, 33 { "*?", "*", "_operator_deref", "Dereference", OT_PREFIX }, 34 { "+?", "+", "_operator_unaryplus", "Plus", OT_PREFIX }, 35 { "-?", "-", "_operator_unaryminus", "Minus", OT_PREFIX }, 36 { "~?", "~", "_operator_bitnot", "Bitwise Not", OT_PREFIX }, 37 { "!?", "!", "_operator_lognot", "Logical Not", OT_PREFIX }, 38 { "++?", "++", "_operator_preincr", "Prefix Increment", OT_PREFIXASSIGN }, 39 { "--?", "--", "_operator_predecr", "Prefix Decrement", OT_PREFIXASSIGN }, 40 { "?\\?", "\\", "_operator_exponential", "Exponentiation", OT_INFIX }, 41 { "?*?", "*", "_operator_multiply", "Multiplication", OT_INFIX }, 42 { "?/?", "/", "_operator_divide", "Division", OT_INFIX }, 43 { "?%?", "%", "_operator_modulus", "Modulo", OT_INFIX }, 44 { "?+?", "+", "_operator_add", "Addition", OT_INFIX }, 45 { "?-?", "-", "_operator_subtract", "Substraction", OT_INFIX }, 46 { "?<<?", "<<", "_operator_shiftleft", "Shift Left", OT_INFIX }, 47 { "?>>?", ">>", "_operator_shiftright", "Shift Right", OT_INFIX }, 48 { "?<?", "<", "_operator_less", "Less-than", OT_INFIX }, 49 { "?>?", ">", "_operator_greater", "Greater-than", OT_INFIX }, 50 { "?<=?", "<=", "_operator_lessequal", "Less-than-or-Equal", OT_INFIX }, 51 { "?>=?", ">=", "_operator_greaterequal", "Greater-than-or-Equal", OT_INFIX }, 52 { "?==?", "==", "_operator_equal", "Equality", OT_INFIX }, 53 { "?!=?", "!=", "_operator_notequal", "Not-Equal", OT_INFIX }, 54 { "?&?", "&", "_operator_bitand", "Bitwise And", OT_INFIX }, 55 { "?^?", "^", "_operator_bitxor", "Bitwise Xor", OT_INFIX }, 56 { "?|?", "|", "_operator_bitor", "Bitwise Or", OT_INFIX }, 57 { "?=?", "=", "_operator_assign", "Assignment", OT_INFIXASSIGN }, 58 { "?\\=?", "\\=", "_operator_expassign", "Exponentiation Assignment", OT_INFIXASSIGN }, 59 { "?*=?", "*=", "_operator_multassign", "Multiplication Assignment", OT_INFIXASSIGN }, 60 { "?/=?", "/=", "_operator_divassign", "Division Assignment", OT_INFIXASSIGN }, 61 { "?%=?", "%=", "_operator_modassign", "Modulo Assignment", OT_INFIXASSIGN }, 62 { "?+=?", "+=", "_operator_addassign", "Addition Assignment", OT_INFIXASSIGN }, 63 { "?-=?", "-=", "_operator_subassign", "Substrction Assignment", OT_INFIXASSIGN }, 64 { "?<<=?", "<<=", "_operator_shiftleftassign", "Shift Left Assignment", OT_INFIXASSIGN }, 65 { "?>>=?", ">>=", "_operator_shiftrightassign", "Shift Right Assignment", OT_INFIXASSIGN }, 66 { "?&=?", "&=", "_operator_bitandassign", "Bitwise And Assignment", OT_INFIXASSIGN }, 67 { "?^=?", "^=", "_operator_bitxorassign", "Bitwise Xor Assignment", OT_INFIXASSIGN }, 68 { "?|=?", "|=", "_operator_bitorassign", "Bitwise Or Assignment", OT_INFIXASSIGN }, 69 }; // tableValues 69 70 70 const int numOps = sizeof( tableValues ) / sizeof( OperatorInfo );71 std::map< std::string, OperatorInfo > CodeGen::table; 71 72 72 std::map< std::string, OperatorInfo > table; 73 74 void initialize() { 75 for ( int i = 0; i < numOps; ++i ) { 76 table[ tableValues[i].inputName ] = tableValues[i]; 77 } // for 78 } 79 } // namespace 80 81 bool operatorLookup( const std::string & funcName, OperatorInfo & info ) { 82 static bool init = false; 83 if ( ! init ) { 84 initialize(); 85 } // if 86 87 std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName ); 88 if ( i == table.end() ) { 89 if ( isPrefix( funcName, "?`" ) ) { 90 // handle literal suffixes, which are user-defined postfix operators 91 info.inputName = funcName; 92 info.symbol = funcName.substr(2); 93 info.outputName = toString( "__operator_literal_", info.symbol ); 94 info.type = OT_POSTFIX; 95 return true; 96 } 97 return false; 98 } else { 99 info = i->second; 100 return true; 101 } // if 73 CodeGen::CodeGen() { 74 enum { numOps = sizeof( tableValues ) / sizeof( OperatorInfo ) }; 75 for ( int i = 0; i < numOps; i += 1 ) { 76 table[ tableValues[i].inputName ] = tableValues[i]; 77 } // for 102 78 } 103 79 104 bool isOperator( const std::string & funcName ) { 105 OperatorInfo info; 106 return operatorLookup( funcName, info ); 80 const OperatorInfo * operatorLookup( const string & funcName ) { 81 if ( funcName.find_first_of( "?^*+-!", 0, 1 ) == string::npos ) return nullptr; // prefilter 82 const OperatorInfo * ret = &CodeGen::table.find( funcName )->second; // must be in the table 83 assert( ret ); 84 return ret; 107 85 } 108 86 109 /// determines if a given function name is one of the operator types between [begin, end) 110 template<typename Iterator> 111 bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) { 112 OperatorInfo info; 113 if ( operatorLookup( funcName, info ) ) { 114 return std::find( begin, end, info.type ) != end; 115 } 87 bool isOperator( const string & funcName ) { 88 return operatorLookup( funcName ) != nullptr; 89 } 90 91 string operatorFriendlyName( const string & funcName ) { 92 const OperatorInfo * info = operatorLookup( funcName ); 93 if ( info ) return info->friendlyName; 94 return ""; 95 } 96 97 bool isConstructor( const string & funcName ) { 98 const OperatorInfo * info = operatorLookup( funcName ); 99 if ( info ) return info->type == OT_CTOR; 116 100 return false; 117 101 } 118 102 119 bool isConstructor( const std::string & funcName ) { 120 static OperatorType types[] = { OT_CTOR }; 121 return isOperatorType( funcName, std::begin(types), std::end(types) ); 103 bool isDestructor( const string & funcName ) { 104 const OperatorInfo * info = operatorLookup( funcName ); 105 if ( info ) return info->type == OT_DTOR; 106 return false; 122 107 } 123 108 124 bool isDestructor( const std::string & funcName ) { 125 static OperatorType types[] = { OT_DTOR }; 126 return isOperatorType( funcName, std::begin(types), std::end(types) ); 109 bool isCtorDtor( const string & funcName ) { 110 const OperatorInfo * info = operatorLookup( funcName ); 111 if ( info ) return info->type <= OT_CONSTRUCTOR; 112 return false; 127 113 } 128 114 129 bool isAssignment( const std::string & funcName ) { 130 static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 131 return isOperatorType( funcName, std::begin(types), std::end(types) ); 115 bool isAssignment( const string & funcName ) { 116 const OperatorInfo * info = operatorLookup( funcName ); 117 if ( info ) return info->type > OT_CONSTRUCTOR && info->type <= OT_ASSIGNMENT; 118 return false; 132 119 } 133 120 134 bool isCtorDtor( const std::string & funcName ) { 135 static OperatorType types[] = { OT_CTOR, OT_DTOR }; 136 return isOperatorType( funcName, std::begin(types), std::end(types) ); 121 bool isCtorDtorAssign( const string & funcName ) { 122 const OperatorInfo * info = operatorLookup( funcName ); 123 if ( info ) return info->type <= OT_ASSIGNMENT; 124 return false; 137 125 } 138 126 139 bool isCtorDtorAssign( const std::string & funcName ) { 140 static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 141 return isOperatorType( funcName, std::begin(types), std::end(types) ); 142 } 127 CodeGen codegen; // initialize singleton package 143 128 } // namespace CodeGen 144 129 145 130 // Local Variables: // 146 131 // tab-width: 4 // 147 // mode: c++ //148 // compile-command: "make install" //149 132 // End: // -
src/CodeGen/OperatorTable.h
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:17:11 201713 // Update Count : 612 // Last Modified On : Sun Feb 16 08:13:34 2020 13 // Update Count : 26 14 14 // 15 15 … … 17 17 18 18 #include <string> 19 #include <map> 19 20 20 21 namespace CodeGen { 21 22 enum OperatorType { 22 OT_INDEX,23 23 OT_CTOR, 24 24 OT_DTOR, 25 OT_CALL, 26 OT_PREFIX, 27 OT_POSTFIX, 28 OT_INFIX, 25 OT_CONSTRUCTOR = OT_DTOR, 29 26 OT_PREFIXASSIGN, 30 27 OT_POSTFIXASSIGN, 31 28 OT_INFIXASSIGN, 29 OT_ASSIGNMENT = OT_INFIXASSIGN, 30 OT_CALL, 31 OT_PREFIX, 32 OT_INFIX, 33 OT_POSTFIX, 34 OT_INDEX, 32 35 OT_LABELADDRESS, 33 36 OT_CONSTANT … … 38 41 std::string symbol; 39 42 std::string outputName; 43 std::string friendlyName; 40 44 OperatorType type; 41 45 }; 42 46 47 class CodeGen { 48 friend const OperatorInfo * operatorLookup( const std::string & funcName ); 49 50 static const OperatorInfo tableValues[]; 51 static std::map< std::string, OperatorInfo > table; 52 public: 53 CodeGen(); 54 }; // CodeGen 55 43 56 bool isOperator( const std::string & funcName ); 44 bool operatorLookup( const std::string & funcName, OperatorInfo & info ); 57 const OperatorInfo * operatorLookup( const std::string & funcName ); 58 std::string operatorFriendlyName( const std::string & funcName ); 45 59 46 60 bool isConstructor( const std::string & ); -
src/CodeGen/Options.h
r8c50aed ra505021 9 9 // Author : Andrew Beach 10 10 // Created On : Tue Apr 30 11:36:00 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr May 2 10:45:00 201913 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 15 18:37:06 2020 13 // Update Count : 3 14 14 // 15 15 16 16 #pragma once 17 17 18 namespace CodeGen { 19 struct Options { 20 // External Options: Same thoughout a pass. 21 bool pretty; 22 bool genC; 23 bool lineMarks; 24 bool printExprTypes; 18 struct Options { 19 // External Options: Same thoughout a pass. 20 bool pretty; 21 bool genC; 22 bool lineMarks; 23 bool printExprTypes; 25 24 26 27 25 // Internal Options: Changed on some recurisive calls. 26 bool anonymousUnused = false; 28 27 29 30 28 Options(bool pretty, bool genC, bool lineMarks, bool printExprTypes) : 29 pretty(pretty), genC(genC), lineMarks(lineMarks), printExprTypes(printExprTypes) 31 30 {} 32 }; 33 } // namespace CodeGen 31 }; 34 32 35 33 // Local Variables: // -
src/CodeTools/ResolvProtoDump.cc
r8c50aed ra505021 9 9 // Author : Aaron Moss 10 10 // Created On : Tue Sep 11 09:04:00 2018 11 // Last Modified By : Aaron Moss12 // Last Modified On : Tue Sep 11 09:04:00 201813 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 15 13:50:11 2020 13 // Update Count : 3 14 14 // 15 15 … … 182 182 183 183 // replace operator names 184 CodeGen::OperatorInfo info;185 if ( CodeGen::operatorLookup( name, info )) {184 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( name ); 185 if ( opInfo ) { 186 186 ss << new_prefix(pre, ""); 187 op_name( info.outputName, ss );187 op_name( opInfo->outputName, ss ); 188 188 return; 189 189 } -
src/Common/PassVisitor.impl.h
r8c50aed ra505021 3302 3302 VISIT_START( node ); 3303 3303 3304 indexerAdd Struct( node->name );3304 indexerAddUnion( node->name ); 3305 3305 3306 3306 { … … 3317 3317 VISIT_START( node ); 3318 3318 3319 indexerAdd Struct( node->name );3319 indexerAddUnion( node->name ); 3320 3320 3321 3321 { … … 3332 3332 MUTATE_START( node ); 3333 3333 3334 indexerAdd Struct( node->name );3334 indexerAddUnion( node->name ); 3335 3335 3336 3336 { -
src/Common/SemanticError.h
r8c50aed ra505021 49 49 struct WarningData { 50 50 const char * const name; 51 const Severity default_severity; 51 52 const char * const message; 52 const Severity default_severity;53 53 }; 54 54 55 55 constexpr WarningData WarningFormats[] = { 56 {"self-assign" , "self assignment of expression: %s" , Severity::Warn}, 57 {"reference-conversion" , "rvalue to reference conversion of rvalue: %s" , Severity::Warn}, 58 {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn}, 59 {"aggregate-forward-decl" , "forward declaration of nested aggregate: %s" , Severity::Warn}, 60 {"superfluous-decl" , "declaration does not allocate storage: %s" , Severity::Warn}, 61 {"gcc-attributes" , "invalid attribute: %s" , Severity::Warn}, 56 {"self-assign" , Severity::Warn , "self assignment of expression: %s" }, 57 {"reference-conversion" , Severity::Warn , "rvalue to reference conversion of rvalue: %s" }, 58 {"qualifiers-zero_t-one_t", Severity::Warn , "questionable use of type qualifier %s with %s" }, 59 {"aggregate-forward-decl" , Severity::Warn , "forward declaration of nested aggregate: %s" }, 60 {"superfluous-decl" , Severity::Warn , "declaration does not allocate storage: %s" }, 61 {"gcc-attributes" , Severity::Warn , "invalid attribute: %s" }, 62 {"c++-like-copy" , Severity::Warn , "Constructor from reference is not a valid copy constructor" }, 62 63 }; 63 64 … … 69 70 SuperfluousDecl, 70 71 GccAttributes, 72 CppCopy, 71 73 NUMBER_OF_WARNINGS, // This MUST be the last warning 72 74 }; -
src/Common/utility.h
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 24 14:28:19 201913 // Update Count : 4112 // Last Modified On : Tue Feb 11 13:00:36 2020 13 // Update Count : 50 14 14 // 15 15 … … 29 29 #include <utility> 30 30 #include <vector> 31 #include <cstring> // memcmp 31 32 32 33 #include "Common/Indenter.h" … … 264 265 } 265 266 266 // / determines if `pref` is a prefix of `str`267 static inline bool isPrefix( const std::string & str, const std::string & pref ) {267 // determines if pref is a prefix of str 268 static inline bool isPrefix( const std::string & str, const std::string & pref, unsigned int start = 0 ) { 268 269 if ( pref.size() > str.size() ) return false; 269 auto its = std::mismatch( pref.begin(), pref.end(), str.begin() );270 return its.first == pref.end();270 return 0 == memcmp( str.c_str() + start, pref.c_str(), pref.size() ); 271 // return prefix == full.substr(0, prefix.size()); // for future, requires c++17 271 272 } 272 273 -
src/ControlStruct/Mutate.cc
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 4 11:39:08 201613 // Update Count : 912 // Last Modified On : Sun Feb 16 03:22:07 2020 13 // Update Count : 10 14 14 // 15 15 … … 37 37 mutateAll( translationUnit, formut ); 38 38 } 39 } // namespace Co deGen39 } // namespace ControlStruct 40 40 41 41 // Local Variables: // -
src/InitTweak/FixInit.cc
r8c50aed ra505021 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:41:27 201913 // Update Count : 7712 // Last Modified On : Sun Feb 16 04:17:07 2020 13 // Update Count : 82 14 14 // 15 15 #include "FixInit.h" … … 745 745 } 746 746 747 // to prevent warnings ( ‘_unq0’may be used uninitialized in this function),747 // to prevent warnings ('_unq0' may be used uninitialized in this function), 748 748 // insert an appropriate zero initializer for UniqueExpr temporaries. 749 749 Initializer * makeInit( Type * t ) { -
src/InitTweak/FixInit.h
r8c50aed ra505021 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jul 22 09:31:06 201713 // Update Count : 612 // Last Modified On : Sun Feb 16 07:54:50 2020 13 // Update Count : 8 14 14 // 15 15 … … 22 22 23 23 namespace InitTweak { 24 /// replace constructor initializers with expression statements 25 /// and unwrap basic C-style initializers 24 /// replace constructor initializers with expression statements and unwrap basic C-style initializers 26 25 void fix( std::list< Declaration * > & translationUnit, bool inLibrary ); 27 26 } // namespace -
src/MakeLibCfa.cc
r8c50aed ra505021 10 10 // Created On : Sat May 16 10:33:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:41:40 201913 // Update Count : 4 212 // Last Modified On : Sun Feb 16 03:49:49 2020 13 // Update Count : 45 14 14 // 15 15 … … 96 96 97 97 FunctionDecl *funcDecl = origFuncDecl->clone(); 98 CodeGen::OperatorInfoopInfo;99 bool lookResult = CodeGen::operatorLookup( funcDecl->get_name(), opInfo);100 assert( lookResult);98 const CodeGen::OperatorInfo * opInfo; 99 opInfo = CodeGen::operatorLookup( funcDecl->get_name() ); 100 assert( opInfo ); 101 101 assert( ! funcDecl->get_statements() ); 102 102 // build a recursive call - this is okay, as the call will actually be codegen'd using operator syntax … … 120 120 121 121 Statement * stmt = nullptr; 122 switch ( opInfo .type ) {122 switch ( opInfo->type ) { 123 123 case CodeGen::OT_INDEX: 124 124 case CodeGen::OT_CALL: -
src/Parser/ParseNode.h
r8c50aed ra505021 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 16 07:46:01 201913 // Update Count : 8 8812 // Last Modified On : Fri Feb 7 17:56:02 2020 13 // Update Count : 891 14 14 // 15 15 … … 449 449 * out++ = result; 450 450 } else { 451 assertf(false, "buildList unknown type");451 SemanticError( cur->location, "type specifier declaration in forall clause is currently unimplemented." ); 452 452 } // if 453 453 } catch( SemanticErrorException & e ) { -
src/Parser/ParserTypes.h
r8c50aed ra505021 10 10 // Created On : Sat Sep 22 08:58:10 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:33:28 201713 // Update Count : 35 012 // Last Modified On : Sat Feb 15 11:04:40 2020 13 // Update Count : 351 14 14 // 15 15 … … 27 27 // current location in the input 28 28 extern int yylineno; 29 extern char * yyfilename;29 extern char * yyfilename; 30 30 31 31 struct Location { 32 char * file;32 char * file; 33 33 int line; 34 34 }; // Location 35 35 36 36 struct Token { 37 std::string * str; // must be pointer as used in union37 std::string * str; // must be pointer as used in union 38 38 Location loc; 39 39 -
src/Parser/TypedefTable.cc
r8c50aed ra505021 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 25 15:32:35 201813 // Update Count : 25 812 // Last Modified On : Sat Feb 15 08:06:36 2020 13 // Update Count : 259 14 14 // 15 15 … … 47 47 } // TypedefTable::~TypedefTable 48 48 49 bool TypedefTable::exists( const string & identifier ) {49 bool TypedefTable::exists( const string & identifier ) const { 50 50 return kindTable.find( identifier ) != kindTable.end(); 51 51 } // TypedefTable::exists 52 52 53 bool TypedefTable::existsCurr( const string & identifier ) {53 bool TypedefTable::existsCurr( const string & identifier ) const { 54 54 return kindTable.findAt( kindTable.currentScope() - 1, identifier ) != kindTable.end(); 55 55 } // TypedefTable::exists -
src/Parser/TypedefTable.h
r8c50aed ra505021 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 25 15:33:55 201813 // Update Count : 11 412 // Last Modified On : Sat Feb 15 08:06:37 2020 13 // Update Count : 117 14 14 // 15 15 … … 30 30 ~TypedefTable(); 31 31 32 bool exists( const std::string & identifier ) ;33 bool existsCurr( const std::string & identifier ) ;32 bool exists( const std::string & identifier ) const; 33 bool existsCurr( const std::string & identifier ) const; 34 34 int isKind( const std::string & identifier ) const; 35 35 void makeTypedef( const std::string & name, int kind = TYPEDEFname ); -
src/Parser/lex.ll
r8c50aed ra505021 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sat Feb 1 07:16:44202013 * Update Count : 7 2412 * Last Modified On : Sat Feb 15 11:05:50 2020 13 * Update Count : 737 14 14 */ 15 15 … … 42 42 #include "ParseNode.h" 43 43 #include "TypedefTable.h" 44 45 string * build_postfix_name( string * name ); 44 46 45 47 char *yyfilename; … … 330 332 /* identifier */ 331 333 {identifier} { IDENTIFIER_RETURN(); } 332 "``"{identifier} "``" {// CFA333 yytext[yyleng - 2] = '\0'; yytext += 2;// SKULLDUGGERY: remove backquotes (ok to shorten?)334 "``"{identifier} { // CFA 335 yytext[yyleng] = '\0'; yytext += 2; // SKULLDUGGERY: remove backquotes (ok to shorten?) 334 336 IDENTIFIER_RETURN(); 335 337 } … … 432 434 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 433 435 "^?{}" { IDENTIFIER_RETURN(); } 434 "?`"{identifier} { IDENTIFIER_RETURN(); } // postfix operator 436 "?`"{identifier} { // postfix operator 437 yylval.tok.str = new string( &yytext[2] ); // remove ?` 438 yylval.tok.str = build_postfix_name( yylval.tok.str ); // add prefix 439 RETURN_LOCN( typedefTable.isKind( *yylval.tok.str ) ); 440 } 435 441 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 436 442 /* -
src/Parser/parser.yy
r8c50aed ra505021 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 1 10:04:40202013 // Update Count : 44 4012 // Last Modified On : Fri Feb 21 14:47:29 2020 13 // Update Count : 4468 14 14 // 15 15 … … 166 166 } // rebindForall 167 167 168 NameExpr * build_postfix_name( const string * name ) { 169 NameExpr * new_name = build_varref( new string( "?`" + *name ) ); 170 delete name; 171 return new_name; 168 string * build_postfix_name( string * name ) { 169 *name = string("__postfix_func_") + *name; 170 return name; 172 171 } // build_postfix_name 173 172 … … 633 632 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 633 | postfix_expression '`' identifier // CFA, postfix call 635 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_ postfix_name( $3) ), $1 ) ); }634 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 636 635 | constant '`' identifier // CFA, postfix call 637 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_ postfix_name( $3) ), $1 ) ); }636 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 638 637 | string_literal '`' identifier // CFA, postfix call 639 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_ postfix_name( $3) ), new ExpressionNode( $1 ) ) ); }638 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); } 640 639 | postfix_expression '.' identifier 641 640 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } … … 1590 1589 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1591 1590 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1592 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1591 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1593 1592 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1594 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ; }1595 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1596 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ; }1593 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1594 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1595 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1597 1596 ; 1598 1597 -
src/ResolvExpr/Resolver.cc
r8c50aed ra505021 84 84 void previsit( ThrowStmt * throwStmt ); 85 85 void previsit( CatchStmt * catchStmt ); 86 void postvisit( CatchStmt * catchStmt ); 86 87 void previsit( WaitForStmt * stmt ); 87 88 … … 567 568 568 569 void Resolver_old::previsit( CatchStmt * catchStmt ) { 570 // Until we are very sure this invarent (ifs that move between passes have thenPart) 571 // holds, check it. This allows a check for when to decode the mangling. 572 if ( IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ) ) { 573 assert( ifStmt->thenPart ); 574 } 575 // Encode the catchStmt so the condition can see the declaration. 569 576 if ( catchStmt->cond ) { 570 findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer ); 577 IfStmt * ifStmt = new IfStmt( catchStmt->cond, nullptr, catchStmt->body ); 578 catchStmt->cond = nullptr; 579 catchStmt->body = ifStmt; 580 } 581 } 582 583 void Resolver_old::postvisit( CatchStmt * catchStmt ) { 584 // Decode the catchStmt so everything is stored properly. 585 IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ); 586 if ( nullptr != ifStmt && nullptr == ifStmt->thenPart ) { 587 assert( ifStmt->condition ); 588 assert( ifStmt->elsePart ); 589 catchStmt->cond = ifStmt->condition; 590 catchStmt->body = ifStmt->elsePart; 591 ifStmt->condition = nullptr; 592 ifStmt->elsePart = nullptr; 593 delete ifStmt; 571 594 } 572 595 } … … 1466 1489 1467 1490 const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) { 1491 // TODO: This will need a fix for the decl/cond scoping problem. 1468 1492 if ( catchStmt->cond ) { 1469 1493 ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool }; -
src/SymTab/Demangle.cc
r8c50aed ra505021 10 10 // Created On : Thu Jul 19 12:52:41 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 14:54:15 201913 // Update Count : 412 // Last Modified On : Tue Feb 11 15:09:18 2020 13 // Update Count : 10 14 14 // 15 15 … … 19 19 #include "CodeGen/GenType.h" 20 20 #include "Common/PassVisitor.h" 21 #include "Common/utility.h" // isPrefix 21 22 #include "Mangler.h" 22 23 #include "SynTree/Type.h" … … 416 417 417 418 bool StringView::isPrefix(const std::string & pref) { 418 if ( pref.size() > str.size()-idx ) return false; 419 auto its = std::mismatch( pref.begin(), pref.end(), std::next(str.begin(), idx) ); 420 if (its.first == pref.end()) { 419 // if ( pref.size() > str.size()-idx ) return false; 420 // auto its = std::mismatch( pref.begin(), pref.end(), std::next(str.begin(), idx) ); 421 // if (its.first == pref.end()) { 422 // idx += pref.size(); 423 // return true; 424 // } 425 426 // This update is untested because there are no tests for this code. 427 if ( ::isPrefix( str, pref, idx ) ) { 421 428 idx += pref.size(); 422 429 return true; … … 429 436 PRINT( std::cerr << "====== " << str.size() << " " << str << std::endl; ) 430 437 if (str.size() < 2+Encoding::manglePrefix.size()) return false; // +2 for at least _1 suffix 431 if ( ! isPrefix(Encoding::manglePrefix) || ! isdigit(str.back())) return false;438 if ( ! isPrefix(Encoding::manglePrefix) || ! isdigit(str.back() ) ) return false; 432 439 433 440 // get name -
src/SymTab/Mangler.cc
r8c50aed ra505021 10 10 // Created On : Sun May 17 21:40:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:43:49 201913 // Update Count : 2812 // Last Modified On : Sat Feb 15 13:55:12 2020 13 // Update Count : 33 14 14 // 15 15 #include "Mangler.h" … … 128 128 } // if 129 129 mangleName << Encoding::manglePrefix; 130 CodeGen::OperatorInfo opInfo;131 if ( op eratorLookup( declaration->get_name(), opInfo )) {132 mangleName << opInfo .outputName.size() << opInfo.outputName;130 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( declaration->get_name() ); 131 if ( opInfo ) { 132 mangleName << opInfo->outputName.size() << opInfo->outputName; 133 133 } else { 134 134 mangleName << declaration->name.size() << declaration->name; … … 471 471 } // if 472 472 mangleName << Encoding::manglePrefix; 473 CodeGen::OperatorInfo opInfo;474 if ( op eratorLookup( decl->name, opInfo )) {475 mangleName << opInfo .outputName.size() << opInfo.outputName;473 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( decl->name ); 474 if ( opInfo ) { 475 mangleName << opInfo->outputName.size() << opInfo->outputName; 476 476 } else { 477 477 mangleName << decl->name.size() << decl->name; -
src/SymTab/Validate.cc
r8c50aed ra505021 311 311 Stats::Heap::newPass("validate-A"); 312 312 Stats::Time::BlockGuard guard("validate-A"); 313 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 313 314 acceptAll( translationUnit, hoistDecls ); 314 315 ReplaceTypedef::replaceTypedef( translationUnit ); … … 336 337 Stats::Time::BlockGuard guard("validate-C"); 337 338 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes_old 338 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors339 339 ReturnChecker::checkFunctionReturns( translationUnit ); 340 340 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen … … 1182 1182 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. 1183 1183 if ( params.size() == 0 ) { 1184 SemanticError( funcDecl , "Constructors, destructors, and assignment functions require at least one parameter" );1184 SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." ); 1185 1185 } 1186 1186 ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() ); 1187 1187 if ( ! refType ) { 1188 SemanticError( funcDecl , "First parameter of a constructor, destructor, or assignment function must be a reference" );1188 SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." ); 1189 1189 } 1190 1190 if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) { 1191 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " ); 1191 if(!returnVals.front()->get_type()->isVoid()) { 1192 SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." ); 1193 } 1192 1194 } 1193 1195 } -
src/SynTree/Attribute.h
r8c50aed ra505021 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:54:14 201713 // Update Count : 3912 // Last Modified On : Thu Feb 13 21:34:08 2020 13 // Update Count : 40 14 14 // 15 15 … … 38 38 virtual ~Attribute(); 39 39 40 std::stringget_name() const { return name; }40 const std::string & get_name() const { return name; } 41 41 void set_name( const std::string & newValue ) { name = newValue; } 42 42 std::list< Expression * > & get_parameters() { return parameters; } -
src/cfa.make
r8c50aed ra505021 32 32 am__v_GOC_1 = 33 33 34 AM_V_PY = $(am__v_PY_@AM_V@) 35 am__v_PY_ = $(am__v_PY_@AM_DEFAULT_V@) 36 am__v_PY_0 = @echo " PYTHON " $@; 37 am__v_PY_1 = 38 34 39 AM_V_RUST = $(am__v_RUST_@AM_V@) 35 40 am__v_RUST_ = $(am__v_RUST_@AM_DEFAULT_V@) 36 am__v_RUST_0 = @echo " RUST 41 am__v_RUST_0 = @echo " RUST " $@; 37 42 am__v_RUST_1 = 38 43 39 44 AM_V_NODEJS = $(am__v_NODEJS_@AM_V@) 40 45 am__v_NODEJS_ = $(am__v_NODEJS_@AM_DEFAULT_V@) 41 am__v_NODEJS_0 = @echo " NODEJS 46 am__v_NODEJS_0 = @echo " NODEJS " $@; 42 47 am__v_NODEJS_1 = 43 48 -
src/main.cc
r8c50aed ra505021 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 16 17:55:53 201913 // Update Count : 6 2712 // Last Modified On : Sat Feb 8 08:33:50 2020 13 // Update Count : 633 14 14 // 15 15 … … 105 105 106 106 static void backtrace( int start ) { // skip first N stack frames 107 enum { Frames = 50 };107 enum { Frames = 50, }; // maximum number of stack frames 108 108 void * array[Frames]; 109 int size = ::backtrace( array, Frames );109 size_t size = ::backtrace( array, Frames ); 110 110 char ** messages = ::backtrace_symbols( array, size ); // does not demangle names 111 111 … … 114 114 115 115 // skip last 2 stack frames after main 116 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {116 for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) { 117 117 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 118 118 … … 180 180 } // sigSegvBusHandler 181 181 182 static void sigFpeHandler( SIGPARMS ) { 183 const char * msg; 184 185 switch ( sfp->si_code ) { 186 case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break; 187 case FPE_FLTOVF: msg = "overflow"; break; 188 case FPE_FLTUND: msg = "underflow"; break; 189 case FPE_FLTRES: msg = "inexact result"; break; 190 case FPE_FLTINV: msg = "invalid operation"; break; 191 default: msg = "unknown"; 192 } // choose 193 cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl 194 << "Possible cause is constant-expression evaluation invalid." << endl; 195 backtrace( 2 ); // skip first 2 stack frames 196 abort(); // cause core dump for debugging 197 } // sigFpeHandler 198 182 199 static void sigAbortHandler( SIGPARMS ) { 183 200 backtrace( 6 ); // skip first 6 stack frames … … 193 210 Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); 194 211 Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO ); 212 Signal( SIGFPE, sigFpeHandler, SA_SIGINFO ); 195 213 Signal( SIGABRT, sigAbortHandler, SA_SIGINFO ); 196 214
Note: See TracChangeset
for help on using the changeset viewer.