Changeset d60ccbf for src/SymTab
- Timestamp:
- Aug 12, 2015, 2:27:31 PM (10 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, string, with_gc
- Children:
- f32c7f4
- Parents:
- e45215c (diff), e869d663 (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. - Location:
- src/SymTab
- Files:
-
- 6 edited
-
FixFunction.h (modified) (1 diff)
-
Indexer.cc (modified) (4 diffs)
-
Indexer.h (modified) (2 diffs)
-
TypeEquality.cc (modified) (2 diffs)
-
Validate.cc (modified) (14 diffs)
-
Validate.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/FixFunction.h
re45215c rd60ccbf 20 20 21 21 namespace SymTab { 22 /// Replaces function and array types by equivalent pointer types. 22 23 class FixFunction : public Mutator { 23 24 typedef Mutator Parent; -
src/SymTab/Indexer.cc
re45215c rd60ccbf 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:37:33 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jun 5 08:05:17201513 // Update Count : 511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 05 13:52:42 2015 13 // Update Count : 10 14 14 // 15 15 … … 26 26 27 27 namespace SymTab { 28 template< typename Container, typename VisitorType > 29 inline void acceptAllNewScope( Container &container, VisitorType &visitor ) { 30 visitor.enterScope(); 31 acceptAll( container, visitor ); 32 visitor.leaveScope(); 33 } 34 28 35 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {} 29 36 … … 31 38 32 39 void Indexer::visit( ObjectDecl *objectDecl ) { 40 enterScope(); 33 41 maybeAccept( objectDecl->get_type(), *this ); 42 leaveScope(); 34 43 maybeAccept( objectDecl->get_init(), *this ); 35 44 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); … … 149 158 leaveScope(); 150 159 } 160 161 162 void Indexer::visit( ApplicationExpr *applicationExpr ) { 163 acceptAllNewScope( applicationExpr->get_results(), *this ); 164 maybeAccept( applicationExpr->get_function(), *this ); 165 acceptAll( applicationExpr->get_args(), *this ); 166 } 167 168 void Indexer::visit( UntypedExpr *untypedExpr ) { 169 acceptAllNewScope( untypedExpr->get_results(), *this ); 170 acceptAll( untypedExpr->get_args(), *this ); 171 } 172 173 void Indexer::visit( NameExpr *nameExpr ) { 174 acceptAllNewScope( nameExpr->get_results(), *this ); 175 } 176 177 void Indexer::visit( AddressExpr *addressExpr ) { 178 acceptAllNewScope( addressExpr->get_results(), *this ); 179 maybeAccept( addressExpr->get_arg(), *this ); 180 } 181 182 void Indexer::visit( LabelAddressExpr *labAddressExpr ) { 183 acceptAllNewScope( labAddressExpr->get_results(), *this ); 184 maybeAccept( labAddressExpr->get_arg(), *this ); 185 } 186 187 void Indexer::visit( CastExpr *castExpr ) { 188 acceptAllNewScope( castExpr->get_results(), *this ); 189 maybeAccept( castExpr->get_arg(), *this ); 190 } 191 192 void Indexer::visit( UntypedMemberExpr *memberExpr ) { 193 acceptAllNewScope( memberExpr->get_results(), *this ); 194 maybeAccept( memberExpr->get_aggregate(), *this ); 195 } 196 197 void Indexer::visit( MemberExpr *memberExpr ) { 198 acceptAllNewScope( memberExpr->get_results(), *this ); 199 maybeAccept( memberExpr->get_aggregate(), *this ); 200 } 201 202 void Indexer::visit( VariableExpr *variableExpr ) { 203 acceptAllNewScope( variableExpr->get_results(), *this ); 204 } 205 206 void Indexer::visit( ConstantExpr *constantExpr ) { 207 acceptAllNewScope( constantExpr->get_results(), *this ); 208 maybeAccept( constantExpr->get_constant(), *this ); 209 } 210 211 void Indexer::visit( SizeofExpr *sizeofExpr ) { 212 acceptAllNewScope( sizeofExpr->get_results(), *this ); 213 if ( sizeofExpr->get_isType() ) { 214 maybeAccept( sizeofExpr->get_type(), *this ); 215 } else { 216 maybeAccept( sizeofExpr->get_expr(), *this ); 217 } 218 } 219 220 void Indexer::visit( AttrExpr *attrExpr ) { 221 acceptAllNewScope( attrExpr->get_results(), *this ); 222 if ( attrExpr->get_isType() ) { 223 maybeAccept( attrExpr->get_type(), *this ); 224 } else { 225 maybeAccept( attrExpr->get_expr(), *this ); 226 } 227 } 228 229 void Indexer::visit( LogicalExpr *logicalExpr ) { 230 acceptAllNewScope( logicalExpr->get_results(), *this ); 231 maybeAccept( logicalExpr->get_arg1(), *this ); 232 maybeAccept( logicalExpr->get_arg2(), *this ); 233 } 234 235 void Indexer::visit( ConditionalExpr *conditionalExpr ) { 236 acceptAllNewScope( conditionalExpr->get_results(), *this ); 237 maybeAccept( conditionalExpr->get_arg1(), *this ); 238 maybeAccept( conditionalExpr->get_arg2(), *this ); 239 maybeAccept( conditionalExpr->get_arg3(), *this ); 240 } 241 242 void Indexer::visit( CommaExpr *commaExpr ) { 243 acceptAllNewScope( commaExpr->get_results(), *this ); 244 maybeAccept( commaExpr->get_arg1(), *this ); 245 maybeAccept( commaExpr->get_arg2(), *this ); 246 } 247 248 void Indexer::visit( TupleExpr *tupleExpr ) { 249 acceptAllNewScope( tupleExpr->get_results(), *this ); 250 acceptAll( tupleExpr->get_exprs(), *this ); 251 } 252 253 void Indexer::visit( SolvedTupleExpr *tupleExpr ) { 254 acceptAllNewScope( tupleExpr->get_results(), *this ); 255 acceptAll( tupleExpr->get_exprs(), *this ); 256 } 257 258 void Indexer::visit( TypeExpr *typeExpr ) { 259 acceptAllNewScope( typeExpr->get_results(), *this ); 260 maybeAccept( typeExpr->get_type(), *this ); 261 } 262 263 void Indexer::visit( AsmExpr *asmExpr ) { 264 maybeAccept( asmExpr->get_inout(), *this ); 265 maybeAccept( asmExpr->get_constraint(), *this ); 266 maybeAccept( asmExpr->get_operand(), *this ); 267 } 268 269 void Indexer::visit( UntypedValofExpr *valofExpr ) { 270 acceptAllNewScope( valofExpr->get_results(), *this ); 271 maybeAccept( valofExpr->get_body(), *this ); 272 } 273 151 274 152 275 void Indexer::visit( ContextInstType *contextInst ) { -
src/SymTab/Indexer.h
re45215c rd60ccbf 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:38:55 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 16:51:21201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 05 13:51:39 2015 13 // Update Count : 4 14 14 // 15 15 … … 43 43 44 44 virtual void visit( CompoundStmt *compoundStmt ); 45 46 virtual void visit( ApplicationExpr *applicationExpr ); 47 virtual void visit( UntypedExpr *untypedExpr ); 48 virtual void visit( NameExpr *nameExpr ); 49 virtual void visit( CastExpr *castExpr ); 50 virtual void visit( AddressExpr *addressExpr ); 51 virtual void visit( LabelAddressExpr *labAddressExpr ); 52 virtual void visit( UntypedMemberExpr *memberExpr ); 53 virtual void visit( MemberExpr *memberExpr ); 54 virtual void visit( VariableExpr *variableExpr ); 55 virtual void visit( ConstantExpr *constantExpr ); 56 virtual void visit( SizeofExpr *sizeofExpr ); 57 virtual void visit( AttrExpr *attrExpr ); 58 virtual void visit( LogicalExpr *logicalExpr ); 59 virtual void visit( ConditionalExpr *conditionalExpr ); 60 virtual void visit( CommaExpr *commaExpr ); 61 virtual void visit( TupleExpr *tupleExpr ); 62 virtual void visit( SolvedTupleExpr *tupleExpr ); 63 virtual void visit( TypeExpr *typeExpr ); 64 virtual void visit( AsmExpr *asmExpr ); 65 virtual void visit( UntypedValofExpr *valofExpr ); 45 66 46 67 virtual void visit( ContextInstType *contextInst ); -
src/SymTab/TypeEquality.cc
re45215c rd60ccbf 10 10 // Created On : Tue Jul 07 16:28:29 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jul 09 11:18:46201513 // Update Count : 3 612 // Last Modified On : Mon Jul 20 14:16:11 2015 13 // Update Count : 37 14 14 // 15 15 … … 91 91 // and must both have a dimension expression or not have a dimension 92 92 result = result && arrayType->get_isVarLen() == at->get_isVarLen() 93 && ( arrayType->get_dimension() != 0 && at->get_dimension() != 094 || arrayType->get_dimension() == 0 && at->get_dimension() == 0);93 && ((arrayType->get_dimension() != 0 && at->get_dimension() != 0) 94 || (arrayType->get_dimension() == 0 && at->get_dimension() == 0)); 95 95 96 96 if ( vlaErr ) { -
src/SymTab/Validate.cc
re45215c rd60ccbf 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:27:54 201513 // Update Count : 1 8612 // Last Modified On : Wed Aug 05 14:00:24 2015 13 // Update Count : 195 14 14 // 15 15 … … 60 60 class HoistStruct : public Visitor { 61 61 public: 62 /// Flattens nested struct types 62 63 static void hoistStruct( std::list< Declaration * > &translationUnit ); 63 64 … … 84 85 }; 85 86 87 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers 86 88 class Pass1 : public Visitor { 87 89 typedef Visitor Parent; … … 89 91 virtual void visit( FunctionType *func ); 90 92 }; 91 93 94 /// Associates forward declarations of aggregates with their definitions 92 95 class Pass2 : public Indexer { 93 96 typedef Indexer Parent; … … 110 113 }; 111 114 115 /// Replaces array and function types in forall lists by appropriate pointer type 112 116 class Pass3 : public Indexer { 113 117 typedef Indexer Parent; … … 123 127 class AddStructAssignment : public Visitor { 124 128 public: 129 /// Generates assignment operators for aggregate types as required 125 130 static void addStructAssignment( std::list< Declaration * > &translationUnit ); 126 131 … … 158 163 public: 159 164 EliminateTypedef() : scopeLevel( 0 ) {} 165 /// Replaces typedefs by forward declarations 160 166 static void eliminateTypedef( std::list< Declaration * > &translationUnit ); 161 167 private: … … 163 169 virtual TypeDecl *mutate( TypeDecl *typeDecl ); 164 170 virtual DeclarationWithType *mutate( FunctionDecl *funcDecl ); 165 virtual ObjectDecl*mutate( ObjectDecl *objDecl );171 virtual DeclarationWithType *mutate( ObjectDecl *objDecl ); 166 172 virtual CompoundStmt *mutate( CompoundStmt *compoundStmt ); 167 173 virtual Type *mutate( TypeInstType *aggregateUseType ); … … 399 405 } // for 400 406 } // for 407 408 if ( ctx->get_parameters().size() != contextInst->get_parameters().size() ) { 409 throw SemanticError( "incorrect number of context parameters: ", contextInst ); 410 } // if 411 401 412 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 402 413 } … … 444 455 } 445 456 457 /// Fix up assertions 446 458 void forallFixer( Type *func ) { 447 // Fix up assertions448 459 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) { 449 460 std::list< DeclarationWithType * > toBeDone, nextRound; … … 532 543 std::list<Statement *> initList; 533 544 initList.push_back( initStmt ); 534 545 535 546 UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) ); 536 547 cond->get_args().push_back( new VariableExpr( index ) ); … … 610 621 delete assigns.front(); 611 622 assigns.pop_front(); 612 } 623 } // for 613 624 614 625 declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() ); … … 817 828 Type *ret = def->second.first->get_base()->clone(); 818 829 ret->get_qualifiers() += typeInst->get_qualifiers(); 830 // place instance parameters on the typedef'd type 831 if ( ! typeInst->get_parameters().empty() ) { 832 ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret); 833 if ( ! rtt ) { 834 throw SemanticError("cannot apply type parameters to base type of " + typeInst->get_name()); 835 } 836 rtt->get_parameters().clear(); 837 cloneAll(typeInst->get_parameters(), rtt->get_parameters()); 838 } // if 819 839 delete typeInst; 820 840 return ret; … … 870 890 } 871 891 872 ObjectDecl*EliminateTypedef::mutate( ObjectDecl * objDecl ) {892 DeclarationWithType *EliminateTypedef::mutate( ObjectDecl * objDecl ) { 873 893 TypedefMap oldNames = typedefNames; 874 ObjectDecl*ret = Mutator::mutate( objDecl );894 DeclarationWithType *ret = Mutator::mutate( objDecl ); 875 895 typedefNames = oldNames; 896 if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) { 897 return new FunctionDecl( ret->get_name(), ret->get_storageClass(), ret->get_linkage(), funtype, 0, ret->get_isInline(), ret->get_isNoreturn() ); 898 } else if ( objDecl->get_isInline() || objDecl->get_isNoreturn() ) { 899 throw SemanticError( "invalid inline or _Noreturn specification in declaration of ", objDecl ); 900 } // if 876 901 return ret; 877 902 } -
src/SymTab/Validate.h
re45215c rd60ccbf 23 23 class Indexer; 24 24 25 /// Normalizes struct and function declarations 25 26 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false ); 26 27 void validateType( Type *type, const Indexer *indexer );
Note:
See TracChangeset
for help on using the changeset viewer.