Changeset 0db6fc0
- Timestamp:
- Jun 2, 2017, 6:30:18 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:
- 7985fa5
- Parents:
- f94ca7e
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ForExprMutator.cc
rf94ca7e r0db6fc0 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ForExprMutator.cc -- 7 // ForExprMutator.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 19 19 20 20 namespace ControlStruct { 21 Statement *ForExprMutator::mutate( ForStmt *forStmt ) { 22 // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99) 23 forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) ); 24 25 std::list<Statement *> &init = forStmt->get_initialization(); 21 Statement *ForExprMutator::postmutate( ForStmt *forStmt ) { 22 // hoist any initializer declarations to make them C89 (rather than C99) 23 std::list<Statement *> &init = forStmt->get_initialization(); 26 24 if ( init.size() == 0 ) { 27 25 return forStmt; … … 39 37 forStmt->set_initialization( std::list<Statement *>() ); 40 38 return block; 41 42 return forStmt;43 39 } 44 40 } // namespace ControlStruct -
src/ControlStruct/ForExprMutator.h
rf94ca7e r0db6fc0 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ForExprMutator.h -- 7 // ForExprMutator.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 21 21 22 22 namespace ControlStruct { 23 class ForExprMutator : public Mutator{23 class ForExprMutator { 24 24 public: 25 virtual Statement *mutate( ForStmt * );25 Statement *postmutate( ForStmt * ); 26 26 }; 27 27 } // namespace ControlStruct -
src/ControlStruct/Mutate.cc
rf94ca7e r0db6fc0 26 26 27 27 #include "Common/utility.h" 28 #include "Common/PassVisitor.h" 28 29 29 30 #include "SynTree/Visitor.h" … … 34 35 void mutate( std::list< Declaration * > translationUnit ) { 35 36 // hoist initialization out of for statements 36 ForExprMutatorformut;37 PassVisitor<ForExprMutator> formut; 37 38 38 39 // normalizes label definitions and generates multi-level exit labels -
src/InitTweak/GenInit.cc
rf94ca7e r0db6fc0 44 44 static void makeReturnTemp( std::list< Declaration * > &translationUnit ); 45 45 46 ReturnFixer();47 48 46 typedef GenPoly::PolyMutator Parent; 49 47 using Parent::mutate; … … 134 132 mutateAll( translationUnit, fixer ); 135 133 } 136 137 ReturnFixer::ReturnFixer() {}138 134 139 135 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) { -
src/SymTab/Validate.cc
rf94ca7e r0db6fc0 38 38 // definition occurs later in the input. 39 39 40 #include <algorithm> 41 #include <iterator> 40 42 #include <list> 41 #include <iterator> 43 44 #include "CodeGen/CodeGenerator.h" 45 46 #include "Common/PassVisitor.h" 42 47 #include "Common/ScopedMap.h" 48 #include "Common/UniqueName.h" 43 49 #include "Common/utility.h" 44 #include "Common/UniqueName.h" 50 45 51 #include "Concurrency/Keywords.h" 46 #include "Validate.h" 47 #include "SynTree/Visitor.h" 48 #include "SynTree/Mutator.h" 49 #include "SynTree/Type.h" 50 #include "SynTree/Expression.h" 51 #include "SynTree/Statement.h" 52 #include "SynTree/TypeSubstitution.h" 53 #include "Indexer.h" 52 53 #include "GenPoly/DeclMutator.h" 54 55 #include "InitTweak/InitTweak.h" 56 57 #include "AddVisit.h" 58 #include "Autogen.h" 54 59 #include "FixFunction.h" 55 60 // #include "ImplementationType.h" 56 #include "GenPoly/DeclMutator.h" 57 #include "AddVisit.h" 61 #include "Indexer.h" 58 62 #include "MakeLibCfa.h" 59 63 #include "TypeEquality.h" 60 #include "Autogen.h" 64 #include "Validate.h" 65 61 66 #include "ResolvExpr/typeops.h" 62 #include <algorithm> 63 #include "InitTweak/InitTweak.h" 64 #include "CodeGen/CodeGenerator.h" 67 68 #include "SynTree/Expression.h" 69 #include "SynTree/Mutator.h" 70 #include "SynTree/Statement.h" 71 #include "SynTree/Type.h" 72 #include "SynTree/TypeSubstitution.h" 73 #include "SynTree/Visitor.h" 65 74 66 75 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } … … 96 105 97 106 /// Fix return types so that every function returns exactly one value 98 class ReturnTypeFixer final : public Visitor{107 class ReturnTypeFixer { 99 108 public: 100 typedef Visitor Parent;101 using Parent::visit;102 103 109 static void fix( std::list< Declaration * > &translationUnit ); 104 110 105 v irtual voidvisit( FunctionDecl * functionDecl );106 v irtual voidvisit( FunctionType * ftype );111 void postvisit( FunctionDecl * functionDecl ); 112 void postvisit( FunctionType * ftype ); 107 113 }; 108 114 … … 153 159 }; 154 160 155 class ReturnChecker : public Visitor{161 class ReturnChecker { 156 162 public: 157 163 /// Checks that return statements return nothing if their return type is void … … 159 165 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 160 166 private: 161 virtual void visit( FunctionDecl * functionDecl ); 162 virtual void visit( ReturnStmt * returnStmt ); 163 164 std::list< DeclarationWithType * > returnVals; 167 void previsit( FunctionDecl * functionDecl ); 168 void postvisit( FunctionDecl * functionDecl ); 169 void previsit( ReturnStmt * returnStmt ); 170 171 typedef std::list< DeclarationWithType * > ReturnVals; 172 ReturnVals returnVals; 173 std::stack< ReturnVals > returnValsStack; 165 174 }; 166 175 … … 198 207 }; 199 208 200 class VerifyCtorDtorAssign : public Visitor{209 class VerifyCtorDtorAssign { 201 210 public: 202 211 /// ensure that constructors, destructors, and assignment have at least one … … 205 214 static void verify( std::list< Declaration * > &translationUnit ); 206 215 207 v irtual voidvisit( FunctionDecl *funcDecl );216 void previsit( FunctionDecl *funcDecl ); 208 217 }; 209 218 210 219 /// ensure that generic types have the correct number of type arguments 211 class ValidateGenericParameters : public Visitor{220 class ValidateGenericParameters { 212 221 public: 213 typedef Visitor Parent; 214 virtual void visit( StructInstType * inst ) final override; 215 virtual void visit( UnionInstType * inst ) final override; 216 }; 217 218 class ArrayLength : public Visitor { 222 void previsit( StructInstType * inst ); 223 void previsit( UnionInstType * inst ); 224 }; 225 226 class ArrayLength { 219 227 public: 220 228 /// for array types without an explicit length, compute the length and store it so that it … … 227 235 static void computeLength( std::list< Declaration * > & translationUnit ); 228 236 229 v irtual voidvisit( ObjectDecl * objDecl );237 void previsit( ObjectDecl * objDecl ); 230 238 }; 231 239 … … 243 251 Pass3 pass3( 0 ); 244 252 CompoundLiteral compoundliteral; 245 ValidateGenericParametersgenericParams;253 PassVisitor<ValidateGenericParameters> genericParams; 246 254 247 255 EliminateTypedef::eliminateTypedef( translationUnit ); … … 594 602 595 603 void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) { 596 ReturnCheckerchecker;604 PassVisitor<ReturnChecker> checker; 597 605 acceptAll( translationUnit, checker ); 598 606 } 599 607 600 void ReturnChecker:: visit( FunctionDecl * functionDecl ) {601 std::list< DeclarationWithType * > oldReturnVals = returnVals;608 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 609 returnValsStack.push( returnVals ); 602 610 returnVals = functionDecl->get_functionType()->get_returnVals(); 603 Visitor::visit( functionDecl ); 604 returnVals = oldReturnVals; 605 } 606 607 void ReturnChecker::visit( ReturnStmt * returnStmt ) { 611 } 612 void ReturnChecker::postvisit( FunctionDecl * functionDecl ) { 613 returnVals = returnValsStack.top(); 614 returnValsStack.pop(); 615 } 616 617 void ReturnChecker::previsit( ReturnStmt * returnStmt ) { 608 618 // Previously this also checked for the existence of an expr paired with no return values on 609 619 // the function return type. This is incorrect, since you can have an expression attached to … … 815 825 816 826 void VerifyCtorDtorAssign::verify( std::list< Declaration * > & translationUnit ) { 817 VerifyCtorDtorAssignverifier;827 PassVisitor<VerifyCtorDtorAssign> verifier; 818 828 acceptAll( translationUnit, verifier ); 819 829 } 820 830 821 void VerifyCtorDtorAssign:: visit( FunctionDecl * funcDecl ) {831 void VerifyCtorDtorAssign::previsit( FunctionDecl * funcDecl ) { 822 832 FunctionType * funcType = funcDecl->get_functionType(); 823 833 std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals(); … … 836 846 } 837 847 } 838 839 Visitor::visit( funcDecl );840 848 } 841 849 … … 875 883 } 876 884 877 void ValidateGenericParameters:: visit( StructInstType * inst ) {885 void ValidateGenericParameters::previsit( StructInstType * inst ) { 878 886 validateGeneric( inst ); 879 Parent::visit( inst ); 880 } 881 882 void ValidateGenericParameters::visit( UnionInstType * inst ) { 887 } 888 889 void ValidateGenericParameters::previsit( UnionInstType * inst ) { 883 890 validateGeneric( inst ); 884 Parent::visit( inst );885 891 } 886 892 … … 906 912 907 913 void ReturnTypeFixer::fix( std::list< Declaration * > &translationUnit ) { 908 ReturnTypeFixerfixer;914 PassVisitor<ReturnTypeFixer> fixer; 909 915 acceptAll( translationUnit, fixer ); 910 916 } 911 917 912 void ReturnTypeFixer::visit( FunctionDecl * functionDecl ) { 913 Parent::visit( functionDecl ); 918 void ReturnTypeFixer::postvisit( FunctionDecl * functionDecl ) { 914 919 FunctionType * ftype = functionDecl->get_functionType(); 915 920 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals(); … … 925 930 } 926 931 927 void ReturnTypeFixer:: visit( FunctionType * ftype ) {932 void ReturnTypeFixer::postvisit( FunctionType * ftype ) { 928 933 // xxx - need to handle named return values - this information needs to be saved somehow 929 934 // so that resolution has access to the names. … … 943 948 944 949 void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) { 945 ArrayLengthlen;950 PassVisitor<ArrayLength> len; 946 951 acceptAll( translationUnit, len ); 947 952 } 948 953 949 void ArrayLength:: visit( ObjectDecl * objDecl ) {954 void ArrayLength::previsit( ObjectDecl * objDecl ) { 950 955 if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) { 951 956 if ( at->get_dimension() != nullptr ) return;
Note: See TracChangeset
for help on using the changeset viewer.