Changeset 1048b31 for src/SymTab/Validate.cc
- Timestamp:
- May 2, 2016, 3:28:16 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1b7ea43
- Parents:
- 1f6e009 (diff), e945826 (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/SymTab/Validate.cc
r1f6e009 r1048b31 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:31:39201613 // Update Count : 2 2612 // Last Modified On : Wed Apr 13 16:39:30 2016 13 // Update Count : 251 14 14 // 15 15 … … 40 40 #include <list> 41 41 #include <iterator> 42 #include "Common/utility.h" 43 #include "Common/UniqueName.h" 42 44 #include "Validate.h" 43 45 #include "SynTree/Visitor.h" 44 46 #include "SynTree/Mutator.h" 45 47 #include "SynTree/Type.h" 48 #include "SynTree/Expression.h" 46 49 #include "SynTree/Statement.h" 47 50 #include "SynTree/TypeSubstitution.h" … … 49 52 #include "FixFunction.h" 50 53 // #include "ImplementationType.h" 51 #include "Common/utility.h" 52 #include "Common/UniqueName.h" 54 #include "GenPoly/DeclMutator.h" 53 55 #include "AddVisit.h" 54 56 #include "MakeLibCfa.h" … … 70 72 71 73 virtual void visit( CompoundStmt *compoundStmt ); 72 virtual void visit( IfStmt *ifStmt );73 virtual void visit( WhileStmt *whileStmt );74 virtual void visit( ForStmt *forStmt );75 74 virtual void visit( SwitchStmt *switchStmt ); 76 75 virtual void visit( ChooseStmt *chooseStmt ); 77 virtual void visit( CaseStmt *caseStmt ); 78 virtual void visit( CatchStmt *catchStmt ); 76 // virtual void visit( CaseStmt *caseStmt ); 79 77 private: 80 78 HoistStruct(); … … 144 142 145 143 virtual void visit( CompoundStmt *compoundStmt ); 146 virtual void visit( IfStmt *ifStmt );147 virtual void visit( WhileStmt *whileStmt );148 virtual void visit( ForStmt *forStmt );149 144 virtual void visit( SwitchStmt *switchStmt ); 150 145 virtual void visit( ChooseStmt *chooseStmt ); 151 virtual void visit( CaseStmt *caseStmt ); 152 virtual void visit( CatchStmt *catchStmt ); 146 // virtual void visit( CaseStmt *caseStmt ); 153 147 154 148 AutogenerateRoutines() : functionNesting( 0 ) {} … … 166 160 /// and return something if the return type is non-void. 167 161 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 168 169 162 private: 170 163 virtual void visit( FunctionDecl * functionDecl ); … … 197 190 AggDecl *handleAggregate( AggDecl * aggDecl ); 198 191 192 template<typename AggDecl> 193 void addImplicitTypedef( AggDecl * aggDecl ); 194 199 195 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 200 196 TypedefMap typedefNames; … … 202 198 }; 203 199 200 class CompoundLiteral : public GenPoly::DeclMutator { 201 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass; 202 203 virtual DeclarationWithType * mutate( ObjectDecl *objectDecl ); 204 virtual Expression *mutate( CompoundLiteralExpr *compLitExpr ); 205 }; 206 204 207 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 205 208 Pass1 pass1; 206 209 Pass2 pass2( doDebug, 0 ); 207 210 Pass3 pass3( 0 ); 211 CompoundLiteral compoundliteral; 212 208 213 EliminateTypedef::eliminateTypedef( translationUnit ); 209 214 HoistStruct::hoistStruct( translationUnit ); … … 211 216 acceptAll( translationUnit, pass2 ); 212 217 ReturnChecker::checkFunctionReturns( translationUnit ); 218 mutateAll( translationUnit, compoundliteral ); 213 219 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 214 220 acceptAll( translationUnit, pass3 ); … … 292 298 } 293 299 294 void HoistStruct::visit( IfStmt *ifStmt ) {295 addVisit( ifStmt, *this );296 }297 298 void HoistStruct::visit( WhileStmt *whileStmt ) {299 addVisit( whileStmt, *this );300 }301 302 void HoistStruct::visit( ForStmt *forStmt ) {303 addVisit( forStmt, *this );304 }305 306 300 void HoistStruct::visit( SwitchStmt *switchStmt ) { 307 301 addVisit( switchStmt, *this ); … … 312 306 } 313 307 314 void HoistStruct::visit( CaseStmt *caseStmt ) { 315 addVisit( caseStmt, *this ); 316 } 317 318 void HoistStruct::visit( CatchStmt *cathStmt ) { 319 addVisit( cathStmt, *this ); 320 } 308 // void HoistStruct::visit( CaseStmt *caseStmt ) { 309 // addVisit( caseStmt, *this ); 310 // } 321 311 322 312 void Pass1::visit( EnumDecl *enumDecl ) { … … 874 864 } 875 865 876 void AutogenerateRoutines::visit( IfStmt *ifStmt ) {877 visitStatement( ifStmt );878 }879 880 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {881 visitStatement( whileStmt );882 }883 884 void AutogenerateRoutines::visit( ForStmt *forStmt ) {885 visitStatement( forStmt );886 }887 888 866 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 889 867 visitStatement( switchStmt ); … … 894 872 } 895 873 896 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 897 visitStatement( caseStmt ); 898 } 899 900 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 901 visitStatement( cathStmt ); 902 } 874 // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 875 // visitStatement( caseStmt ); 876 // } 903 877 904 878 void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) { … … 947 921 } 948 922 rtt->get_parameters().clear(); 949 cloneAll(typeInst->get_parameters(), rtt->get_parameters()); 923 cloneAll( typeInst->get_parameters(), rtt->get_parameters() ); 924 mutateAll( rtt->get_parameters(), *this ); // recursively fix typedefs on parameters 950 925 } // if 951 926 delete typeInst; … … 1043 1018 } 1044 1019 1045 // there may be typedefs nested within aggregates 1046 // in order for everything to work properly, these 1047 // should be removed as well 1020 // there may be typedefs nested within aggregates in order for everything to work properly, these should be removed 1021 // as well 1048 1022 template<typename AggDecl> 1049 1023 AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) { … … 1059 1033 return aggDecl; 1060 1034 } 1061 1035 1036 template<typename AggDecl> 1037 void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) { 1038 if ( typedefNames.count( aggDecl->get_name() ) == 0 ) { 1039 Type *type; 1040 if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) { 1041 type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ); 1042 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) { 1043 type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ); 1044 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl ) ) { 1045 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 1046 } // if 1047 TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type ); 1048 typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 1049 } // if 1050 } 1062 1051 Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) { 1052 addImplicitTypedef( structDecl ); 1063 1053 Mutator::mutate( structDecl ); 1064 1054 return handleAggregate( structDecl ); … … 1066 1056 1067 1057 Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) { 1058 addImplicitTypedef( unionDecl ); 1068 1059 Mutator::mutate( unionDecl ); 1069 1060 return handleAggregate( unionDecl ); … … 1071 1062 1072 1063 Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) { 1064 addImplicitTypedef( enumDecl ); 1073 1065 Mutator::mutate( enumDecl ); 1074 1066 return handleAggregate( enumDecl ); 1075 1067 } 1076 1068 1077 1069 Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) { 1078 1070 Mutator::mutate( contextDecl ); 1079 1071 return handleAggregate( contextDecl ); 1080 1072 } 1081 1073 1074 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) { 1075 storageclass = objectDecl->get_storageClass(); 1076 DeclarationWithType * temp = Mutator::mutate( objectDecl ); 1077 storageclass = DeclarationNode::NoStorageClass; 1078 return temp; 1079 } 1080 1081 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) { 1082 // transform [storage_class] ... (struct S){ 3, ... }; 1083 // into [storage_class] struct S temp = { 3, ... }; 1084 static UniqueName indexName( "_compLit" ); 1085 1086 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() ); 1087 compLitExpr->set_type( 0 ); 1088 compLitExpr->set_initializer( 0 ); 1089 delete compLitExpr; 1090 DeclarationWithType * newtempvar = mutate( tempvar ); 1091 addDeclaration( newtempvar ); // add modified temporary to current block 1092 return new VariableExpr( newtempvar ); 1093 } 1082 1094 } // namespace SymTab 1083 1095
Note:
See TracChangeset
for help on using the changeset viewer.