Changes in / [579263a:2a7b3ca]
- Location:
- src
- Files:
-
- 2 deleted
- 24 edited
-
CodeGen/CodeGenerator.cc (modified) (3 diffs)
-
CodeGen/CodeGenerator.h (modified) (2 diffs)
-
Common/utility.h (modified) (1 diff)
-
InitTweak/FixInit.cc (modified) (1 diff)
-
InitTweak/InitTweak.cc (modified) (1 diff)
-
MakeLibCfa.cc (modified) (1 diff)
-
Makefile.in (modified) (6 diffs)
-
Parser/InitializerNode.cc (modified) (1 diff)
-
Parser/TypeData.cc (modified) (1 diff)
-
ResolvExpr/AlternativeFinder.cc (modified) (2 diffs)
-
ResolvExpr/AlternativeFinder.h (modified) (1 diff)
-
ResolvExpr/CurrentObject.cc (deleted)
-
ResolvExpr/CurrentObject.h (deleted)
-
ResolvExpr/Resolver.cc (modified) (8 diffs)
-
ResolvExpr/module.mk (modified) (2 diffs)
-
SymTab/Autogen.h (modified) (3 diffs)
-
SynTree/Expression.cc (modified) (2 diffs)
-
SynTree/Expression.h (modified) (1 diff)
-
SynTree/Initializer.cc (modified) (3 diffs)
-
SynTree/Initializer.h (modified) (7 diffs)
-
SynTree/Mutator.cc (modified) (3 diffs)
-
SynTree/Mutator.h (modified) (2 diffs)
-
SynTree/SynTree.h (modified) (2 diffs)
-
SynTree/Visitor.cc (modified) (3 diffs)
-
SynTree/Visitor.h (modified) (2 diffs)
-
Tuples/TupleExpansion.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r579263a r2a7b3ca 288 288 } 289 289 290 void CodeGenerator:: visit( Designation * designation) {291 std::list< Expression * > designators = designation->get_designators();290 void CodeGenerator::printDesignators( std::list< Expression * > & designators ) { 291 typedef std::list< Expression * > DesignatorList; 292 292 if ( designators.size() == 0 ) return; 293 for ( Expression * des : designators ) { 294 if ( dynamic_cast< ConstantExpr * >( des ) ) { 295 // if expression is a ConstantExpr, then initializing array element 293 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) { 294 if ( dynamic_cast< NameExpr * >( *iter ) ) { 295 // if expression is a name, then initializing aggregate member 296 output << "."; 297 (*iter)->accept( *this ); 298 } else { 299 // if not a simple name, it has to be a constant expression, i.e. an array designator 296 300 output << "["; 297 des->accept( *this );301 (*iter)->accept( *this ); 298 302 output << "]"; 299 } else {300 // if not a ConstantExpr, it has to be a NameExpr or VariableExpr, initializing aggregate member301 output << ".";302 des->accept( *this );303 303 } // if 304 304 } // for … … 307 307 308 308 void CodeGenerator::visit( SingleInit * init ) { 309 printDesignators( init->get_designators() ); 309 310 init->get_value()->accept( *this ); 310 311 } 311 312 312 313 void CodeGenerator::visit( ListInit * init ) { 313 auto initBegin = init->begin(); 314 auto initEnd = init->end(); 315 auto desigBegin = init->get_designations().begin(); 316 auto desigEnd = init->get_designations().end(); 317 314 printDesignators( init->get_designators() ); 318 315 output << "{ "; 319 for ( ; initBegin != initEnd && desigBegin != desigEnd; ) { 320 (*desigBegin)->accept( *this ); 321 (*initBegin)->accept( *this ); 322 ++initBegin, ++desigBegin; 323 if ( initBegin != initEnd ) { 324 output << ", "; 325 } 326 } 316 genCommaList( init->begin(), init->end() ); 327 317 output << " }"; 328 assertf( initBegin == initEnd && desigBegin == desigEnd, "Initializers and designators not the same length. %s", toString( init ).c_str() );329 318 } 330 319 … … 727 716 728 717 void CodeGenerator::visit( TypeExpr * typeExpr ) { 729 // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl; 730 // assertf( ! genC, "TypeExpr should not reach code generation." ); 731 if ( ! genC ) { 732 output<< genType( typeExpr->get_type(), "", pretty, genC ); 733 } 718 assertf( ! genC, "TypeExpr should not reach code generation." ); 719 output<< genType( typeExpr->get_type(), "", pretty, genC ); 734 720 } 735 721 -
src/CodeGen/CodeGenerator.h
r579263a r2a7b3ca 47 47 48 48 //*** Initializer 49 virtual void visit( Designation * );50 49 virtual void visit( SingleInit * ); 51 50 virtual void visit( ListInit * ); … … 138 137 bool lineMarks = false; 139 138 139 void printDesignators( std::list< Expression * > & ); 140 140 void handleStorageClass( DeclarationWithType *decl ); 141 141 void handleAggregate( AggregateDecl *aggDecl, const std::string & kind ); -
src/Common/utility.h
r579263a r2a7b3ca 305 305 // for ( val : group_iterate( container1, container2, ... ) ) {} 306 306 // syntax to have a for each that iterates multiple containers of the same length 307 // TODO: update to use variadic arguments , perfect forwarding307 // TODO: update to use variadic arguments 308 308 309 309 template< typename T1, typename T2 > -
src/InitTweak/FixInit.cc
r579263a r2a7b3ca 724 724 // static bool __objName_uninitialized = true 725 725 BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool ); 726 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ) );726 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ), noDesignators ); 727 727 ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, boolType, boolInitExpr ); 728 728 isUninitializedVar->fixUniqueId(); -
src/InitTweak/InitTweak.cc
r579263a r2a7b3ca 14 14 public: 15 15 bool hasDesignations = false; 16 virtual void visit( Designation * des ) { 17 if ( ! des->get_designators().empty() ) hasDesignations = true; 18 else Visitor::visit( des ); 19 } 16 template<typename Init> 17 void handleInit( Init * init ) { 18 if ( ! init->get_designators().empty() ) hasDesignations = true; 19 else Visitor::visit( init ); 20 } 21 virtual void visit( SingleInit * singleInit ) { handleInit( singleInit); } 22 virtual void visit( ListInit * listInit ) { handleInit( listInit); } 20 23 }; 21 24 -
src/MakeLibCfa.cc
r579263a r2a7b3ca 92 92 assert( ! objDecl->get_init() ); 93 93 std::list< Expression* > noDesignators; 94 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), false ) ); // cannot be constructed94 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators, false ) ); // cannot be constructed 95 95 newDecls.push_back( objDecl ); 96 96 } -
src/Makefile.in
r579263a r2a7b3ca 161 161 ResolvExpr/driver_cfa_cpp-Occurs.$(OBJEXT) \ 162 162 ResolvExpr/driver_cfa_cpp-TypeEnvironment.$(OBJEXT) \ 163 ResolvExpr/driver_cfa_cpp-CurrentObject.$(OBJEXT) \164 163 SymTab/driver_cfa_cpp-Indexer.$(OBJEXT) \ 165 164 SymTab/driver_cfa_cpp-Mangler.$(OBJEXT) \ … … 415 414 ResolvExpr/RenameVars.cc ResolvExpr/FindOpenVars.cc \ 416 415 ResolvExpr/PolyCost.cc ResolvExpr/Occurs.cc \ 417 ResolvExpr/TypeEnvironment.cc ResolvExpr/CurrentObject.cc \418 SymTab/ Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \419 SymTab/ FixFunction.cc SymTab/ImplementationType.cc \420 SymTab/ TypeEquality.cc SymTab/Autogen.cc SynTree/Type.cc \421 SynTree/ VoidType.cc SynTree/BasicType.cc \422 SynTree/ PointerType.cc SynTree/ArrayType.cc \423 SynTree/ FunctionType.cc SynTree/ReferenceToType.cc \424 SynTree/T upleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \416 ResolvExpr/TypeEnvironment.cc SymTab/Indexer.cc \ 417 SymTab/Mangler.cc SymTab/Validate.cc SymTab/FixFunction.cc \ 418 SymTab/ImplementationType.cc SymTab/TypeEquality.cc \ 419 SymTab/Autogen.cc SynTree/Type.cc SynTree/VoidType.cc \ 420 SynTree/BasicType.cc SynTree/PointerType.cc \ 421 SynTree/ArrayType.cc SynTree/FunctionType.cc \ 422 SynTree/ReferenceToType.cc SynTree/TupleType.cc \ 423 SynTree/TypeofType.cc SynTree/AttrType.cc \ 425 424 SynTree/VarArgsType.cc SynTree/ZeroOneType.cc \ 426 425 SynTree/Constant.cc SynTree/Expression.cc SynTree/TupleExpr.cc \ … … 722 721 ResolvExpr/$(am__dirstamp) \ 723 722 ResolvExpr/$(DEPDIR)/$(am__dirstamp) 724 ResolvExpr/driver_cfa_cpp-CurrentObject.$(OBJEXT): \725 ResolvExpr/$(am__dirstamp) \726 ResolvExpr/$(DEPDIR)/$(am__dirstamp)727 723 SymTab/$(am__dirstamp): 728 724 @$(MKDIR_P) SymTab … … 894 890 -rm -f ResolvExpr/driver_cfa_cpp-CommonType.$(OBJEXT) 895 891 -rm -f ResolvExpr/driver_cfa_cpp-ConversionCost.$(OBJEXT) 896 -rm -f ResolvExpr/driver_cfa_cpp-CurrentObject.$(OBJEXT)897 892 -rm -f ResolvExpr/driver_cfa_cpp-FindOpenVars.$(OBJEXT) 898 893 -rm -f ResolvExpr/driver_cfa_cpp-Occurs.$(OBJEXT) … … 1007 1002 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CommonType.Po@am__quote@ 1008 1003 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ConversionCost.Po@am__quote@ 1009 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Po@am__quote@1010 1004 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-FindOpenVars.Po@am__quote@ 1011 1005 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-Occurs.Po@am__quote@ … … 1949 1943 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-TypeEnvironment.obj `if test -f 'ResolvExpr/TypeEnvironment.cc'; then $(CYGPATH_W) 'ResolvExpr/TypeEnvironment.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/TypeEnvironment.cc'; fi` 1950 1944 1951 ResolvExpr/driver_cfa_cpp-CurrentObject.o: ResolvExpr/CurrentObject.cc1952 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ResolvExpr/driver_cfa_cpp-CurrentObject.o -MD -MP -MF ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Tpo -c -o ResolvExpr/driver_cfa_cpp-CurrentObject.o `test -f 'ResolvExpr/CurrentObject.cc' || echo '$(srcdir)/'`ResolvExpr/CurrentObject.cc1953 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Tpo ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Po1954 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ResolvExpr/CurrentObject.cc' object='ResolvExpr/driver_cfa_cpp-CurrentObject.o' libtool=no @AMDEPBACKSLASH@1955 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1956 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-CurrentObject.o `test -f 'ResolvExpr/CurrentObject.cc' || echo '$(srcdir)/'`ResolvExpr/CurrentObject.cc1957 1958 ResolvExpr/driver_cfa_cpp-CurrentObject.obj: ResolvExpr/CurrentObject.cc1959 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ResolvExpr/driver_cfa_cpp-CurrentObject.obj -MD -MP -MF ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Tpo -c -o ResolvExpr/driver_cfa_cpp-CurrentObject.obj `if test -f 'ResolvExpr/CurrentObject.cc'; then $(CYGPATH_W) 'ResolvExpr/CurrentObject.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/CurrentObject.cc'; fi`1960 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Tpo ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Po1961 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ResolvExpr/CurrentObject.cc' object='ResolvExpr/driver_cfa_cpp-CurrentObject.obj' libtool=no @AMDEPBACKSLASH@1962 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1963 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-CurrentObject.obj `if test -f 'ResolvExpr/CurrentObject.cc'; then $(CYGPATH_W) 'ResolvExpr/CurrentObject.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/CurrentObject.cc'; fi`1964 1965 1945 SymTab/driver_cfa_cpp-Indexer.o: SymTab/Indexer.cc 1966 1946 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-Indexer.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Tpo -c -o SymTab/driver_cfa_cpp-Indexer.o `test -f 'SymTab/Indexer.cc' || echo '$(srcdir)/'`SymTab/Indexer.cc -
src/Parser/InitializerNode.cc
r579263a r2a7b3ca 74 74 75 75 InitializerNode *moreInit; 76 if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {76 if ( get_next() != 0 && ((moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) != 0) ) 77 77 moreInit->printOneLine( os ); 78 }79 78 } 80 79 81 80 Initializer *InitializerNode::build() const { 82 81 if ( aggregate ) { 83 // steal designators from children84 std::list< Designation * > designlist;85 InitializerNode * child = next_init();86 for ( ; child != nullptr; child = dynamic_cast< InitializerNode * >( child->get_next() ) ) {87 std::list< Expression * > desList;88 buildList< Expression, ExpressionNode >( child->designator, desList );89 designlist.push_back( new Designation( desList ) );90 } // for91 82 std::list< Initializer * > initlist; 92 83 buildList< Initializer, InitializerNode >( next_init(), initlist ); 84 85 std::list< Expression * > designlist; 86 87 if ( designator != 0 ) { 88 buildList< Expression, ExpressionNode >( designator, designlist ); 89 } // if 90 93 91 return new ListInit( initlist, designlist, maybeConstructed ); 94 92 } else { 95 if ( get_expression() != 0) { 96 return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed ); 97 } 93 std::list< Expression * > designators; 94 95 if ( designator != 0 ) 96 buildList< Expression, ExpressionNode >( designator, designators ); 97 98 if ( get_expression() != 0) 99 return new SingleInit( maybeBuild< Expression >( get_expression() ), designators, maybeConstructed ); 98 100 } // if 101 99 102 return 0; 100 103 } -
src/Parser/TypeData.cc
r579263a r2a7b3ca 760 760 if ( cur->has_enumeratorValue() ) { 761 761 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 762 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );762 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), list< Expression * >() ) ); 763 763 } // if 764 764 } // for -
src/ResolvExpr/AlternativeFinder.cc
r579263a r2a7b3ca 604 604 // ) 605 605 SymTab::Indexer decls( indexer ); 606 //PRINT(607 //std::cerr << "============= original indexer" << std::endl;608 //indexer.print( std::cerr );609 //std::cerr << "============= new indexer" << std::endl;610 //decls.print( std::cerr );611 //)606 PRINT( 607 std::cerr << "============= original indexer" << std::endl; 608 indexer.print( std::cerr ); 609 std::cerr << "============= new indexer" << std::endl; 610 decls.print( std::cerr ); 611 ) 612 612 addToIndexer( have, decls ); 613 613 AssertionSet newNeed; … … 1182 1182 } 1183 1183 1184 void AlternativeFinder::visit( UntypedInitExpr *initExpr ) {1185 AlternativeFinder finder( indexer, env );1186 finder.findWithAdjustment( initExpr->get_expr() );1187 // handle each option like a cast -- should probably push this info into AltFinder as a kind of expression, both to keep common code close and to have less 'reach-in', but more 'push-in'1188 AltList candidates;1189 std::cerr << "untyped init expr: " << initExpr << std::endl;1190 // O(N^2) checks of d-types with e-types1191 for ( Alternative & alt : finder.get_alternatives() ) {1192 for ( InitAlternative & initAlt : initExpr->get_initAlts() ) {1193 AssertionSet needAssertions, haveAssertions;1194 OpenVarSet openVars;1195 std::cerr << " " << initAlt.type << " " << initAlt.designation << std::endl;1196 // It's possible that a cast can throw away some values in a multiply-valued expression. (An example is a1197 // cast-to-void, which casts from one value to zero.) Figure out the prefix of the subexpression results1198 // that are cast directly. The candidate is invalid if it has fewer results than there are types to cast1199 // to.1200 int discardedValues = alt.expr->get_result()->size() - initAlt.type->size();1201 if ( discardedValues < 0 ) continue;1202 // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not1203 // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3]))1204 // unification run for side-effects1205 unify( initAlt.type, alt.expr->get_result(), alt.env, needAssertions, haveAssertions, openVars, indexer );1206 1207 Cost thisCost = castCost( alt.expr->get_result(), initAlt.type, indexer, alt.env );1208 if ( thisCost != Cost::infinity ) {1209 // count one safe conversion for each value that is thrown away1210 thisCost += Cost( 0, 0, discardedValues );1211 candidates.push_back( Alternative( new InitExpr( alt.expr->clone(), initAlt.type->clone(), initAlt.designation->clone() ), alt.env, alt.cost, thisCost ) );1212 }1213 }1214 }1215 1216 // findMinCost selects the alternatives with the lowest "cost" members, but has the side effect of copying the1217 // cvtCost member to the cost member (since the old cost is now irrelevant). Thus, calling findMinCost twice1218 // selects first based on argument cost, then on conversion cost.1219 AltList minArgCost;1220 findMinCost( candidates.begin(), candidates.end(), std::back_inserter( minArgCost ) );1221 findMinCost( minArgCost.begin(), minArgCost.end(), std::back_inserter( alternatives ) );1222 }1223 1184 } // namespace ResolvExpr 1224 1185 -
src/ResolvExpr/AlternativeFinder.h
r579263a r2a7b3ca 73 73 virtual void visit( UniqueExpr *unqExpr ); 74 74 virtual void visit( StmtExpr *stmtExpr ); 75 virtual void visit( UntypedInitExpr *initExpr );76 75 /// Runs a new alternative finder on each element in [begin, end) 77 76 /// and writes each alternative finder to out. -
src/ResolvExpr/Resolver.cc
r579263a r2a7b3ca 14 14 // 15 15 16 #include <iostream>17 16 #include "Resolver.h" 17 #include "AlternativeFinder.h" 18 18 #include "Alternative.h" 19 #include "AlternativeFinder.h"20 #include "CurrentObject.h"21 19 #include "RenameVars.h" 22 #include "Resolver.h"23 20 #include "ResolveTypeof.h" 24 21 #include "typeops.h" 25 22 #include "SynTree/Statement.h" 23 #include "SynTree/Type.h" 26 24 #include "SynTree/Expression.h" 27 25 #include "SynTree/Initializer.h" 28 #include "SynTree/Statement.h" 29 #include "SynTree/Type.h" 30 26 #include "SymTab/Indexer.h" 31 27 #include "SymTab/Autogen.h" 32 #include "SymTab/Indexer.h"33 34 28 #include "Common/utility.h" 35 36 29 #include "InitTweak/InitTweak.h" 37 30 31 #include <iostream> 38 32 using namespace std; 39 33 … … 45 39 if ( const Resolver * res = dynamic_cast< const Resolver * >( &other ) ) { 46 40 functionReturn = res->functionReturn; 47 currentObject = res->currentObject;41 initContext = res->initContext; 48 42 inEnumDecl = res->inEnumDecl; 49 43 } … … 85 79 86 80 Type * functionReturn = nullptr; 87 CurrentObject currentObject = nullptr;81 Type *initContext = nullptr; 88 82 bool inEnumDecl = false; 89 83 }; … … 192 186 // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting 193 187 // the RHS. 194 ValueGuard<CurrentObject> temp( currentObject );195 currentObject = CurrentObject( objectDecl->get_type() );196 if ( inEnumDecl && dynamic_cast< EnumInstType * >( objectDecl->get_type()) ) {188 Type *temp = initContext; 189 initContext = new_type; 190 if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) { 197 191 // enumerator initializers should not use the enum type to initialize, since 198 192 // the enum type is still incomplete at this point. Use signed int instead. 199 currentObject = CurrentObject( new BasicType( Type::Qualifiers(), BasicType::SignedInt ));193 initContext = new BasicType( Type::Qualifiers(), BasicType::SignedInt ); 200 194 } 201 195 Parent::visit( objectDecl ); 202 if ( inEnumDecl && dynamic_cast< EnumInstType * >( objectDecl->get_type()) ) {196 if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) { 203 197 // delete newly created signed int type 204 // delete currentObject.getType(); 205 } 198 delete initContext; 199 } 200 initContext = temp; 206 201 } 207 202 … … 320 315 321 316 void Resolver::visit( SwitchStmt *switchStmt ) { 322 ValueGuard< CurrentObject > oldCurrentObject( currentObject );317 ValueGuard< Type * > oldInitContext( initContext ); 323 318 Expression *newExpr; 324 319 newExpr = findIntegralExpression( switchStmt->get_condition(), *this ); … … 326 321 switchStmt->set_condition( newExpr ); 327 322 328 currentObject = CurrentObject( newExpr->get_result());323 initContext = newExpr->get_result(); 329 324 Parent::visit( switchStmt ); 330 325 } … … 332 327 void Resolver::visit( CaseStmt *caseStmt ) { 333 328 if ( caseStmt->get_condition() ) { 334 std::list< InitAlternative > initAlts = currentObject.getOptions(); 335 assertf( initAlts.size() == 1, "SwitchStmt did not correctly resolve an integral expression." ); 336 CastExpr * castExpr = new CastExpr( caseStmt->get_condition(), initAlts.front().type->clone() ); 329 assert( initContext ); 330 CastExpr * castExpr = new CastExpr( caseStmt->get_condition(), initContext->clone() ); 337 331 Expression * newExpr = findSingleExpression( castExpr, *this ); 338 332 castExpr = safe_dynamic_cast< CastExpr * >( newExpr ); … … 375 369 } 376 370 377 template< typename Aggr >378 void lookupDesignation( Aggr * aggr, const std::list< Expression > & designators ) {379 380 }381 382 371 void Resolver::visit( SingleInit *singleInit ) { 383 UntypedInitExpr * untyped = new UntypedInitExpr( singleInit->get_value(), currentObject.getOptions() ); 384 Expression * newExpr = findSingleExpression( untyped, *this ); 385 InitExpr * initExpr = safe_dynamic_cast< InitExpr * >( newExpr ); 386 singleInit->set_value( new CastExpr( initExpr->get_expr()->clone(), initExpr->get_result()->clone() ) ); 387 currentObject.setNext( initExpr->get_designation() ); 388 currentObject.increment(); 389 delete initExpr; 390 391 // // check if initializing type is char[] 392 // if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 393 // if ( isCharType( at->get_base() ) ) { 394 // // check if the resolved type is char * 395 // if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 396 // if ( isCharType( pt->get_base() ) ) { 397 // // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello"; 398 // CastExpr *ce = dynamic_cast< CastExpr * >( newExpr ); 399 // singleInit->set_value( ce->get_arg() ); 400 // ce->set_arg( NULL ); 401 // delete ce; 402 // } 403 // } 404 // } 405 // } 406 } 407 408 // template< typename AggrInst > 409 // TypeSubstitution makeGenericSubstitution( AggrInst * inst ) { 410 // assert( inst ); 411 // assert( inst->get_baseParameters() ); 412 // std::list< TypeDecl * > baseParams = *inst->get_baseParameters(); 413 // std::list< Expression * > typeSubs = inst->get_parameters(); 414 // TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() ); 415 // return subs; 416 // } 417 418 // ReferenceToType * isStructOrUnion( Type * type ) { 419 // if ( StructInstType * sit = dynamic_cast< StructInstType * >( type ) ) { 420 // return sit; 421 // } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( type ) ) { 422 // return uit; 423 // } 424 // return nullptr; 425 // } 426 427 // void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd, TypeSubstitution sub ) { 428 // ObjectDecl * obj = dynamic_cast< ObjectDecl * >( dcl ); 429 // assert( obj ); 430 // // need to substitute for generic types, so that casts are to concrete types 431 // currentObject = obj->clone(); // xxx - delete this 432 // sub.apply( currentObject ); 433 434 // try { 435 // if ( init == initEnd ) return; // stop when there are no more initializers 436 // (*init)->accept( *this ); 437 // ++init; // made it past an initializer 438 // } catch( SemanticError & ) { 439 // // need to delve deeper, if you can 440 // if ( ReferenceToType * type = isStructOrUnion( currentObject->get_type() ) ) { 441 // resolveAggrInit( type, init, initEnd ); 442 // } else { 443 // // member is not an aggregate type, so can't go any deeper 444 445 // // might need to rethink what is being thrown 446 // throw; 447 // } // if 448 // } 449 // } 450 451 // void Resolver::resolveAggrInit( ReferenceToType * inst, InitIterator & init, InitIterator & initEnd ) { 452 // if ( StructInstType * sit = dynamic_cast< StructInstType * >( inst ) ) { 453 // TypeSubstitution sub = makeGenericSubstitution( sit ); 454 // StructDecl * st = sit->get_baseStruct(); 455 // if(st->get_members().empty()) return; 456 // // want to resolve each initializer to the members of the struct, 457 // // but if there are more initializers than members we should stop 458 // list< Declaration * >::iterator it = st->get_members().begin(); 459 // for ( ; it != st->get_members().end(); ++it) { 460 // resolveSingleAggrInit( *it, init, initEnd, sub ); 461 // } 462 // } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) { 463 // TypeSubstitution sub = makeGenericSubstitution( uit ); 464 // UnionDecl * un = uit->get_baseUnion(); 465 // if(un->get_members().empty()) return; 466 // // only resolve to the first member of a union 467 // resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub ); 468 // } // if 469 // } 372 if ( singleInit->get_value() ) { 373 // // find all the d's 374 // std::list<Expression *> &designators = singleInit->get_designators(); 375 // std::list<Type *> types1{ initContext }, types2; 376 // for ( Expression * expr: designators ) { 377 // cerr << expr << endl; 378 // if ( NameExpr * nexpr = dynamic_cast<NameExpr *>( expr ) ) { 379 // for ( Type * type: types1 ) { 380 // cerr << type << endl; 381 // ReferenceToType * fred = dynamic_cast<ReferenceToType *>(type); 382 // std::list<Declaration *> members; 383 // if ( fred ) { 384 // fred->lookup( nexpr->get_name(), members ); // concatenate identical field name 385 // for ( Declaration * mem: members ) { 386 // if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>(mem) ) { 387 // types2.push_back( dwt->get_type() ); 388 // } // if 389 // } // for 390 // } // if 391 // } // for 392 // types1 = types2; 393 // types2.clear(); 394 // } // if 395 // } // for 396 // // for ( Type * type: types1 ) { 397 // // cerr << type << endl; 398 // // } // for 399 400 // // O(N^2) checks of d-types with f-types 401 // // find the minimum cost 402 CastExpr *castExpr = new CastExpr( singleInit->get_value(), initContext->clone() ); 403 Expression *newExpr = findSingleExpression( castExpr, *this ); 404 delete castExpr; 405 singleInit->set_value( newExpr ); 406 407 // check if initializing type is char[] 408 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 409 if ( isCharType( at->get_base() ) ) { 410 // check if the resolved type is char * 411 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 412 if ( isCharType( pt->get_base() ) ) { 413 // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello"; 414 CastExpr *ce = dynamic_cast< CastExpr * >( newExpr ); 415 singleInit->set_value( ce->get_arg() ); 416 ce->set_arg( NULL ); 417 delete ce; 418 } 419 } 420 } 421 } 422 } // if 423 } 424 425 template< typename AggrInst > 426 TypeSubstitution makeGenericSubstitutuion( AggrInst * inst ) { 427 assert( inst ); 428 assert( inst->get_baseParameters() ); 429 std::list< TypeDecl * > baseParams = *inst->get_baseParameters(); 430 std::list< Expression * > typeSubs = inst->get_parameters(); 431 TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() ); 432 return subs; 433 } 434 435 ReferenceToType * isStructOrUnion( Type * type ) { 436 if ( StructInstType * sit = dynamic_cast< StructInstType * >( type ) ) { 437 return sit; 438 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( type ) ) { 439 return uit; 440 } 441 return nullptr; 442 } 443 444 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd, TypeSubstitution sub ) { 445 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl ); 446 assert( dt ); 447 // need to substitute for generic types, so that casts are to concrete types 448 initContext = dt->get_type()->clone(); 449 sub.apply( initContext ); 450 451 try { 452 if ( init == initEnd ) return; // stop when there are no more initializers 453 (*init)->accept( *this ); 454 ++init; // made it past an initializer 455 } catch( SemanticError & ) { 456 // need to delve deeper, if you can 457 if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 458 resolveAggrInit( type, init, initEnd ); 459 } else { 460 // member is not an aggregate type, so can't go any deeper 461 462 // might need to rethink what is being thrown 463 throw; 464 } // if 465 } 466 } 467 468 void Resolver::resolveAggrInit( ReferenceToType * inst, InitIterator & init, InitIterator & initEnd ) { 469 if ( StructInstType * sit = dynamic_cast< StructInstType * >( inst ) ) { 470 TypeSubstitution sub = makeGenericSubstitutuion( sit ); 471 StructDecl * st = sit->get_baseStruct(); 472 if(st->get_members().empty()) return; 473 // want to resolve each initializer to the members of the struct, 474 // but if there are more initializers than members we should stop 475 list< Declaration * >::iterator it = st->get_members().begin(); 476 for ( ; it != st->get_members().end(); ++it) { 477 resolveSingleAggrInit( *it, init, initEnd, sub ); 478 } 479 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) { 480 TypeSubstitution sub = makeGenericSubstitutuion( uit ); 481 UnionDecl * un = uit->get_baseUnion(); 482 if(un->get_members().empty()) return; 483 // only resolve to the first member of a union 484 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub ); 485 } // if 486 } 470 487 471 488 void Resolver::visit( ListInit * listInit ) { 472 currentObject.enterListInit(); 473 // xxx - fix this so that the list isn't copied, iterator should be used to change current element 474 std::list<Designation *> newDesignations; 475 for ( auto p : group_iterate(listInit->get_designations(), listInit->get_initializers()) ) { 476 Designation * des = std::get<0>(p); 477 Initializer * init = std::get<1>(p); 478 newDesignations.push_back( currentObject.findNext( des ) ); 479 init->accept( *this ); 480 } 481 listInit->get_designations() = newDesignations; // xxx - memory management 482 currentObject.exitListInit(); 483 484 // } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 485 // Type * base = tt->get_baseType()->get_base(); 486 // if ( base ) { 487 // // know the implementation type, so try using that as the initContext 488 // ObjectDecl tmpObj( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, base->clone(), nullptr ); 489 // currentObject = &tmpObj; 490 // visit( listInit ); 491 // } else { 492 // // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context 493 // Parent::visit( listInit ); 494 // } 495 // } else { 489 InitIterator iter = listInit->begin(); 490 InitIterator end = listInit->end(); 491 492 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 493 // resolve each member to the base type of the array 494 for ( ; iter != end; ++iter ) { 495 initContext = at->get_base(); 496 (*iter)->accept( *this ); 497 } // for 498 } else if ( TupleType * tt = dynamic_cast< TupleType * > ( initContext ) ) { 499 for ( Type * t : *tt ) { 500 if ( iter == end ) break; 501 initContext = t; 502 (*iter++)->accept( *this ); 503 } 504 } else if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 505 resolveAggrInit( type, iter, end ); 506 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 507 Type * base = tt->get_baseType()->get_base(); 508 if ( base ) { 509 // know the implementation type, so try using that as the initContext 510 initContext = base; 511 visit( listInit ); 512 } else { 513 // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context 514 Parent::visit( listInit ); 515 } 516 } else { 517 assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) 518 || dynamic_cast< ZeroType * >( initContext ) || dynamic_cast< OneType * >( initContext ) || dynamic_cast < EnumInstType * > ( initContext ) ); 519 // basic types are handled here 520 Parent::visit( listInit ); 521 } 522 523 #if 0 524 if ( ArrayType *at = dynamic_cast<ArrayType*>(initContext) ) { 525 std::list<Initializer *>::iterator iter( listInit->begin_initializers() ); 526 for ( ; iter != listInit->end_initializers(); ++iter ) { 527 initContext = at->get_base(); 528 (*iter)->accept( *this ); 529 } // for 530 } else if ( StructInstType *st = dynamic_cast<StructInstType*>(initContext) ) { 531 StructDecl *baseStruct = st->get_baseStruct(); 532 std::list<Declaration *>::iterator iter1( baseStruct->get_members().begin() ); 533 std::list<Initializer *>::iterator iter2( listInit->begin_initializers() ); 534 for ( ; iter1 != baseStruct->get_members().end() && iter2 != listInit->end_initializers(); ++iter2 ) { 535 if ( (*iter2)->get_designators().empty() ) { 536 DeclarationWithType *dt = dynamic_cast<DeclarationWithType *>( *iter1 ); 537 initContext = dt->get_type(); 538 (*iter2)->accept( *this ); 539 ++iter1; 540 } else { 541 StructDecl *st = baseStruct; 542 iter1 = st->get_members().begin(); 543 std::list<Expression *>::iterator iter3( (*iter2)->get_designators().begin() ); 544 for ( ; iter3 != (*iter2)->get_designators().end(); ++iter3 ) { 545 NameExpr *key = dynamic_cast<NameExpr *>( *iter3 ); 546 assert( key ); 547 for ( ; iter1 != st->get_members().end(); ++iter1 ) { 548 if ( key->get_name() == (*iter1)->get_name() ) { 549 (*iter1)->print( cout ); 550 cout << key->get_name() << endl; 551 ObjectDecl *fred = dynamic_cast<ObjectDecl *>( *iter1 ); 552 assert( fred ); 553 StructInstType *mary = dynamic_cast<StructInstType*>( fred->get_type() ); 554 assert( mary ); 555 st = mary->get_baseStruct(); 556 iter1 = st->get_members().begin(); 557 break; 558 } // if 559 } // for 560 } // for 561 ObjectDecl *fred = dynamic_cast<ObjectDecl *>( *iter1 ); 562 assert( fred ); 563 initContext = fred->get_type(); 564 (*listInit->begin_initializers())->accept( *this ); 565 } // if 566 } // for 567 } else if ( UnionInstType *st = dynamic_cast<UnionInstType*>(initContext) ) { 568 DeclarationWithType *dt = dynamic_cast<DeclarationWithType *>( *st->get_baseUnion()->get_members().begin() ); 569 initContext = dt->get_type(); 570 (*listInit->begin_initializers())->accept( *this ); 571 } // if 572 #endif 496 573 } 497 574 -
src/ResolvExpr/module.mk
r579263a r2a7b3ca 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## module.mk -- 8 ## module.mk -- 9 9 ## 10 10 ## Author : Richard C. Bilson … … 31 31 ResolvExpr/PolyCost.cc \ 32 32 ResolvExpr/Occurs.cc \ 33 ResolvExpr/TypeEnvironment.cc \ 34 ResolvExpr/CurrentObject.cc 33 ResolvExpr/TypeEnvironment.cc -
src/SymTab/Autogen.h
r579263a r2a7b3ca 25 25 26 26 namespace SymTab { 27 /// Generates assignment operators, constructors, and destructor for aggregate types as required28 void autogenerateRoutines( std::list< Declaration * > &translationUnit );27 /// Generates assignment operators, constructors, and destructor for aggregate types as required 28 void autogenerateRoutines( std::list< Declaration * > &translationUnit ); 29 29 30 /// returns true if obj's name is the empty string and it has a bitfield width31 bool isUnnamedBitfield( ObjectDecl * obj );30 /// returns true if obj's name is the empty string and it has a bitfield width 31 bool isUnnamedBitfield( ObjectDecl * obj ); 32 32 33 /// size_t type - set when size_t typedef is seen. Useful in a few places,34 /// such as in determining array dimension type35 extern Type * SizeType;33 /// size_t type - set when size_t typedef is seen. Useful in a few places, 34 /// such as in determining array dimension type 35 extern Type * SizeType; 36 36 37 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.38 template< typename OutputIterator >37 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. 38 template< typename OutputIterator > 39 39 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true ); 40 40 41 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.42 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one43 template< typename OutputIterator >41 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types. 42 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one 43 template< typename OutputIterator > 44 44 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) { 45 45 // want to be able to generate assignment, ctor, and dtor generically, … … 50 50 dstParam = new AddressExpr( dstParam ); 51 51 if ( addCast ) { 52 // cast to T* with qualifiers removed, so that qualified objects can be constructed 53 // and destructed with the same functions as non-qualified objects. 54 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument 55 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever 56 // remove lvalue as a qualifier, this can change to 57 // type->get_qualifiers() = Type::Qualifiers(); 58 assert( type ); 59 Type * castType = type->clone(); 60 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 61 castType->set_lvalue( true ); // xxx - might not need this 62 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); 52 // cast to T* with qualifiers removed, so that qualified objects can be constructed 53 // and destructed with the same functions as non-qualified objects. 54 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument 55 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever 56 // remove lvalue as a qualifier, this can change to 57 // type->get_qualifiers() = Type::Qualifiers(); 58 assert( type ); 59 Type * castType = type->clone(); 60 // castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false); 61 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 62 castType->set_lvalue( true ); // xxx - might not need this 63 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); 63 64 } 64 65 fExpr->get_args().push_back( dstParam ); … … 74 75 75 76 return listInit; 77 } 78 79 /// Store in out a loop which calls fname on each element of the array with srcParam and dstParam as arguments. 80 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 81 template< typename OutputIterator > 82 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) { 83 static UniqueName indexName( "_index" ); 84 85 // for a flexible array member nothing is done -- user must define own assignment 86 if ( ! array->get_dimension() ) return ; 87 88 Expression * begin, * end, * update, * cmp; 89 if ( forward ) { 90 // generate: for ( int i = 0; i < N; ++i ) 91 begin = new ConstantExpr( Constant::from_int( 0 ) ); 92 end = array->get_dimension()->clone(); 93 cmp = new NameExpr( "?<?" ); 94 update = new NameExpr( "++?" ); 95 } else { 96 // generate: for ( int i = N-1; i >= 0; --i ) 97 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 98 ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() ); 99 ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) ); 100 end = new ConstantExpr( Constant::from_int( 0 ) ); 101 cmp = new NameExpr( "?>=?" ); 102 update = new NameExpr( "--?" ); 76 103 } 77 104 78 /// Store in out a loop which calls fname on each element of the array with srcParam and dstParam as arguments. 79 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 80 template< typename OutputIterator > 81 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) { 82 static UniqueName indexName( "_index" ); 105 ObjectDecl *index = new ObjectDecl( indexName.newName(), Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 83 106 84 // for a flexible array member nothing is done -- user must define own assignment 85 if ( ! array->get_dimension() ) return ; 107 UntypedExpr *cond = new UntypedExpr( cmp ); 108 cond->get_args().push_back( new VariableExpr( index ) ); 109 cond->get_args().push_back( end ); 86 110 87 Expression * begin, * end, * update, * cmp; 88 if ( forward ) { 89 // generate: for ( int i = 0; i < N; ++i ) 90 begin = new ConstantExpr( Constant::from_int( 0 ) ); 91 end = array->get_dimension()->clone(); 92 cmp = new NameExpr( "?<?" ); 93 update = new NameExpr( "++?" ); 94 } else { 95 // generate: for ( int i = N-1; i >= 0; --i ) 96 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 97 ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() ); 98 ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) ); 99 end = new ConstantExpr( Constant::from_int( 0 ) ); 100 cmp = new NameExpr( "?>=?" ); 101 update = new NameExpr( "--?" ); 102 } 111 UntypedExpr *inc = new UntypedExpr( update ); 112 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 103 113 104 ObjectDecl *index = new ObjectDecl( indexName.newName(), Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin ) ); 114 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 115 dstIndex->get_args().push_back( dstParam ); 116 dstIndex->get_args().push_back( new VariableExpr( index ) ); 117 dstParam = dstIndex; 105 118 106 UntypedExpr *cond = new UntypedExpr( cmp );107 cond->get_args().push_back( new VariableExpr( index ) );108 cond->get_args().push_back( end);119 // srcParam must keep track of the array indices to build the 120 // source parameter and/or array list initializer 121 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() ); 109 122 110 UntypedExpr *inc = new UntypedExpr( update ); 111 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 123 // for stmt's body, eventually containing call 124 CompoundStmt * body = new CompoundStmt( noLabels ); 125 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward ); 112 126 113 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 114 dstIndex->get_args().push_back( dstParam ); 115 dstIndex->get_args().push_back( new VariableExpr( index ) ); 116 dstParam = dstIndex; 127 // block containing for stmt and index variable 128 std::list<Statement *> initList; 129 CompoundStmt * block = new CompoundStmt( noLabels ); 130 block->get_kids().push_back( new DeclStmt( noLabels, index ) ); 131 if ( listInit ) block->get_kids().push_back( listInit ); 132 block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 117 133 118 // srcParam must keep track of the array indices to build the 119 // source parameter and/or array list initializer 120 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() ); 134 *out++ = block; 135 } 121 136 122 // for stmt's body, eventually containing call 123 CompoundStmt * body = new CompoundStmt( noLabels ); 124 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward ); 137 template< typename OutputIterator > 138 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 139 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 140 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); 141 return 0; 142 } else { 143 return genScalarCall( srcParam, dstParam, fname, out, type, addCast ); 144 } 145 } 125 146 126 // block containing for stmt and index variable 127 std::list<Statement *> initList; 128 CompoundStmt * block = new CompoundStmt( noLabels ); 129 block->get_kids().push_back( new DeclStmt( noLabels, index ) ); 130 if ( listInit ) block->get_kids().push_back( listInit ); 131 block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 147 /// inserts into out a generated call expression to function fname with arguments dstParam 148 /// and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. decl is the 149 /// object being constructed. The function wraps constructor and destructor calls in an 150 /// ImplicitCtorDtorStmt node. 151 template< typename OutputIterator > 152 void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) { 153 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl ); 154 assert( obj ); 155 // unnamed bit fields are not copied as they cannot be accessed 156 if ( isUnnamedBitfield( obj ) ) return; 132 157 133 *out++ = block; 158 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ); 159 std::list< Statement * > stmts; 160 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward ); 161 162 // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call 163 assert( stmts.size() <= 1 ); 164 if ( stmts.size() == 1 ) { 165 Statement * callStmt = stmts.front(); 166 if ( addCast ) { 167 // implicitly generated ctor/dtor calls should be wrapped 168 // so that later passes are aware they were generated. 169 // xxx - don't mark as an implicit ctor/dtor if obj is a bitfield, 170 // because this causes the address to be taken at codegen, which is illegal in C. 171 callStmt = new ImplicitCtorDtorStmt( callStmt ); 172 } 173 *out++ = callStmt; 134 174 } 135 136 template< typename OutputIterator > 137 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 138 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 139 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); 140 return 0; 141 } else { 142 return genScalarCall( srcParam, dstParam, fname, out, type, addCast ); 143 } 144 } 145 146 /// inserts into out a generated call expression to function fname with arguments dstParam 147 /// and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. decl is the 148 /// object being constructed. The function wraps constructor and destructor calls in an 149 /// ImplicitCtorDtorStmt node. 150 template< typename OutputIterator > 151 void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) { 152 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl ); 153 assert( obj ); 154 // unnamed bit fields are not copied as they cannot be accessed 155 if ( isUnnamedBitfield( obj ) ) return; 156 157 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ); 158 std::list< Statement * > stmts; 159 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward ); 160 161 // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call 162 assert( stmts.size() <= 1 ); 163 if ( stmts.size() == 1 ) { 164 Statement * callStmt = stmts.front(); 165 if ( addCast ) { 166 // implicitly generated ctor/dtor calls should be wrapped 167 // so that later passes are aware they were generated. 168 // xxx - don't mark as an implicit ctor/dtor if obj is a bitfield, 169 // because this causes the address to be taken at codegen, which is illegal in C. 170 callStmt = new ImplicitCtorDtorStmt( callStmt ); 171 } 172 *out++ = callStmt; 173 } 174 } 175 } 175 176 } // namespace SymTab 176 177 #endif // AUTOGEN_H -
src/SynTree/Expression.cc
r579263a r2a7b3ca 92 92 93 93 Declaration *decl = get_var(); 94 // if ( decl != 0) decl->print(os, indent + 2); 94 95 if ( decl != 0) decl->printShort(os, indent + 2); 95 96 os << std::endl; … … 656 657 } 657 658 658 InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}659 InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}660 InitAlternative::~InitAlternative() {661 delete type;662 delete designation;663 }664 665 UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}666 UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}667 UntypedInitExpr::~UntypedInitExpr() {668 delete expr;669 }670 671 void UntypedInitExpr::print( std::ostream & os, int indent ) const {672 os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' );673 expr->print( os, indent+2 );674 if ( ! initAlts.empty() ) {675 for ( const InitAlternative & alt : initAlts ) {676 os << std::string( indent+2, ' ' ) << "InitAlternative: ";677 alt.type->print( os, indent+2 );678 alt.designation->print( os, indent+2 );679 }680 }681 }682 683 InitExpr::InitExpr( Expression * expr, Type * type, Designation * designation ) : expr( expr ), designation( designation ) {684 set_result( type );685 }686 InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}687 InitExpr::~InitExpr() {688 delete expr;689 delete designation;690 }691 692 void InitExpr::print( std::ostream & os, int indent ) const {693 os << "Init Expression" << std::endl << std::string( indent+2, ' ' );694 expr->print( os, indent+2 );695 os << std::string( indent+2, ' ' ) << "with designation: ";696 designation->print( os, indent+2 );697 }698 699 700 659 std::ostream & operator<<( std::ostream & out, const Expression * expr ) { 701 660 if ( expr ) { -
src/SynTree/Expression.h
r579263a r2a7b3ca 744 744 }; 745 745 746 struct InitAlternative {747 public:748 Type * type = nullptr;749 Designation * designation = nullptr;750 InitAlternative( Type * type, Designation * designation );751 InitAlternative( const InitAlternative & other );752 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it753 ~InitAlternative();754 };755 756 class UntypedInitExpr : public Expression {757 public:758 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );759 UntypedInitExpr( const UntypedInitExpr & other );760 ~UntypedInitExpr();761 762 Expression * get_expr() const { return expr; }763 UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }764 765 std::list<InitAlternative> & get_initAlts() { return initAlts; }766 767 virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }768 virtual void accept( Visitor & v ) { v.visit( this ); }769 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }770 virtual void print( std::ostream & os, int indent = 0 ) const;771 private:772 Expression * expr;773 std::list<InitAlternative> initAlts;774 };775 776 class InitExpr : public Expression {777 public:778 InitExpr( Expression * expr, Type * type, Designation * designation );779 InitExpr( const InitExpr & other );780 ~InitExpr();781 782 Expression * get_expr() const { return expr; }783 InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }784 785 Designation * get_designation() const { return designation; }786 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }787 788 virtual InitExpr * clone() const { return new InitExpr( * this ); }789 virtual void accept( Visitor & v ) { v.visit( this ); }790 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }791 virtual void print( std::ostream & os, int indent = 0 ) const;792 private:793 Expression * expr;794 Designation * designation;795 };796 797 798 746 std::ostream & operator<<( std::ostream & out, const Expression * expr ); 799 747 -
src/SynTree/Initializer.cc
r579263a r2a7b3ca 19 19 #include "Common/utility.h" 20 20 21 Designation::Designation( const std::list< Expression * > & designators ) : designators( designators ) {}22 Designation::Designation( const Designation & other ) : BaseSyntaxNode( other ) {23 // std::cerr << "cloning designation" << std::endl;24 cloneAll( other.designators, designators );25 // std::cerr << "finished cloning designation" << std::endl;26 }27 28 Designation::~Designation() {29 // std::cerr << "destroying designation" << std::endl;30 deleteAll( designators );31 // std::cerr << "finished destroying designation" << std::endl;32 }33 34 void Designation::print( std::ostream &os, int indent ) const {35 if ( ! designators.empty() ) {36 os << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;37 for ( std::list < Expression * >::const_iterator i = designators.begin(); i != designators.end(); i++ ) {38 os << std::string(indent + 4, ' ' );39 ( *i )->print(os, indent + 4 );40 }41 os << std::endl;42 } // if43 }44 45 21 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 46 22 Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) { 47 23 } 24 25 48 26 Initializer::~Initializer() {} 49 27 50 SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) { 28 std::string Initializer::designator_name( Expression *des ) { 29 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) 30 return n->get_name(); 31 else 32 throw 0; 33 } 34 35 // void Initializer::print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent ) {} 36 37 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { 51 38 } 52 39 53 40 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { 41 cloneAll(other.designators, designators ); 54 42 } 55 43 56 44 SingleInit::~SingleInit() { 57 45 delete value; 46 deleteAll(designators); 58 47 } 59 48 60 void SingleInit::print( std::ostream &os, int indent ) const{61 os << std:: string(indent, ' ' ) << "Simple Initializer: " << std::endl;49 void SingleInit::print( std::ostream &os, int indent ) { 50 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl; 62 51 os << std::string(indent+4, ' ' ); 63 52 value->print( os, indent+4 ); 53 54 if ( ! designators.empty() ) { 55 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl; 56 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) { 57 os << std::string(indent + 4, ' ' ); 58 ( *i )->print(os, indent + 4 ); 59 } 60 } // if 64 61 } 65 62 66 67 ListInit::ListInit( const std::list<Initializer*> &initializers, const std::list<Designation *> &designations, bool maybeConstructed ) 68 : Initializer( maybeConstructed ), initializers( initializers ), designations( designations ) { 63 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed ) 64 : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) { 69 65 } 70 66 71 67 ListInit::ListInit( const ListInit & other ) : Initializer( other ) { 72 68 cloneAll( other.initializers, initializers ); 73 cloneAll( other.designat ions, designations );69 cloneAll( other.designators, designators ); 74 70 } 71 75 72 76 73 ListInit::~ListInit() { 77 74 deleteAll( initializers ); 78 deleteAll( designat ions );75 deleteAll( designators ); 79 76 } 80 77 81 void ListInit::print( std::ostream &os, int indent ) const { 82 os << std::string(indent, ' ') << "Compound initializer: " << std::endl; 83 for ( Designation * d : designations ) { 84 d->print( os, indent + 2 ); 85 } 78 void ListInit::print( std::ostream &os, int indent ) { 79 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 80 if ( ! designators.empty() ) { 81 os << std::string(indent + 2, ' ' ) << "designated by: ["; 82 for ( std::list < Expression * >::iterator i = designators.begin(); 83 i != designators.end(); i++ ) { 84 ( *i )->print(os, indent + 4 ); 85 } // for 86 86 87 for ( const Initializer * init : initializers ) { 88 init->print( os, indent + 2 ); 89 os << std::endl; 90 } 87 os << std::string(indent + 2, ' ' ) << "]"; 88 } // if 89 90 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 91 (*i)->print( os, indent + 2 ); 91 92 } 92 93 … … 102 103 } 103 104 104 void ConstructorInit::print( std::ostream &os, int indent ) const{105 void ConstructorInit::print( std::ostream &os, int indent ) { 105 106 os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl; 106 107 if ( ctor ) { … … 123 124 } 124 125 125 std::ostream & operator<<( std::ostream & out, const Initializer * init ) { 126 if ( init ) { 127 init->print( out ); 128 } else { 129 out << "nullptr"; 130 } 131 return out; 132 } 133 134 std::ostream & operator<<( std::ostream & out, const Designation * des ) { 135 if ( des ) { 136 des->print( out ); 137 } else { 138 out << "nullptr"; 139 } 126 std::ostream & operator<<( std::ostream & out, Initializer * init ) { 127 init->print( out ); 140 128 return out; 141 129 } -
src/SynTree/Initializer.h
r579263a r2a7b3ca 25 25 #include "Visitor.h" 26 26 27 // Designation: list of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an object being initialized. 28 class Designation : public BaseSyntaxNode { 29 public: 30 Designation( const std::list< Expression * > & designators ); 31 Designation( const Designation & other ); 32 virtual ~Designation(); 33 34 std::list< Expression * > & get_designators() { return designators; } 35 36 virtual Designation * clone() const { return new Designation( *this ); }; 37 virtual void accept( Visitor &v ) { v.visit( this ); } 38 virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); } 39 virtual void print( std::ostream &os, int indent = 0 ) const; 40 private: 41 std::list< Expression * > designators; 42 }; 43 44 const std::list<Designation *> noDesignators; 27 const std::list<Expression*> noDesignators; 45 28 46 29 // Initializer: base class for object initializers (provide default values) 47 30 class Initializer : public BaseSyntaxNode { 48 31 public: 32 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 49 33 Initializer( bool maybeConstructed ); 50 34 Initializer( const Initializer & other ); 51 35 virtual ~Initializer(); 36 37 static std::string designator_name( Expression *designator ); 38 39 // void set_name( std::string newValue ) { name = newValue; } 40 // std::string get_name() const { return name; } 41 42 // void set_pos( int newValue ) { pos = newValue; } 43 // int get_pos() const { return pos; } 44 virtual void set_designators( std::list<Expression *> & ) { assert(false); } 45 virtual std::list<Expression *> &get_designators() { 46 assert(false); 47 std::list<Expression *> *ret = 0; return *ret; // never reached 48 } 52 49 53 50 bool get_maybeConstructed() { return maybeConstructed; } … … 56 53 virtual void accept( Visitor &v ) = 0; 57 54 virtual Initializer *acceptMutator( Mutator &m ) = 0; 58 virtual void print( std::ostream &os, int indent = 0 ) const= 0;55 virtual void print( std::ostream &os, int indent = 0 ) = 0; 59 56 private: 57 // std::string name; 58 // int pos; 60 59 bool maybeConstructed; 61 60 }; … … 64 63 class SingleInit : public Initializer { 65 64 public: 66 SingleInit( Expression *value, bool maybeConstructed = false );65 SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false ); 67 66 SingleInit( const SingleInit &other ); 68 67 virtual ~SingleInit(); … … 71 70 void set_value( Expression *newValue ) { value = newValue; } 72 71 72 std::list<Expression *> &get_designators() { return designators; } 73 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; } 74 73 75 virtual SingleInit *clone() const { return new SingleInit( *this); } 74 76 virtual void accept( Visitor &v ) { v.visit( this ); } 75 77 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 76 virtual void print( std::ostream &os, int indent = 0 ) const;78 virtual void print( std::ostream &os, int indent = 0 ); 77 79 private: 78 80 //Constant *value; 79 81 Expression *value; // has to be a compile-time constant 82 std::list< Expression * > designators; 80 83 }; 81 84 … … 85 88 public: 86 89 ListInit( const std::list<Initializer*> &initializers, 87 const std::list< Designation *> &designators = {}, bool maybeConstructed = false );90 const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false ); 88 91 ListInit( const ListInit & other ); 89 92 virtual ~ListInit(); 90 93 91 std::list<Designation *> & get_designations() { return designations; } 92 std::list<Initializer *> & get_initializers() { return initializers; } 94 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; } 95 std::list<Expression *> &get_designators() { return designators; } 96 void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; } 97 std::list<Initializer*> &get_initializers() { return initializers; } 93 98 94 99 typedef std::list<Initializer*>::iterator iterator; 95 typedef std::list<Initializer*>::const_iterator const_iterator;96 100 iterator begin() { return initializers.begin(); } 97 101 iterator end() { return initializers.end(); } 98 const_iterator begin() const { return initializers.begin(); }99 const_iterator end() const { return initializers.end(); }100 102 101 103 virtual ListInit *clone() const { return new ListInit( *this ); } 102 104 virtual void accept( Visitor &v ) { v.visit( this ); } 103 105 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 104 virtual void print( std::ostream &os, int indent = 0 ) const;106 virtual void print( std::ostream &os, int indent = 0 ); 105 107 private: 106 std::list<Initializer *> initializers; // order *is* important107 std::list< Designation *> designations; // order/length is consistent with initializers108 std::list<Initializer*> initializers; // order *is* important 109 std::list<Expression *> designators; 108 110 }; 109 111 … … 128 130 virtual void accept( Visitor &v ) { v.visit( this ); } 129 131 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 130 virtual void print( std::ostream &os, int indent = 0 ) const;132 virtual void print( std::ostream &os, int indent = 0 ); 131 133 132 134 private: … … 138 140 }; 139 141 140 std::ostream & operator<<( std::ostream & out, const Initializer * init ); 141 std::ostream & operator<<( std::ostream & out, const Designation * des ); 142 std::ostream & operator<<( std::ostream & out, Initializer * init ); 142 143 143 144 #endif // INITIALIZER_H -
src/SynTree/Mutator.cc
r579263a r2a7b3ca 433 433 } 434 434 435 Expression *Mutator::mutate( UntypedInitExpr * initExpr ) {436 initExpr->set_env( maybeMutate( initExpr->get_env(), *this ) );437 initExpr->set_result( maybeMutate( initExpr->get_result(), *this ) );438 initExpr->set_expr( maybeMutate( initExpr->get_expr(), *this ) );439 // not currently mutating initAlts, but this doesn't matter since this node is only used in the resolver.440 return initExpr;441 }442 443 Expression *Mutator::mutate( InitExpr * initExpr ) {444 initExpr->set_env( maybeMutate( initExpr->get_env(), *this ) );445 initExpr->set_result( maybeMutate( initExpr->get_result(), *this ) );446 initExpr->set_expr( maybeMutate( initExpr->get_expr(), *this ) );447 initExpr->set_designation( maybeMutate( initExpr->get_designation(), *this ) );448 return initExpr;449 }450 451 435 452 436 Type *Mutator::mutate( VoidType *voidType ) { … … 551 535 552 536 553 Designation *Mutator::mutate( Designation * designation ) {554 mutateAll( designation->get_designators(), *this );555 return designation;556 }557 558 537 Initializer *Mutator::mutate( SingleInit *singleInit ) { 559 538 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); … … 562 541 563 542 Initializer *Mutator::mutate( ListInit *listInit ) { 564 mutateAll( listInit->get_designat ions(), *this );543 mutateAll( listInit->get_designators(), *this ); 565 544 mutateAll( listInit->get_initializers(), *this ); 566 545 return listInit; -
src/SynTree/Mutator.h
r579263a r2a7b3ca 85 85 virtual Expression* mutate( StmtExpr * stmtExpr ); 86 86 virtual Expression* mutate( UniqueExpr * uniqueExpr ); 87 virtual Expression* mutate( UntypedInitExpr * initExpr );88 virtual Expression* mutate( InitExpr * initExpr );89 87 90 88 virtual Type* mutate( VoidType *basicType ); … … 105 103 virtual Type* mutate( OneType *oneType ); 106 104 107 virtual Designation* mutate( Designation *designation );108 105 virtual Initializer* mutate( SingleInit *singleInit ); 109 106 virtual Initializer* mutate( ListInit *listInit ); -
src/SynTree/SynTree.h
r579263a r2a7b3ca 93 93 class StmtExpr; 94 94 class UniqueExpr; 95 class UntypedInitExpr;96 class InitExpr;97 95 98 96 class Type; … … 115 113 class OneType; 116 114 117 class Designation;118 115 class Initializer; 119 116 class SingleInit; -
src/SynTree/Visitor.cc
r579263a r2a7b3ca 340 340 } 341 341 342 void Visitor::visit( UntypedInitExpr * initExpr ) {343 maybeAccept( initExpr->get_result(), *this );344 maybeAccept( initExpr->get_expr(), *this );345 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.346 }347 348 void Visitor::visit( InitExpr * initExpr ) {349 maybeAccept( initExpr->get_result(), *this );350 maybeAccept( initExpr->get_expr(), *this );351 maybeAccept( initExpr->get_designation(), *this );352 }353 354 342 355 343 void Visitor::visit( VoidType *voidType ) { … … 436 424 } 437 425 438 void Visitor::visit( Designation * designation ) {439 acceptAll( designation->get_designators(), *this );440 }441 426 442 427 void Visitor::visit( SingleInit *singleInit ) { … … 445 430 446 431 void Visitor::visit( ListInit *listInit ) { 447 acceptAll( listInit->get_designat ions(), *this );432 acceptAll( listInit->get_designators(), *this ); 448 433 acceptAll( listInit->get_initializers(), *this ); 449 434 } -
src/SynTree/Visitor.h
r579263a r2a7b3ca 88 88 virtual void visit( StmtExpr * stmtExpr ); 89 89 virtual void visit( UniqueExpr * uniqueExpr ); 90 virtual void visit( UntypedInitExpr * initExpr );91 virtual void visit( InitExpr * initExpr );92 90 93 91 virtual void visit( VoidType *basicType ); … … 108 106 virtual void visit( OneType *oneType ); 109 107 110 virtual void visit( Designation *designation );111 108 virtual void visit( SingleInit *singleInit ); 112 109 virtual void visit( ListInit *listInit ); -
src/Tuples/TupleExpansion.cc
r579263a r2a7b3ca 192 192 } 193 193 ObjectDecl * finished = new ObjectDecl( toString( "_unq", id, "_finished_" ), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::Bool ), 194 new SingleInit( new ConstantExpr( Constant::from_int( 0 ) ) ) );194 new SingleInit( new ConstantExpr( Constant::from_int( 0 ) ), noDesignators ) ); 195 195 addDeclaration( finished ); 196 196 // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N))
Note:
See TracChangeset
for help on using the changeset viewer.