Changeset 5b51f5e for src/SynTree
- Timestamp:
- Jan 5, 2018, 3:21:42 PM (8 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:
- 65deb18, cae28da
- Parents:
- 5c4f2c2 (diff), b834e98 (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/SynTree
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AggregateDecl.cc
r5c4f2c2 r5b51f5e 86 86 std::string TraitDecl::typeString() const { return "trait"; } 87 87 88 namespace { 89 long long int getConstValue( Expression * expr ) { 90 if ( CastExpr * castExpr = dynamic_cast< CastExpr * > ( expr ) ) { 91 return getConstValue( castExpr->arg ); 92 } else if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 93 return constExpr->intValue(); 94 } else { 95 assertf( false, "Unhandled expression type in getConstValue for enumerators: %s", toString( expr ).c_str() ); 96 } 97 } 98 } 99 100 bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) { 101 if ( enumValues.empty() ) { 102 long long int currentValue = 0; 103 for ( Declaration * member : members ) { 104 ObjectDecl * field = strict_dynamic_cast< ObjectDecl * >( member ); 105 if ( field->init ) { 106 SingleInit * init = strict_dynamic_cast< SingleInit * >( field->init ); 107 currentValue = getConstValue( init->value ); 108 } 109 assertf( enumValues.count( field->name ) == 0, "Enum %s has multiple members with the name %s", name.c_str(), field->name.c_str() ); 110 enumValues[ field->name ] = currentValue; 111 ++currentValue; 112 } 113 } 114 if ( enumValues.count( enumerator->name ) ) { 115 value = enumValues[ enumerator->name ]; 116 return true; 117 } 118 return false; 119 } 120 88 121 // Local Variables: // 89 122 // tab-width: 4 // -
src/SynTree/Declaration.h
r5c4f2c2 r5b51f5e 319 319 EnumDecl( const EnumDecl &other ) : Parent( other ) {} 320 320 321 bool valueOf( Declaration * enumerator, long long int & value ); 322 321 323 virtual EnumDecl *clone() const override { return new EnumDecl( *this ); } 322 324 virtual void accept( Visitor &v ) override { v.visit( this ); } 323 325 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 324 326 private: 327 std::map< std::string, long long int > enumValues; 325 328 virtual std::string typeString() const override; 326 329 }; -
src/SynTree/Expression.cc
r5c4f2c2 r5b51f5e 83 83 } 84 84 85 long long int ConstantExpr::intValue() const { 86 if ( BasicType * basicType = dynamic_cast< BasicType * >( result ) ) { 87 if ( basicType->isInteger() ) { 88 return get_constant()->get_ival(); 89 } 90 } else if ( dynamic_cast< OneType * >( result ) ) { 91 return 1; 92 } else if ( dynamic_cast< ZeroType * >( result ) ) { 93 return 0; 94 } 95 throw SemanticError( "Constant expression of non-integral type ", this ); 96 } 97 85 98 VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) { 86 99 assert( var ); … … 589 602 if ( ! body.empty() ) { 590 603 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) { 591 set_result( maybeClone( exprStmt->get_expr()->get_result() ));604 result = maybeClone( exprStmt->expr->result ); 592 605 } 593 606 } 594 607 // ensure that StmtExpr has a result type 595 608 if ( ! result ) { 596 set_result( new VoidType( Type::Qualifiers()) );609 result = new VoidType( Type::Qualifiers() ); 597 610 } 598 611 } -
src/SynTree/Expression.h
r5c4f2c2 r5b51f5e 295 295 296 296 Constant * get_constant() { return & constant; } 297 const Constant * get_constant() const { return & constant; } 297 298 void set_constant( const Constant & newValue ) { constant = newValue; } 299 300 long long int intValue() const; 298 301 299 302 virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); } -
src/SynTree/Type.h
r5c4f2c2 r5b51f5e 356 356 bool isTtype() const; 357 357 358 bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; } 359 358 360 virtual FunctionType *clone() const override { return new FunctionType( *this ); } 359 361 virtual void accept( Visitor & v ) override { v.visit( this ); }
Note:
See TracChangeset
for help on using the changeset viewer.