Changeset 4b97770
- Timestamp:
- Jan 3, 2018, 10:40:02 AM (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:
- 6138d0f, b834e98
- Parents:
- be9aa0f
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
rbe9aa0f r4b97770 125 125 base = at->get_base(); 126 126 memberIter = createMemberIterator( base ); 127 if ( at->isVarLen ) throw SemanticError( "VLA initialization does not support @=", at ); 127 128 setSize( at->get_dimension() ); 128 129 } … … 135 136 void setSize( Expression * expr ) { 136 137 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 137 size = constExpr->intValue(); 138 isVLA = false; 139 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 138 try { 139 size = constExpr->intValue(); 140 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 141 } catch ( SemanticError & ) { 142 throw SemanticError( "Constant expression of non-integral type in array dimension: ", expr ); 143 } 140 144 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 141 145 setSize( castExpr->get_arg() ); // xxx - need to perform the conversion specified by the cast … … 145 149 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 146 150 size = value; 147 isVLA = false;148 151 } 149 152 } … … 157 160 // need to permit integer-constant-expressions, including: integer constants, enumeration constants, character constants, sizeof expressions, _Alignof expressions, cast expressions 158 161 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 159 index = constExpr->intValue(); 162 try { 163 index = constExpr->intValue(); 164 } catch( SemanticError & ) { 165 throw SemanticError( "Constant expression of non-integral type in array designator: ", expr ); 166 } 160 167 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 161 168 setPosition( castExpr->get_arg() ); … … 186 193 } 187 194 188 virtual operator bool() const { return ! isVLA &&index < size; }195 virtual operator bool() const { return index < size; } 189 196 190 197 virtual MemberIterator & bigStep() { … … 192 199 ++index; 193 200 delete memberIter; 194 if ( ! isVLA &&index < size ) memberIter = createMemberIterator( base );201 if ( index < size ) memberIter = createMemberIterator( base ); 195 202 else memberIter = nullptr; 196 203 return *this; … … 239 246 size_t index = 0; 240 247 size_t size = 0; 241 bool isVLA = true;242 248 MemberIterator * memberIter = nullptr; 243 249 }; -
src/SymTab/Validate.cc
rbe9aa0f r4b97770 754 754 throw SemanticError( "Cannot redefine typedef: " + tyDecl->name ); 755 755 } 756 // cannot redefine VLA typedefs 756 // Cannot redefine VLA typedefs. Note: this is slightly incorrect, because our notion of VLAs 757 // at this point in the translator is imprecise. In particular, this will disallow redefining typedefs 758 // with arrays whose dimension is an enumerator or a cast of a constant/enumerator. The effort required 759 // to fix this corner case likely outweighs the utility of allowing it. 757 760 if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) { 758 761 throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
Note: See TracChangeset
for help on using the changeset viewer.