Changeset b6838214 for src/ResolvExpr/CurrentObject.cc
- Timestamp:
- Jan 23, 2018, 5:46:43 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:
- 258e6ad5
- Parents:
- b158d8f (diff), 15d248e (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
rb158d8f rb6838214 38 38 39 39 namespace ResolvExpr { 40 long long int getConstValue( ConstantExpr * constExpr ) {41 if ( BasicType * basicType = dynamic_cast< BasicType * >( constExpr->get_result() ) ) {42 if ( basicType->isInteger() ) {43 return constExpr->get_constant()->get_ival();44 } else {45 assertf( false, "Non-integer constant expression in getConstValue %s", toString( constExpr ).c_str() ); // xxx - might be semantic error46 }47 } else if ( dynamic_cast< OneType * >( constExpr->get_result() ) ) {48 return 1;49 } else if ( dynamic_cast< ZeroType * >( constExpr->get_result() ) ) {50 return 0;51 } else {52 assertf( false, "unhandled type on getConstValue %s", toString( constExpr->get_result() ).c_str() ); // xxx - might be semantic error53 }54 }55 56 40 template< typename AggrInst > 57 41 TypeSubstitution makeGenericSubstitution( AggrInst * inst ) { … … 78 62 virtual ~MemberIterator() {} 79 63 64 /// walks the current object using the given designators as a guide 80 65 virtual void setPosition( std::list< Expression * > & designators ) = 0; 66 67 /// retrieve the list of possible Type/Designaton pairs for the current position in the currect object 81 68 virtual std::list<InitAlternative> operator*() const = 0; 69 70 /// true if the iterator is not currently at the end 82 71 virtual operator bool() const = 0; 72 73 /// moves the iterator by one member in the current object 83 74 virtual MemberIterator & bigStep() = 0; 75 76 /// moves the iterator by one member in the current subobject 84 77 virtual MemberIterator & smallStep() = 0; 78 79 /// the type of the current object 85 80 virtual Type * getType() = 0; 81 82 /// the type of the current subobject 86 83 virtual Type * getNext() = 0; 87 84 85 /// printing for debug 88 86 virtual void print( std::ostream & out, Indenter indent ) const = 0; 89 87 88 /// helper for operator*; aggregates must add designator to each init alternative, but 89 /// adding designators in operator* creates duplicates. 90 90 virtual std::list<InitAlternative> first() const = 0; // should be protected 91 91 }; … … 141 141 base = at->get_base(); 142 142 memberIter = createMemberIterator( base ); 143 if ( at->isVarLen ) throw SemanticError( "VLA initialization does not support @=", at ); 143 144 setSize( at->get_dimension() ); 144 145 } … … 151 152 void setSize( Expression * expr ) { 152 153 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 153 size = getConstValue( constExpr ); 154 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 154 try { 155 size = constExpr->intValue(); 156 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 157 } catch ( SemanticError & ) { 158 throw SemanticError( "Constant expression of non-integral type in array dimension: ", expr ); 159 } 155 160 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 156 161 setSize( castExpr->get_arg() ); // xxx - need to perform the conversion specified by the cast 162 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 163 if ( EnumInstType * inst = dynamic_cast< EnumInstType * > ( varExpr->result ) ) { 164 long long int value; 165 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 166 size = value; 167 } 168 } 157 169 } else { 158 170 assertf( false, "unhandled expression in setSize: %s", toString( expr ).c_str() ); // xxx - if not a constant expression, it's not simple to determine how long the array actually is, which is necessary for initialization to be done correctly -- fix this … … 164 176 // need to permit integer-constant-expressions, including: integer constants, enumeration constants, character constants, sizeof expressions, _Alignof expressions, cast expressions 165 177 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 166 index = getConstValue( constExpr ); 178 try { 179 index = constExpr->intValue(); 180 } catch( SemanticError & ) { 181 throw SemanticError( "Constant expression of non-integral type in array designator: ", expr ); 182 } 167 183 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 168 184 setPosition( castExpr->get_arg() ); 169 185 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 170 assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 171 index = 0; // xxx - get actual value of enum constant 186 EnumInstType * inst = dynamic_cast<EnumInstType *>( varExpr->get_result() ); 187 assertf( inst, "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 188 long long int value; 189 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 190 index = value; 191 } 172 192 } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) { 173 193 index = 0; // xxx - get actual sizeof/alignof value? … … 350 370 } 351 371 } 352 // if ( curMember == std::next( decl->get_members().begin(), 1 ) ) { // xxx - this never triggers because curMember is incremented immediately on construction 353 if ( atbegin ) { // xxx - this never triggers because curMember is incremented immediately on construction 372 if ( atbegin ) { 354 373 // xxx - what about case of empty struct?? 355 374 // only add self if at the very beginning of the structure … … 385 404 return *this; 386 405 } 387 virtual std::list<InitAlternative> first() const { return std::list<InitAlternative>{}; }388 406 }; 389 407 … … 439 457 return new UnionIterator( uit ); 440 458 } else { 441 assertf( dynamic_cast< TypeInstType * >( type ), "some other reftotype");459 assertf( dynamic_cast< EnumInstType * >( type ) || dynamic_cast< TypeInstType * >( type ), "Encountered unhandled ReferenceToType in createMemberIterator: %s", toString( type ).c_str() ); 442 460 return new SimpleIterator( type ); 443 461 }
Note:
See TracChangeset
for help on using the changeset viewer.