Changeset eb182b0 for src


Ignore:
Timestamp:
May 23, 2017, 9:55:37 AM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
2 added
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/CodeGen/GenType.cc

    r547e9b7 reb182b0  
    237237        void GenType::visit( TupleType * tupleType ) {
    238238                assertf( ! genC, "Tuple types should not reach code generation." );
    239                 Visitor::visit( tupleType );
    240239                unsigned int i = 0;
    241240                std::ostringstream os;
     
    245244                        os << genType( t, "", pretty, genC, lineMarks ) << (i == tupleType->size() ? "" : ", ");
    246245                }
    247                 os << "]";
     246                os << "] ";
    248247                typeString = os.str() + typeString;
    249248        }
  • src/GenPoly/InstantiateGeneric.cc

    r547e9b7 reb182b0  
    367367                                concDecl->set_body( inst->get_baseStruct()->has_body() );
    368368                                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
    371370                                concDecl->acceptMutator( *this ); // recursively instantiate members
     371                                DeclMutator::addDeclaration( concDecl ); // must occur before declaration is added so that member instantiations appear first
    372372                        }
    373373                        StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() );
     
    422422                                concDecl->set_body( inst->get_baseUnion()->has_body() );
    423423                                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
    426425                                concDecl->acceptMutator( *this ); // recursively instantiate members
     426                                DeclMutator::addDeclaration( concDecl ); // must occur before declaration is added so that member instantiations appear first
    427427                        }
    428428                        UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() );
  • src/InitTweak/FixInit.cc

    r547e9b7 reb182b0  
    619619
    620620                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 ) );
    622632                        assert( stmtExpr->get_result() );
    623633                        Type * result = stmtExpr->get_result();
     
    886896                        Parent::visit( compoundStmt );
    887897
    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
    889900                        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                        }
    891904                        reverseDeclOrder.pop_front();
    892905                }
  • src/Parser/ExpressionNode.cc

    r547e9b7 reb182b0  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 17:02:46 2017
    13 // Update Count     : 515
     12// Last Modified On : Wed May 17 21:31:01 2017
     13// Update Count     : 527
    1414//
    1515
     
    207207} // build_field_name_fraction_constants
    208208
     209
     210
    209211Expression * 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 );
    211213        Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) );
    212214        delete &str;
     
    215217
    216218Expression * 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 );
    218220        Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) );
    219221        delete &str;
  • src/Parser/lex.ll

    r547e9b7 reb182b0  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon Mar 13 08:36:17 2017
    13  * Update Count     : 506
     12 * Last Modified On : Thu May 18 09:03:49 2017
     13 * Update Count     : 513
    1414 */
    1515
     
    7777                                // numeric constants, CFA: '_' in constant
    7878hex_quad {hex}("_"?{hex}){3}
    79 integer_suffix "_"?(([uU][lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?)
     79integer_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]?)))
    8080
    8181octal_digits ({octal})|({octal}({octal}|"_")*{octal})
     
    9191
    9292decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    93 real_decimal {decimal_digits}"."
    94 real_fraction "."{decimal_digits}
    95 real_constant {decimal_digits}?{real_fraction}
     93real_decimal {decimal_digits}"."{exponent}?{floating_suffix}?
     94real_fraction "."{decimal_digits}{exponent}?{floating_suffix}?
     95real_constant {decimal_digits}{real_fraction}
    9696exponent "_"?[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)
     98floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL")
    10099floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}?
    101100
  • src/Parser/parser.yy

    r547e9b7 reb182b0  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 15:42:32 2017
    13 // Update Count     : 2318
     12// Last Modified On : Thu May 18 18:06:17 2017
     13// Update Count     : 2338
    1414//
    1515
     
    8585        } // for
    8686} // distExt
     87
     88bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    8789%}
    8890
     
    15561558sue_type_specifier:                                                                             // struct, union, enum + type specifier
    15571559        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 ); }
    15601564        | sue_type_specifier type_qualifier
    15611565                { $$ = $1->addQualifiers( $2 ); }
     
    16131617                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    16141618        | 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                }
    16161624          '{' field_declaration_list '}'
    16171625                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
  • src/SymTab/Validate.cc

    r547e9b7 reb182b0  
    208208        };
    209209
     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
    210218        class ArrayLength : public Visitor {
    211219        public:
     
    235243                Pass3 pass3( 0 );
    236244                CompoundLiteral compoundliteral;
    237 
    238                 HoistStruct::hoistStruct( translationUnit );
     245                ValidateGenericParameters genericParams;
     246
    239247                EliminateTypedef::eliminateTypedef( translationUnit );
     248                HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
    240249                ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
    241250                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
    242252                acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist
    243253                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
     
    829839        }
    830840
     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
    831861        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
    832862                storageClasses = objectDecl->get_storageClasses();
  • src/SynTree/TypeSubstitution.cc

    r547e9b7 reb182b0  
    166166                        boundVars.insert( (*tyvar )->get_name() );
    167167                } // for
    168         } // if
    169         // bind type variables from generic type instantiations
    170         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                 } // for
     168                // 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
    175175        } // if
    176176        Type *ret = Mutator::mutate( type );
  • src/libcfa/gmp

    r547e9b7 reb182b0  
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 14 23:47:36 2017
    13 // Update Count     : 9
     12// Last Modified On : Mon May 22 08:32:39 2017
     13// Update Count     : 13
    1414//
    1515
     
    3535Int ?=?( Int * lhs, long int rhs ) { mpz_set_si( lhs->mpz, rhs ); return *lhs; }
    3636Int ?=?( 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; }
     37Int ?=?( Int * lhs, const char * rhs ) { if ( mpz_set_str( lhs->mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return *lhs; }
    3838
    3939char ?=?( char * lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }
  • src/main.cc

    r547e9b7 reb182b0  
    6464        bresolvep = false,
    6565        bboxp = false,
     66        bcodegenp = false,
    6667        ctorinitp = false,
    6768        declstatsp = false,
     
    306307                OPTPRINT( "box" )
    307308                GenPoly::box( translationUnit );
     309
     310                if ( bcodegenp ) {
     311                        dump( translationUnit );
     312                        return 0;
     313                }
    308314
    309315                if ( optind < argc ) {                                                  // any commands after the flags and input file ? => output file name
     
    377383
    378384        int c;
    379         while ( (c = getopt_long( argc, argv, "abBcdefglLmnpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {
     385        while ( (c = getopt_long( argc, argv, "abBcCdefglLmnpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {
    380386                switch ( c ) {
    381387                  case Ast:
     
    393399                  case 'c':                                                                             // print after constructors and destructors are replaced
    394400                        ctorinitp = true;
     401                        break;
     402                  case 'C':                                                                             // print before code generation
     403                        bcodegenp = true;
    395404                        break;
    396405                  case DeclStats:
  • src/tests/.expect/64/gmp.txt

    r547e9b7 reb182b0  
    44conversions
    55y:97
     6y:12345678901234567890123456789
    67y:3
    78y:-3
     
    2425z:150000000000000000000
    2526z:16666666666666666666
     2716666666666666666666, 2 16666666666666666666, 2
    2628x:16666666666666666666 y:2
    2729
  • src/tests/gmp.c

    r547e9b7 reb182b0  
    1010// Created On       : Tue Apr 19 08:55:51 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 14 14:46:50 2017
    13 // Update Count     : 530
     12// Last Modified On : Mon May 22 09:05:09 2017
     13// Update Count     : 538
    1414//
    1515
    1616#include <gmp>
    1717
    18 int main() {
     18int main( void ) {
    1919        sout | "constructors" | endl;
    2020        short int si = 3;
     
    2525        sout | "conversions" | endl;
    2626        y = 'a';
     27        sout | "y:" | y | endl;
     28        y = "12345678901234567890123456789";
    2729        sout | "y:" | y | endl;
    2830        y = si;
     
    6264        z = x / 3;
    6365        sout | "z:" | z | endl;
     66        sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;
    6467        [ x, y ] = div( x, 3 );
    6568        sout | "x:" | x | "y:" | y | endl;
    66 //      sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;
    6769
    6870        sout | endl;
     
    7274        fn = (Int){0}; fn1 = fn;                                                        // 1st case
    7375        sout | (int)0 | fn | endl;
    74         fn = (Int){1}; fn2 = fn1; fn1 = fn;                                     // 2nd case
     76        fn = 1; fn2 = fn1; fn1 = fn;                                            // 2nd case
    7577        sout | 1 | fn | endl;
    76         for ( int i = 2; i <= 200; i += 1 ) {
     78        for ( unsigned int i = 2; i <= 200; i += 1 ) {
    7779                fn = fn1 + fn2; fn2 = fn1; fn1 = fn;                    // general case
    7880                sout | i | fn | endl;
     
    8385        sout | "Factorial Numbers" | endl;
    8486        Int fact;
    85         fact = (Int){1};                                                                        // 1st case
     87        fact = 1;                                                                                       // 1st case
    8688        sout | (int)0 | fact | endl;
    87         for ( int i = 1; i <= 40; i += 1 ) {
     89        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    8890                fact = fact * i;                                                                // general case
    8991                sout | i | fact | endl;
  • src/tests/tuplePolymorphism.c

    r547e9b7 reb182b0  
    99// Author           : Rob Schluntz
    1010// Created On       : Tue Nov 16 10:38:00 2016
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Nov 16 10:39:18 2016
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu May 18 18:05:12 2017
     13// Update Count     : 4
    1414//
    1515
    1616// packed is needed so that structs are not passed with the same alignment as function arguments
    1717__attribute__((packed)) struct A {
    18   double x;
    19   char y;
    20   double z;
     18        double x;
     19        char y;
     20        double z;
    2121};
    2222
    2323__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;
    2727};
    2828
     
    3939
    4040int main() {
    41   int x1 = 123, x3 = 456;
    42   double x2 = 999.123;
     41        int x1 = 123, x3 = 456;
     42        double x2 = 999.123;
    4343
    44   int i1 = 111, i3 = 222;
    45   double i2 = 333;
     44        int i1 = 111, i3 = 222;
     45        double i2 = 333;
    4646
    47   int d1 = 555, d3 = 444;
    48   double d2 = 666;
     47        int d1 = 555, d3 = 444;
     48        double d2 = 666;
    4949
    5050
    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);
    5555
    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);
    6161
    62   // ensure non-matching assertions are specialized correctly
    63   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 });
    6464}
    6565
     
    7373// tab-width: 4 //
    7474// End: //
    75 
Note: See TracChangeset for help on using the changeset viewer.