- Timestamp:
- May 23, 2017, 9:55:37 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 27dde72
- Parents:
- 547e9b7 (diff), 935315d (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:
-
- 2 added
- 12 edited
- 1 moved
-
CodeGen/GenType.cc (modified) (2 diffs)
-
GenPoly/InstantiateGeneric.cc (modified) (2 diffs)
-
InitTweak/FixInit.cc (modified) (2 diffs)
-
Parser/ExpressionNode.cc (modified) (3 diffs)
-
Parser/lex.ll (modified) (3 diffs)
-
Parser/parser.yy (modified) (4 diffs)
-
SymTab/Validate.cc (modified) (3 diffs)
-
SynTree/TypeSubstitution.cc (modified) (1 diff)
-
libcfa/gmp (modified) (2 diffs)
-
main.cc (modified) (4 diffs)
-
tests/.expect/64/gmp.txt (moved) (moved from src/tests/.expect/gmp.txt ) (2 diffs)
-
tests/.expect/complex.txt (added)
-
tests/complex.c (added)
-
tests/gmp.c (modified) (5 diffs)
-
tests/tuplePolymorphism.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/GenType.cc
r547e9b7 reb182b0 237 237 void GenType::visit( TupleType * tupleType ) { 238 238 assertf( ! genC, "Tuple types should not reach code generation." ); 239 Visitor::visit( tupleType );240 239 unsigned int i = 0; 241 240 std::ostringstream os; … … 245 244 os << genType( t, "", pretty, genC, lineMarks ) << (i == tupleType->size() ? "" : ", "); 246 245 } 247 os << "] ";246 os << "] "; 248 247 typeString = os.str() + typeString; 249 248 } -
src/GenPoly/InstantiateGeneric.cc
r547e9b7 reb182b0 367 367 concDecl->set_body( inst->get_baseStruct()->has_body() ); 368 368 substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() ); 369 DeclMutator::addDeclaration( concDecl ); 370 insert( inst, typeSubs, concDecl ); 369 insert( inst, typeSubs, concDecl ); // must insert before recursion 371 370 concDecl->acceptMutator( *this ); // recursively instantiate members 371 DeclMutator::addDeclaration( concDecl ); // must occur before declaration is added so that member instantiations appear first 372 372 } 373 373 StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() ); … … 422 422 concDecl->set_body( inst->get_baseUnion()->has_body() ); 423 423 substituteMembers( inst->get_baseUnion()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() ); 424 DeclMutator::addDeclaration( concDecl ); 425 insert( inst, typeSubs, concDecl ); 424 insert( inst, typeSubs, concDecl ); // must insert before recursion 426 425 concDecl->acceptMutator( *this ); // recursively instantiate members 426 DeclMutator::addDeclaration( concDecl ); // must occur before declaration is added so that member instantiations appear first 427 427 } 428 428 UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() ); -
src/InitTweak/FixInit.cc
r547e9b7 reb182b0 619 619 620 620 Expression * FixCopyCtors::mutate( StmtExpr * stmtExpr ) { 621 stmtExpr = safe_dynamic_cast< StmtExpr * >( Parent::mutate( stmtExpr ) ); 621 // function call temporaries should be placed at statement-level, rather than nested inside of a new statement expression, 622 // since temporaries can be shared across sub-expressions, e.g. 623 // [A, A] f(); 624 // g([A] x, [A] y); 625 // f(g()); 626 // f is executed once, so the return temporary is shared across the tuple constructors for x and y. 627 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 628 for ( Statement *& stmt : stmts ) { 629 stmt = stmt->acceptMutator( *this ); 630 } // for 631 // stmtExpr = safe_dynamic_cast< StmtExpr * >( Parent::mutate( stmtExpr ) ); 622 632 assert( stmtExpr->get_result() ); 623 633 Type * result = stmtExpr->get_result(); … … 886 896 Parent::visit( compoundStmt ); 887 897 888 // add destructors for the current scope that we're exiting 898 // add destructors for the current scope that we're exiting, unless the last statement is a return, which 899 // causes unreachable code warnings 889 900 std::list< Statement * > & statements = compoundStmt->get_kids(); 890 insertDtors( reverseDeclOrder.front().begin(), reverseDeclOrder.front().end(), back_inserter( statements ) ); 901 if ( ! statements.empty() && ! dynamic_cast< ReturnStmt * >( statements.back() ) ) { 902 insertDtors( reverseDeclOrder.front().begin(), reverseDeclOrder.front().end(), back_inserter( statements ) ); 903 } 891 904 reverseDeclOrder.pop_front(); 892 905 } -
src/Parser/ExpressionNode.cc
r547e9b7 reb182b0 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 30 17:02:46201713 // Update Count : 5 1512 // Last Modified On : Wed May 17 21:31:01 2017 13 // Update Count : 527 14 14 // 15 15 … … 207 207 } // build_field_name_fraction_constants 208 208 209 210 209 211 Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) { 210 assert( str[0] == '.');212 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 211 213 Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) ); 212 214 delete &str; … … 215 217 216 218 Expression * build_field_name_REALDECIMALconstant( const std::string & str ) { 217 assert( str[str.size()-1] == '.');219 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 218 220 Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) ); 219 221 delete &str; -
src/Parser/lex.ll
r547e9b7 reb182b0 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Mon Mar 13 08:36:17201713 * Update Count : 5 0612 * Last Modified On : Thu May 18 09:03:49 2017 13 * Update Count : 513 14 14 */ 15 15 … … 77 77 // numeric constants, CFA: '_' in constant 78 78 hex_quad {hex}("_"?{hex}){3} 79 integer_suffix "_"?(([uU] [lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?)79 integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?))) 80 80 81 81 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) … … 91 91 92 92 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 93 real_decimal {decimal_digits}"." 94 real_fraction "."{decimal_digits} 95 real_constant {decimal_digits} ?{real_fraction}93 real_decimal {decimal_digits}"."{exponent}?{floating_suffix}? 94 real_fraction "."{decimal_digits}{exponent}?{floating_suffix}? 95 real_constant {decimal_digits}{real_fraction} 96 96 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 97 // GCC: D (double), DL (long double) and iI (imaginary) suffixes 98 floating_suffix "_"?([fFdDlL][iI]?|"DL"|[iI][lLfFdD]?) 99 //floating_suffix "_"?([fFdD]|[lL]|[D][L])|([iI][lLfFdD])|([lLfFdD][iI])) 97 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 98 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL") 100 99 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}? 101 100 -
src/Parser/parser.yy
r547e9b7 reb182b0 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Ma r 30 15:42:32201713 // Update Count : 23 1812 // Last Modified On : Thu May 18 18:06:17 2017 13 // Update Count : 2338 14 14 // 15 15 … … 85 85 } // for 86 86 } // distExt 87 88 bool forall = false; // aggregate have one or more forall qualifiers ? 87 89 %} 88 90 … … 1556 1558 sue_type_specifier: // struct, union, enum + type specifier 1557 1559 elaborated_type 1558 | type_qualifier_list elaborated_type 1559 { $$ = $2->addQualifiers( $1 ); } 1560 | type_qualifier_list 1561 { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type 1562 elaborated_type 1563 { $$ = $3->addQualifiers( $1 ); } 1560 1564 | sue_type_specifier type_qualifier 1561 1565 { $$ = $1->addQualifiers( $2 ); } … … 1613 1617 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1614 1618 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1615 { typedefTable.makeTypedef( *$3 ); } 1619 { 1620 typedefTable.makeTypedef( *$3 ); // create typedef 1621 if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update 1622 forall = false; // reset 1623 } 1616 1624 '{' field_declaration_list '}' 1617 1625 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } -
src/SymTab/Validate.cc
r547e9b7 reb182b0 208 208 }; 209 209 210 /// ensure that generic types have the correct number of type arguments 211 class ValidateGenericParameters : public Visitor { 212 public: 213 typedef Visitor Parent; 214 virtual void visit( StructInstType * inst ) final override; 215 virtual void visit( UnionInstType * inst ) final override; 216 }; 217 210 218 class ArrayLength : public Visitor { 211 219 public: … … 235 243 Pass3 pass3( 0 ); 236 244 CompoundLiteral compoundliteral; 237 238 HoistStruct::hoistStruct( translationUnit ); 245 ValidateGenericParameters genericParams; 246 239 247 EliminateTypedef::eliminateTypedef( translationUnit ); 248 HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order 240 249 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 241 250 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 251 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes 242 252 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist 243 253 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors … … 829 839 } 830 840 841 template< typename Aggr > 842 void validateGeneric( Aggr * inst ) { 843 std::list< TypeDecl * > * params = inst->get_baseParameters(); 844 if ( params != NULL ) { 845 std::list< Expression * > & args = inst->get_parameters(); 846 if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst ); 847 if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst ); 848 } 849 } 850 851 void ValidateGenericParameters::visit( StructInstType * inst ) { 852 validateGeneric( inst ); 853 Parent::visit( inst ); 854 } 855 856 void ValidateGenericParameters::visit( UnionInstType * inst ) { 857 validateGeneric( inst ); 858 Parent::visit( inst ); 859 } 860 831 861 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) { 832 862 storageClasses = objectDecl->get_storageClasses(); -
src/SynTree/TypeSubstitution.cc
r547e9b7 reb182b0 166 166 boundVars.insert( (*tyvar )->get_name() ); 167 167 } // for 168 } // if169 // bind type variables from generic type instantiations170 std::list< TypeDecl* > *baseParameters = type->get_baseParameters();171 if ( baseParameters && ! type->get_parameters().empty()) {172 for ( std::list< TypeDecl* >::const_iterator tyvar = baseParameters->begin(); tyvar != baseParameters->end(); ++tyvar ) {173 boundVars.insert( (*tyvar)->get_name() );174 } // for168 // bind type variables from generic type instantiations 169 std::list< TypeDecl* > *baseParameters = type->get_baseParameters(); 170 if ( baseParameters && ! type->get_parameters().empty() ) { 171 for ( std::list< TypeDecl* >::const_iterator tyvar = baseParameters->begin(); tyvar != baseParameters->end(); ++tyvar ) { 172 boundVars.insert( (*tyvar)->get_name() ); 173 } // for 174 } // if 175 175 } // if 176 176 Type *ret = Mutator::mutate( type ); -
src/libcfa/gmp
r547e9b7 reb182b0 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 14 23:47:36201713 // Update Count : 912 // Last Modified On : Mon May 22 08:32:39 2017 13 // Update Count : 13 14 14 // 15 15 … … 35 35 Int ?=?( Int * lhs, long int rhs ) { mpz_set_si( lhs->mpz, rhs ); return *lhs; } 36 36 Int ?=?( Int * lhs, unsigned long int rhs ) { mpz_set_ui( lhs->mpz, rhs ); return *lhs; } 37 //Int ?=?( Int * lhs, const char * rhs ) { if ( mpq_set_str( lhs->mpz, rhs, 0 ) ) abort();return *lhs; }37 Int ?=?( Int * lhs, const char * rhs ) { if ( mpz_set_str( lhs->mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return *lhs; } 38 38 39 39 char ?=?( char * lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); *lhs = val; return val; } -
src/main.cc
r547e9b7 reb182b0 64 64 bresolvep = false, 65 65 bboxp = false, 66 bcodegenp = false, 66 67 ctorinitp = false, 67 68 declstatsp = false, … … 306 307 OPTPRINT( "box" ) 307 308 GenPoly::box( translationUnit ); 309 310 if ( bcodegenp ) { 311 dump( translationUnit ); 312 return 0; 313 } 308 314 309 315 if ( optind < argc ) { // any commands after the flags and input file ? => output file name … … 377 383 378 384 int c; 379 while ( (c = getopt_long( argc, argv, "abBc defglLmnpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {385 while ( (c = getopt_long( argc, argv, "abBcCdefglLmnpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) { 380 386 switch ( c ) { 381 387 case Ast: … … 393 399 case 'c': // print after constructors and destructors are replaced 394 400 ctorinitp = true; 401 break; 402 case 'C': // print before code generation 403 bcodegenp = true; 395 404 break; 396 405 case DeclStats: -
src/tests/.expect/64/gmp.txt
r547e9b7 reb182b0 4 4 conversions 5 5 y:97 6 y:12345678901234567890123456789 6 7 y:3 7 8 y:-3 … … 24 25 z:150000000000000000000 25 26 z:16666666666666666666 27 16666666666666666666, 2 16666666666666666666, 2 26 28 x:16666666666666666666 y:2 27 29 -
src/tests/gmp.c
r547e9b7 reb182b0 10 10 // Created On : Tue Apr 19 08:55:51 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 14 14:46:50201713 // Update Count : 53 012 // Last Modified On : Mon May 22 09:05:09 2017 13 // Update Count : 538 14 14 // 15 15 16 16 #include <gmp> 17 17 18 int main( ) {18 int main( void ) { 19 19 sout | "constructors" | endl; 20 20 short int si = 3; … … 25 25 sout | "conversions" | endl; 26 26 y = 'a'; 27 sout | "y:" | y | endl; 28 y = "12345678901234567890123456789"; 27 29 sout | "y:" | y | endl; 28 30 y = si; … … 62 64 z = x / 3; 63 65 sout | "z:" | z | endl; 66 sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl; 64 67 [ x, y ] = div( x, 3 ); 65 68 sout | "x:" | x | "y:" | y | endl; 66 // sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;67 69 68 70 sout | endl; … … 72 74 fn = (Int){0}; fn1 = fn; // 1st case 73 75 sout | (int)0 | fn | endl; 74 fn = (Int){1}; fn2 = fn1; fn1 = fn;// 2nd case76 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 75 77 sout | 1 | fn | endl; 76 for ( int i = 2; i <= 200; i += 1 ) {78 for ( unsigned int i = 2; i <= 200; i += 1 ) { 77 79 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 78 80 sout | i | fn | endl; … … 83 85 sout | "Factorial Numbers" | endl; 84 86 Int fact; 85 fact = (Int){1};// 1st case87 fact = 1; // 1st case 86 88 sout | (int)0 | fact | endl; 87 for ( int i = 1; i <= 40; i += 1 ) {89 for ( unsigned int i = 1; i <= 40; i += 1 ) { 88 90 fact = fact * i; // general case 89 91 sout | i | fact | endl; -
src/tests/tuplePolymorphism.c
r547e9b7 reb182b0 9 9 // Author : Rob Schluntz 10 10 // Created On : Tue Nov 16 10:38:00 2016 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T ue Nov 16 10:39:18 201613 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 18 18:05:12 2017 13 // Update Count : 4 14 14 // 15 15 16 16 // packed is needed so that structs are not passed with the same alignment as function arguments 17 17 __attribute__((packed)) struct A { 18 double x;19 char y;20 double z;18 double x; 19 char y; 20 double z; 21 21 }; 22 22 23 23 __attribute__((packed)) struct B { 24 long long x;25 char y;26 long long z;24 long long x; 25 char y; 26 long long z; 27 27 }; 28 28 … … 39 39 40 40 int main() { 41 int x1 = 123, x3 = 456;42 double x2 = 999.123;41 int x1 = 123, x3 = 456; 42 double x2 = 999.123; 43 43 44 int i1 = 111, i3 = 222;45 double i2 = 333;44 int i1 = 111, i3 = 222; 45 double i2 = 333; 46 46 47 int d1 = 555, d3 = 444;48 double d2 = 666;47 int d1 = 555, d3 = 444; 48 double d2 = 666; 49 49 50 50 51 [i1, i2, i3] = ([x1, (int)x2, x3]) + ([9, 2, 3]);52 [d1, d2, d3] = ([x1, x2, x3]) + ([9, 2, 3]);53 printf("%d %g %d\n", i1, i2, i3);54 printf("%d %g %d\n", d1, d2, d3);51 [i1, i2, i3] = ([x1, (int)x2, x3]) + ([9, 2, 3]); 52 [d1, d2, d3] = ([x1, x2, x3]) + ([9, 2, 3]); 53 printf("%d %g %d\n", i1, i2, i3); 54 printf("%d %g %d\n", d1, d2, d3); 55 55 56 [double, double, double] zzz;57 zzz = [x1, x2, x3];58 printf("%g %g %g\n", zzz);59 [x1, x2, x3] = zzz+zzz;60 printf("%d %g %d\n", x1, x2, x3);56 [double, double, double] zzz; 57 zzz = [x1, x2, x3]; 58 printf("%g %g %g\n", zzz); 59 [x1, x2, x3] = zzz+zzz; 60 printf("%d %g %d\n", x1, x2, x3); 61 61 62 // ensure non-matching assertions are specialized correctly63 g((A){ 1.21, 'x', 10.21}, (B){ 1111LL, 'v', 54385938LL });62 // ensure non-matching assertions are specialized correctly 63 g((A){ 1.21, 'x', 10.21}, (B){ 1111LL, 'v', 54385938LL }); 64 64 } 65 65 … … 73 73 // tab-width: 4 // 74 74 // End: // 75
Note:
See TracChangeset
for help on using the changeset viewer.