Changeset d24d4e1 for src/SymTab
- Timestamp:
- Jun 23, 2017, 12:12:46 PM (7 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:
- 2a7b3ca
- Parents:
- ba915fb5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rba915fb5 rd24d4e1 106 106 107 107 /// Fix return types so that every function returns exactly one value 108 class ReturnTypeFixer { 109 public: 108 struct ReturnTypeFixer { 110 109 static void fix( std::list< Declaration * > &translationUnit ); 111 110 … … 115 114 116 115 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 117 class EnumAndPointerDecay { 118 public: 116 struct EnumAndPointerDecay { 119 117 void previsit( EnumDecl *aggregateDecl ); 120 118 void previsit( FunctionType *func ); … … 159 157 }; 160 158 161 class ReturnChecker : public WithScopes { 162 public: 159 struct ReturnChecker : public WithGuards { 163 160 /// Checks that return statements return nothing if their return type is void 164 161 /// and return something if the return type is non-void. 165 162 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 166 private: 163 167 164 void previsit( FunctionDecl * functionDecl ); 168 165 void previsit( ReturnStmt * returnStmt ); … … 205 202 }; 206 203 207 class VerifyCtorDtorAssign { 208 public: 204 struct VerifyCtorDtorAssign { 209 205 /// ensure that constructors, destructors, and assignment have at least one 210 206 /// parameter, the first of which must be a pointer, and that ctor/dtors have no … … 216 212 217 213 /// ensure that generic types have the correct number of type arguments 218 class ValidateGenericParameters { 219 public: 214 struct ValidateGenericParameters { 220 215 void previsit( StructInstType * inst ); 221 216 void previsit( UnionInstType * inst ); 222 217 }; 223 218 224 class ArrayLength { 225 public: 219 struct ArrayLength { 226 220 /// for array types without an explicit length, compute the length and store it so that it 227 221 /// is known to the rest of the phases. For example, … … 236 230 }; 237 231 238 class CompoundLiteral final : public GenPoly::DeclMutator{232 struct CompoundLiteral final : public WithDeclsToAdd, public WithVisitorRef<CompoundLiteral> { 239 233 Type::StorageClasses storageClasses; 240 234 241 using GenPoly::DeclMutator::mutate; 242 DeclarationWithType * mutate( ObjectDecl *objectDecl ) final; 243 Expression *mutate( CompoundLiteralExpr *compLitExpr ) final; 235 void premutate( ObjectDecl *objectDecl ); 236 Expression * postmutate( CompoundLiteralExpr *compLitExpr ); 244 237 }; 245 238 … … 248 241 LinkReferenceToTypes lrt( doDebug, 0 ); 249 242 ForallPointerDecay fpd( 0 ); 250 CompoundLiteralcompoundliteral;243 PassVisitor<CompoundLiteral> compoundliteral; 251 244 PassVisitor<ValidateGenericParameters> genericParams; 252 245 … … 263 256 Concurrency::implementThreadStarter( translationUnit ); 264 257 ReturnChecker::checkFunctionReturns( translationUnit ); 265 compoundliteral.mutateDeclarationList( translationUnit);258 mutateAll( translationUnit, compoundliteral ); 266 259 acceptAll( translationUnit, fpd ); 267 260 ArrayLength::computeLength( translationUnit ); … … 883 876 } 884 877 885 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {878 void CompoundLiteral::premutate( ObjectDecl *objectDecl ) { 886 879 storageClasses = objectDecl->get_storageClasses(); 887 DeclarationWithType * temp = Mutator::mutate( objectDecl ); 888 return temp; 889 } 890 891 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) { 880 } 881 882 Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) { 892 883 // transform [storage_class] ... (struct S){ 3, ... }; 893 884 // into [storage_class] struct S temp = { 3, ... }; 894 885 static UniqueName indexName( "_compLit" ); 895 886 896 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, 0, compLitExpr->get_result(), compLitExpr->get_initializer() );897 compLitExpr->set_result( 0);898 compLitExpr->set_initializer( 0);887 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() ); 888 compLitExpr->set_result( nullptr ); 889 compLitExpr->set_initializer( nullptr ); 899 890 delete compLitExpr; 900 DeclarationWithType * newtempvar = mutate( tempvar ); 901 addDeclaration( newtempvar ); // add modified temporary to current block 902 return new VariableExpr( newtempvar ); 891 declsToAddBefore.push_back( tempvar ); // add modified temporary to current block 892 return new VariableExpr( tempvar ); 903 893 } 904 894
Note: See TracChangeset
for help on using the changeset viewer.