Changes in src/AST/Expr.cpp [c36298d:60aaa51d]
- File:
-
- 1 edited
-
src/AST/Expr.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
rc36298d r60aaa51d 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 15 17:00:00 2019 11 // Last Modified By : A ndrew Beach12 // Created On : Thr Jun 13 13:38:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Created On : Wed May 15 17:00:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 194 194 if ( const BasicType * bty = result.as< BasicType >() ) { 195 195 if ( bty->isInteger() ) { 196 assert(ival); 197 return ival.value(); 196 return val.ival; 198 197 } 199 198 } else if ( result.as< ZeroType >() ) { … … 205 204 } 206 205 206 double ConstantExpr::floatValue() const { 207 if ( const BasicType * bty = result.as< BasicType >() ) { 208 if ( ! bty->isInteger() ) { 209 return val.dval; 210 } 211 } 212 SemanticError( this, "Constant expression of non-floating-point type " ); 213 } 214 207 215 ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) { 208 216 return new ConstantExpr{ 209 217 loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b }; 218 } 219 220 ConstantExpr * ConstantExpr::from_char( const CodeLocation & loc, char c ) { 221 return new ConstantExpr{ 222 loc, new BasicType{ BasicType::Char }, std::to_string( c ), (unsigned long long)c }; 210 223 } 211 224 … … 219 232 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), 220 233 (unsigned long long)i }; 234 } 235 236 ConstantExpr * ConstantExpr::from_double( const CodeLocation & loc, double d ) { 237 return new ConstantExpr{ loc, new BasicType{ BasicType::Double }, std::to_string( d ), d }; 238 } 239 240 ConstantExpr * ConstantExpr::from_string( const CodeLocation & loc, const std::string & s ) { 241 return new ConstantExpr{ 242 loc, 243 new ArrayType{ 244 new BasicType{ BasicType::Char, CV::Const }, 245 ConstantExpr::from_int( loc, s.size() + 1 /* null terminator */ ), 246 FixedLen, DynamicDim }, 247 std::string{"\""} + s + "\"", 248 (unsigned long long)0, 249 ConstantExpr::String }; 221 250 } 222 251 … … 353 382 354 383 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) 355 : Expr( loc, e->result ), expr( e ),id( i ) {384 : Expr( loc, e->result ), id( i ) { 356 385 assert( expr ); 357 386 if ( id == -1ull ) {
Note:
See TracChangeset
for help on using the changeset viewer.