Changeset f441c88
- Timestamp:
- Nov 2, 2018, 4:14:33 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 5753b33, 8e04794
- Parents:
- c45b304
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TypeData.cc
rc45b304 rf441c88 522 522 switch ( td->kind ) { 523 523 case TypeData::Unknown: 524 // fill in implicit int525 return new BasicType( buildQualifiers( td ), BasicType::SignedInt );524 // fill in implicit int 525 return new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 526 526 case TypeData::Basic: 527 return buildBasicType( td );527 return buildBasicType( td ); 528 528 case TypeData::Pointer: 529 return buildPointer( td );529 return buildPointer( td ); 530 530 case TypeData::Array: 531 return buildArray( td );531 return buildArray( td ); 532 532 case TypeData::Reference: 533 return buildReference( td );533 return buildReference( td ); 534 534 case TypeData::Function: 535 return buildFunction( td );535 return buildFunction( td ); 536 536 case TypeData::AggregateInst: 537 return buildAggInst( td );537 return buildAggInst( td ); 538 538 case TypeData::EnumConstant: 539 // the name gets filled in later -- by SymTab::Validate540 return new EnumInstType( buildQualifiers( td ), "" );539 // the name gets filled in later -- by SymTab::Validate 540 return new EnumInstType( buildQualifiers( td ), "" ); 541 541 case TypeData::SymbolicInst: 542 return buildSymbolicInst( td );542 return buildSymbolicInst( td ); 543 543 case TypeData::Tuple: 544 return buildTuple( td );544 return buildTuple( td ); 545 545 case TypeData::Typeof: 546 546 case TypeData::Basetypeof: 547 return buildTypeof( td );547 return buildTypeof( td ); 548 548 case TypeData::Builtin: 549 if(td->builtintype == DeclarationNode::Zero) {550 return new ZeroType( noQualifiers );551 }552 else if(td->builtintype == DeclarationNode::One) {553 return new OneType( noQualifiers );554 }555 else {556 return new VarArgsType( buildQualifiers( td ) );557 }549 if (td->builtintype == DeclarationNode::Zero) { 550 return new ZeroType( noQualifiers ); 551 } 552 else if (td->builtintype == DeclarationNode::One) { 553 return new OneType( noQualifiers ); 554 } 555 else { 556 return new VarArgsType( buildQualifiers( td ) ); 557 } 558 558 case TypeData::GlobalScope: 559 return new GlobalScopeType();559 return new GlobalScopeType(); 560 560 case TypeData::Qualified: 561 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );561 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) ); 562 562 case TypeData::Symbolic: 563 563 case TypeData::Enum: 564 564 case TypeData::Aggregate: 565 assert( false );565 assert( false ); 566 566 } // switch 567 567 … … 942 942 assert( td->typeexpr ); 943 943 // assert( td->typeexpr->expr ); 944 return new TypeofType( td->kind == TypeData::Basetypeof ? Type::Qualifiers{} : buildQualifiers( td ), td->typeexpr->build() ); 944 return new TypeofType{ 945 buildQualifiers( td ), td->typeexpr->build(), td->kind == TypeData::Basetypeof }; 945 946 } // buildTypeof 946 947 -
src/ResolvExpr/ResolveTypeof.cc
rc45b304 rf441c88 67 67 std::cerr << std::endl; 68 68 #endif 69 if ( typeofType->expr ) { 69 // pass on null expression 70 if ( ! typeofType->expr ) return typeofType; 71 72 bool isBasetypeof = typeofType->is_basetypeof; 73 auto oldQuals = typeofType->get_qualifiers().val; 74 75 Type* newType; 76 if ( TypeExpr* tyExpr = dynamic_cast<TypeExpr*>(typeofType->expr) ) { 77 // typeof wrapping type 78 newType = tyExpr->type; 79 tyExpr->type = nullptr; 80 delete tyExpr; 81 } else { 82 // typeof wrapping expression 70 83 Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer ); 71 84 assert( newExpr->result && ! newExpr->result->isVoid() ); 72 Type *newType = newExpr->result;85 newType = newExpr->result; 73 86 newExpr->result = nullptr; 74 87 delete typeofType; 75 88 delete newExpr; 76 return newType; 77 } // if 78 return typeofType; 89 } 90 91 // clear qualifiers for base, combine with typeoftype quals in any case 92 if ( isBasetypeof ) { 93 newType->get_qualifiers().val 94 = ( newType->get_qualifiers().val & ~Type::Qualifiers::Mask ) | oldQuals; 95 } else { 96 newType->get_qualifiers().val |= oldQuals; 97 } 98 99 return newType; 79 100 } 80 101 } // namespace ResolvExpr -
src/SynTree/Type.h
rc45b304 rf441c88 598 598 class TypeofType : public Type { 599 599 public: 600 Expression *expr; 601 602 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 600 Expression *expr; ///< expression to take the type of 601 bool is_basetypeof; ///< true iff is basetypeof type 602 603 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 604 TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof, 605 const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 603 606 TypeofType( const TypeofType& ); 604 607 virtual ~TypeofType(); -
src/SynTree/TypeofType.cc
rc45b304 rf441c88 23 23 class Attribute; 24 24 25 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), expr( expr ) { 26 } 25 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, 26 const std::list< Attribute * > & attributes ) 27 : Type( tq, attributes ), expr( expr ), is_basetypeof(false) {} 27 28 28 TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) { 29 } 29 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, bool is_basetypeof, 30 const std::list< Attribute * > & attributes ) 31 : Type( tq, attributes ), expr( expr ), is_basetypeof( is_basetypeof ) {} 32 33 TypeofType::TypeofType( const TypeofType &other ) 34 : Type( other ), expr( maybeClone( other.expr ) ), is_basetypeof( other.is_basetypeof ) {} 30 35 31 36 TypeofType::~TypeofType() { … … 35 40 void TypeofType::print( std::ostream &os, Indenter indent ) const { 36 41 Type::print( os, indent ); 42 if ( is_basetypeof ) { os << "base-"; } 37 43 os << "type-of expression "; 38 44 if ( expr ) {
Note: See TracChangeset
for help on using the changeset viewer.