Changeset 40e636a
- Timestamp:
- Jul 21, 2016, 11:19:24 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, 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:
- b81adcc4
- Parents:
- 5f98ce5
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r5f98ce5 r40e636a 46 46 FunctionDecl * destroyFunction; 47 47 }; 48 49 class ConstExprChecker : public Visitor {50 public:51 ConstExprChecker() : isConstExpr( true ) {}52 53 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }54 virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; }55 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; }56 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }57 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }58 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }59 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }60 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }61 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }62 // these might be okay?63 // virtual void visit( SizeofExpr *sizeofExpr );64 // virtual void visit( AlignofExpr *alignofExpr );65 // virtual void visit( UntypedOffsetofExpr *offsetofExpr );66 // virtual void visit( OffsetofExpr *offsetofExpr );67 // virtual void visit( OffsetPackExpr *offsetPackExpr );68 // virtual void visit( AttrExpr *attrExpr );69 // virtual void visit( CommaExpr *commaExpr );70 // virtual void visit( LogicalExpr *logicalExpr );71 // virtual void visit( ConditionalExpr *conditionalExpr );72 virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; }73 virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; }74 virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; }75 virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; }76 virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; }77 virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; }78 79 bool isConstExpr;80 };81 82 bool isConstExpr( Expression * expr ) {83 if ( expr ) {84 ConstExprChecker checker;85 expr->accept( checker );86 return checker.isConstExpr;87 }88 return true;89 }90 91 bool isConstExpr( Initializer * init ) {92 if ( init ) {93 ConstExprChecker checker;94 init->accept( checker );95 return checker.isConstExpr;96 } // if97 // for all intents and purposes, no initializer means const expr98 return true;99 }100 48 101 49 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) { … … 159 107 // xxx - initialize each element of the array 160 108 } else { 161 // steal initializer from object and attach it to a new temporary 162 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() ); 163 objDecl->set_init( NULL ); 164 initStatements.push_back( new DeclStmt( noLabels, newObj ) ); 165 166 // copy construct objDecl using temporary 109 // insert constructor for objDecl into global init function 167 110 UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) ); 168 111 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 169 init->get_args().push_back( new VariableExpr( newObj ) ); 112 init->get_args().splice( init->get_args().end(), makeInitList( objDecl->get_init() ) ); 113 objDecl->set_init( NULL ); 170 114 initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init ) ) ); 171 115 -
src/InitTweak/GenInit.cc
r5f98ce5 r40e636a 90 90 91 91 private: 92 DeclarationWithType * mutate( ObjectDecl * objectDecl ); 92 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ); 93 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 93 94 // should not traverse into any of these declarations to find objects 94 95 // that need to be constructed or destructed … … 105 106 106 107 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass; 108 bool inFunction = false; 107 109 }; 108 110 … … 157 159 void HoistArrayDimension::hoistArrayDimension( std::list< Declaration * > & translationUnit ) { 158 160 HoistArrayDimension hoister; 159 mutateAll( translationUnit, hoister);161 hoister.mutateDeclarationList( translationUnit ); 160 162 } 161 163 … … 169 171 170 172 void HoistArrayDimension::hoist( Type * type ) { 173 // if in function, generate const size_t var 171 174 static UniqueName dimensionName( "_array_dim" ); 172 175 if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) { 176 if ( ! inFunction ) return; 177 173 178 if ( ! arrayType->get_dimension() ) return; // xxx - recursive call to hoist? 174 179 … … 186 191 return; 187 192 } 193 } 194 195 DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) { 196 bool oldInFunc = inFunction; 197 inFunction = true; 198 DeclarationWithType * decl = Parent::mutate( functionDecl ); 199 inFunction = oldInFunc; 200 return decl; 188 201 } 189 202 -
src/InitTweak/InitTweak.cc
r5f98ce5 r40e636a 160 160 else return NULL; 161 161 } 162 163 class ConstExprChecker : public Visitor { 164 public: 165 ConstExprChecker() : isConstExpr( true ) {} 166 167 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; } 168 virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; } 169 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; } 170 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 171 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 172 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 173 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; } 174 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; } 175 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ } 176 // these might be okay? 177 // virtual void visit( SizeofExpr *sizeofExpr ); 178 // virtual void visit( AlignofExpr *alignofExpr ); 179 // virtual void visit( UntypedOffsetofExpr *offsetofExpr ); 180 // virtual void visit( OffsetofExpr *offsetofExpr ); 181 // virtual void visit( OffsetPackExpr *offsetPackExpr ); 182 // virtual void visit( AttrExpr *attrExpr ); 183 // virtual void visit( CommaExpr *commaExpr ); 184 // virtual void visit( LogicalExpr *logicalExpr ); 185 // virtual void visit( ConditionalExpr *conditionalExpr ); 186 virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; } 187 virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; } 188 virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; } 189 virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; } 190 virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; } 191 virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; } 192 193 bool isConstExpr; 194 }; 195 196 bool isConstExpr( Expression * expr ) { 197 if ( expr ) { 198 ConstExprChecker checker; 199 expr->accept( checker ); 200 return checker.isConstExpr; 201 } 202 return true; 203 } 204 205 bool isConstExpr( Initializer * init ) { 206 if ( init ) { 207 ConstExprChecker checker; 208 init->accept( checker ); 209 return checker.isConstExpr; 210 } // if 211 // for all intents and purposes, no initializer means const expr 212 return true; 213 } 214 162 215 } -
src/ResolvExpr/Resolver.cc
r5f98ce5 r40e636a 42 42 43 43 virtual void visit( ArrayType * at ); 44 virtual void visit( PointerType * at ); 44 45 45 46 virtual void visit( ExprStmt *exprStmt ); … … 60 61 private: 61 62 typedef std::list< Initializer * >::iterator InitIterator; 63 64 template< typename PtrType > 65 void handlePtrType( PtrType * type ); 62 66 63 67 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); … … 193 197 } 194 198 199 template< typename PtrType > 200 void Resolver::handlePtrType( PtrType * type ) { 201 if ( type->get_dimension() ) { 202 CastExpr *castExpr = new CastExpr( type->get_dimension(), SymTab::SizeType->clone() ); 203 Expression *newExpr = findSingleExpression( castExpr, *this ); 204 delete type->get_dimension(); 205 type->set_dimension( newExpr ); 206 } 207 } 208 195 209 void Resolver::visit( ArrayType * at ) { 196 if ( at->get_dimension() ) { 197 CastExpr *castExpr = new CastExpr( at->get_dimension(), SymTab::SizeType->clone() ); 198 Expression *newExpr = findSingleExpression( castExpr, *this ); 199 delete at->get_dimension(); 200 at->set_dimension( newExpr ); 201 } 210 handlePtrType( at ); 202 211 Visitor::visit( at ); 212 } 213 214 void Resolver::visit( PointerType * pt ) { 215 handlePtrType( pt ); 216 Visitor::visit( pt ); 203 217 } 204 218 -
src/SymTab/FixFunction.cc
r5f98ce5 r40e636a 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixFunction.cc -- 7 // FixFunction.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 44 44 45 45 Type * FixFunction::mutate(ArrayType *arrayType) { 46 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), maybeClone( arrayType->get_base()->clone() ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 46 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 47 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 47 48 delete arrayType; 48 49 return pointerType; -
src/SymTab/Validate.cc
r5f98ce5 r40e636a 191 191 EliminateTypedef::eliminateTypedef( translationUnit ); 192 192 HoistStruct::hoistStruct( translationUnit ); 193 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs Pass1 193 194 acceptAll( translationUnit, pass1 ); 194 195 acceptAll( translationUnit, pass2 ); 195 196 ReturnChecker::checkFunctionReturns( translationUnit ); 196 mutateAll( translationUnit, compoundliteral ); 197 autogenerateRoutines( translationUnit ); 197 compoundliteral.mutateDeclarationList( translationUnit ); 198 198 acceptAll( translationUnit, pass3 ); 199 199 VerifyCtorDtor::verify( translationUnit ); … … 494 494 SizeType = eliminator.typedefNames["size_t"].first->get_base()->clone(); 495 495 } else { 496 assert( false && "missing global typedef for size_t" ); 496 // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong 497 // eventually should have a warning for this case. 498 SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 497 499 } 498 500 filter( translationUnit, isTypedef, true );
Note: See TracChangeset
for help on using the changeset viewer.