Changeset b826e6b for src/CodeGen/CodeGenerator.cc
- Timestamp:
- Jul 19, 2017, 11:49:33 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9cc0472
- Parents:
- fea3faa (diff), a57cb58 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rfea3faa rb826e6b 14 14 // 15 15 16 #include <algorithm> 17 #include <iostream> 18 #include <cassert> 19 #include <list> 20 21 #include "Parser/ParseNode.h" 22 23 #include "SynTree/Declaration.h" 24 #include "SynTree/Expression.h" 25 #include "SynTree/Initializer.h" 26 #include "SynTree/Statement.h" 27 #include "SynTree/Type.h" 28 #include "SynTree/Attribute.h" 29 30 #include "Common/utility.h" 31 #include "Common/UnimplementedError.h" 16 #include <cassert> // for assert, assertf 17 #include <list> // for _List_iterator, list, list<>::it... 32 18 33 19 #include "CodeGenerator.h" 34 #include "OperatorTable.h" 35 #include "GenType.h" 36 37 #include "InitTweak/InitTweak.h" 20 #include "Common/SemanticError.h" // for SemanticError 21 #include "Common/UniqueName.h" // for UniqueName 22 #include "Common/utility.h" // for CodeLocation, toString 23 #include "GenType.h" // for genType 24 #include "InitTweak/InitTweak.h" // for getPointerBase 25 #include "OperatorTable.h" // for OperatorInfo, operatorLookup 26 #include "Parser/LinkageSpec.h" // for Spec, Intrinsic 27 #include "SynTree/Attribute.h" // for Attribute 28 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode 29 #include "SynTree/Constant.h" // for Constant 30 #include "SynTree/Declaration.h" // for DeclarationWithType, TypeDecl 31 #include "SynTree/Expression.h" // for Expression, UntypedExpr, Applica... 32 #include "SynTree/Initializer.h" // for Initializer, ListInit, Designation 33 #include "SynTree/Label.h" // for Label, operator<< 34 #include "SynTree/Statement.h" // for Statement, AsmStmt, BranchStmt 35 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Func... 38 36 39 37 using namespace std; … … 288 286 } 289 287 290 void CodeGenerator:: printDesignators( std::list< Expression * > & designators) {291 typedef std::list< Expression * > DesignatorList;288 void CodeGenerator::visit( Designation * designation ) { 289 std::list< Expression * > designators = designation->get_designators(); 292 290 if ( designators.size() == 0 ) return; 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 member291 for ( Expression * des : designators ) { 292 if ( dynamic_cast< NameExpr * >( des ) || dynamic_cast< VariableExpr * >( des ) ) { 293 // if expression is a NameExpr or VariableExpr, then initializing aggregate member 296 294 output << "."; 297 (*iter)->accept( *this );295 des->accept( *this ); 298 296 } else { 299 // if not a simple name, it has to be a constant expression, i.e. an array designator297 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt 300 298 output << "["; 301 (*iter)->accept( *this );299 des->accept( *this ); 302 300 output << "]"; 303 301 } // if … … 307 305 308 306 void CodeGenerator::visit( SingleInit * init ) { 309 printDesignators( init->get_designators() );310 307 init->get_value()->accept( *this ); 311 308 } 312 309 313 310 void CodeGenerator::visit( ListInit * init ) { 314 printDesignators( init->get_designators() ); 311 auto initBegin = init->begin(); 312 auto initEnd = init->end(); 313 auto desigBegin = init->get_designations().begin(); 314 auto desigEnd = init->get_designations().end(); 315 315 316 output << "{ "; 316 genCommaList( init->begin(), init->end() ); 317 for ( ; initBegin != initEnd && desigBegin != desigEnd; ) { 318 (*desigBegin)->accept( *this ); 319 (*initBegin)->accept( *this ); 320 ++initBegin, ++desigBegin; 321 if ( initBegin != initEnd ) { 322 output << ", "; 323 } 324 } 317 325 output << " }"; 326 assertf( initBegin == initEnd && desigBegin == desigEnd, "Initializers and designators not the same length. %s", toString( init ).c_str() ); 318 327 } 319 328 … … 716 725 717 726 void CodeGenerator::visit( TypeExpr * typeExpr ) { 718 assertf( ! genC, "TypeExpr should not reach code generation." ); 719 output<< genType( typeExpr->get_type(), "", pretty, genC ); 727 // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl; 728 // assertf( ! genC, "TypeExpr should not reach code generation." ); 729 if ( ! genC ) { 730 output<< genType( typeExpr->get_type(), "", pretty, genC ); 731 } 720 732 } 721 733
Note:
See TracChangeset
for help on using the changeset viewer.