Changeset f64d9bc
- Timestamp:
- Dec 22, 2017, 4:20: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:
- f3458a8
- Parents:
- caab997
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
rcaab997 rf64d9bc 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 ) { … … 151 135 void setSize( Expression * expr ) { 152 136 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 153 size = getConstValue( constExpr ); 137 size = constExpr->intValue(); 138 isVLA = false; 154 139 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 155 140 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 156 141 setSize( castExpr->get_arg() ); // xxx - need to perform the conversion specified by the cast 142 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 143 if ( EnumInstType * inst = dynamic_cast< EnumInstType * > ( varExpr->result ) ) { 144 long long int value; 145 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 146 size = value; 147 isVLA = false; 148 } 149 } 157 150 } else { 158 151 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 157 // need to permit integer-constant-expressions, including: integer constants, enumeration constants, character constants, sizeof expressions, _Alignof expressions, cast expressions 165 158 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 166 index = getConstValue( constExpr);159 index = constExpr->intValue(); 167 160 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 168 161 setPosition( castExpr->get_arg() ); 169 162 } 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 163 EnumInstType * inst = dynamic_cast<EnumInstType *>( varExpr->get_result() ); 164 assertf( inst, "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 165 long long int value; 166 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 167 index = value; 168 } 172 169 } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) { 173 170 index = 0; // xxx - get actual sizeof/alignof value? … … 189 186 } 190 187 191 virtual operator bool() const { return index < size; }188 virtual operator bool() const { return ! isVLA && index < size; } 192 189 193 190 virtual MemberIterator & bigStep() { … … 195 192 ++index; 196 193 delete memberIter; 197 if ( index < size ) memberIter = createMemberIterator( base );194 if ( ! isVLA && index < size ) memberIter = createMemberIterator( base ); 198 195 else memberIter = nullptr; 199 196 return *this; … … 242 239 size_t index = 0; 243 240 size_t size = 0; 241 bool isVLA = true; 244 242 MemberIterator * memberIter = nullptr; 245 243 };
Note: See TracChangeset
for help on using the changeset viewer.