Changeset 9bfc9da
- Timestamp:
- Mar 7, 2018, 4:59:00 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:
- 02c816fc
- Parents:
- 2097cd4
- Location:
- src/SynTree
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r2097cd4 r9bfc9da 345 345 } 346 346 347 namespace {348 TypeSubstitution makeSub( Type * t ) {349 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) {350 return makeSub( refType->get_base() );351 } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {352 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );353 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {354 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );355 } else {356 assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );357 }358 }359 }360 361 362 347 MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) : 363 348 Expression(), member(member), aggregate(aggregate) { 364 349 assert( member ); 365 350 assert( aggregate ); 366 367 TypeSubstitution sub( makeSub( aggregate->get_result() ) ); 351 assert( aggregate->result ); 352 353 TypeSubstitution sub = aggregate->result->genericSubstitution(); 368 354 Type * res = member->get_type()->clone(); 369 355 sub.apply( res ); -
src/SynTree/ReferenceToType.cc
r2097cd4 r9bfc9da 14 14 // 15 15 16 #include <cassert> // for assert 17 #include <list> // for list, _List_const_iterator, list<>::cons... 18 #include <ostream> // for operator<<, basic_ostream, ostream, endl 19 #include <string> // for string, operator<<, char_traits, operator== 20 21 #include "Common/utility.h" // for printAll, cloneAll, deleteAll 22 #include "Declaration.h" // for StructDecl, UnionDecl, EnumDecl, Declara... 23 #include "Expression.h" // for Expression 24 #include "Type.h" // for TypeInstType, StructInstType, UnionInstType 16 #include <cassert> // for assert 17 #include <list> // for list, _List_const_iterator, list<>::cons... 18 #include <ostream> // for operator<<, basic_ostream, ostream, endl 19 #include <string> // for string, operator<<, char_traits, operator== 20 21 #include "Common/utility.h" // for printAll, cloneAll, deleteAll 22 #include "Declaration.h" // for StructDecl, UnionDecl, EnumDecl, Declara... 23 #include "Expression.h" // for Expression 24 #include "Type.h" // for TypeInstType, StructInstType, UnionInstType 25 #include "TypeSubstitution.h" // for TypeSubstitution 25 26 26 27 class Attribute; … … 63 64 std::string StructInstType::typeString() const { return "struct"; } 64 65 66 const std::list<TypeDecl*>* StructInstType::get_baseParameters() const { 67 if ( ! baseStruct ) return nullptr; 68 return &baseStruct->get_parameters(); 69 } 70 65 71 std::list<TypeDecl*>* StructInstType::get_baseParameters() { 66 72 if ( ! baseStruct ) return nullptr; … … 71 77 72 78 AggregateDecl * StructInstType::getAggr() { return baseStruct; } 79 80 TypeSubstitution StructInstType::genericSubstitution() const { 81 return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() ); 82 } 73 83 74 84 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { … … 102 112 } 103 113 114 const std::list< TypeDecl * > * UnionInstType::get_baseParameters() const { 115 if ( ! baseUnion ) return nullptr; 116 return &baseUnion->get_parameters(); 117 } 118 104 119 bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; } 105 120 106 121 AggregateDecl * UnionInstType::getAggr() { return baseUnion; } 122 123 TypeSubstitution UnionInstType::genericSubstitution() const { 124 return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() ); 125 } 107 126 108 127 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { -
src/SynTree/ReferenceType.cc
r2097cd4 r9bfc9da 16 16 #include "Type.h" 17 17 #include "Expression.h" 18 #include "TypeSubstitution.h" 18 19 #include "Common/utility.h" 19 20 … … 35 36 } 36 37 38 TypeSubstitution ReferenceType::genericSubstitution() const { return base->genericSubstitution(); } 39 37 40 void ReferenceType::print( std::ostream &os, Indenter indent ) const { 38 41 Type::print( os, indent ); -
src/SynTree/Type.cc
r2097cd4 r9bfc9da 15 15 #include "Type.h" 16 16 17 #include "Attribute.h" // for Attribute 18 #include "Common/utility.h" // for cloneAll, deleteAll, printAll 19 #include "InitTweak/InitTweak.h" // for getPointerBase 20 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode 21 #include "SynTree/Declaration.h" // for TypeDecl 17 #include "Attribute.h" // for Attribute 18 #include "Common/utility.h" // for cloneAll, deleteAll, printAll 19 #include "InitTweak/InitTweak.h" // for getPointerBase 20 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode 21 #include "SynTree/Declaration.h" // for TypeDecl 22 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 22 23 23 24 using namespace std; … … 81 82 int Type::referenceDepth() const { return 0; } 82 83 84 TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } 85 83 86 void Type::print( std::ostream &os, Indenter indent ) const { 84 87 if ( ! forall.empty() ) { -
src/SynTree/Type.h
r2097cd4 r9bfc9da 178 178 virtual bool isComplete() const { return true; } 179 179 180 virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toString( this ).c_str() ); } 180 virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } 181 182 virtual TypeSubstitution genericSubstitution() const; 181 183 182 184 virtual Type *clone() const = 0; … … 329 331 virtual unsigned size() const override { return base->size(); } 330 332 333 virtual TypeSubstitution genericSubstitution() const override; 334 331 335 virtual ReferenceType *clone() const override { return new ReferenceType( *this ); } 332 336 virtual void accept( Visitor & v ) override { v.visit( this ); } … … 406 410 /// Accesses generic parameters of base struct (NULL if none such) 407 411 std::list<TypeDecl*> * get_baseParameters(); 412 const std::list<TypeDecl*> * get_baseParameters() const; 408 413 409 414 virtual bool isComplete() const override; 410 415 411 416 virtual AggregateDecl * getAggr() override; 417 418 virtual TypeSubstitution genericSubstitution() const override; 412 419 413 420 /// Looks up the members of this struct named "name" and places them into "foundDecls". … … 439 446 440 447 /// Accesses generic parameters of base union (NULL if none such) 441 std::list< TypeDecl * > * get_baseParameters(); 448 std::list<TypeDecl*> * get_baseParameters(); 449 const std::list<TypeDecl*> * get_baseParameters() const; 442 450 443 451 virtual bool isComplete() const override; 444 452 445 453 virtual AggregateDecl * getAggr() override; 454 455 virtual TypeSubstitution genericSubstitution() const override; 446 456 447 457 /// looks up the members of this union named "name" and places them into "foundDecls"
Note: See TracChangeset
for help on using the changeset viewer.