Changeset 246c245 for src/AST/Expr.cpp
- Timestamp:
- May 16, 2019, 6:51:18 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8ff178d, d66e7b7
- Parents:
- 9b4f329 (diff), 6f8e87d (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/AST/Expr.cpp
r9b4f329 r246c245 32 32 // --- ApplicationExpr 33 33 34 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, 35 std::vector<ptr<Expr>> && as ) 36 : Expr( loc ), func( f ), args( std::move(a rgs) ) {34 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, 35 std::vector<ptr<Expr>> && as ) 36 : Expr( loc ), func( f ), args( std::move(as) ) { 37 37 // ensure that `ApplicationExpr` result type is `FuncExpr` 38 38 const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() ); … … 48 48 assert( arg ); 49 49 50 UntypedExpr * ret = new UntypedExpr{ 51 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 50 UntypedExpr * ret = new UntypedExpr{ 51 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 52 52 }; 53 53 if ( const Type * ty = arg->result ) { … … 59 59 ret->result = new ReferenceType{ base }; 60 60 } else { 61 // references have been removed, in which case dereference returns an lvalue of the 61 // references have been removed, in which case dereference returns an lvalue of the 62 62 // base type 63 63 ret->result.set_and_mutate( base )->set_lvalue( true ); … … 112 112 } else { 113 113 // taking address of non-lvalue, must be a reference, loses one layer of reference 114 if ( const ReferenceType * refType = 114 if ( const ReferenceType * refType = 115 115 dynamic_cast< const ReferenceType * >( arg->result.get() ) ) { 116 116 Type * res = addrType( refType->base ); … … 118 118 result = res; 119 119 } else { 120 SemanticError( loc, arg->result, 120 SemanticError( loc, arg->result, 121 121 "Attempt to take address of non-lvalue expression: " ); 122 122 } … … 128 128 129 129 // label address always has type `void*` 130 LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a ) 130 LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a ) 131 131 : Expr( loc, new PointerType{ new VoidType{} } ), arg( a ) {} 132 132 133 133 // --- CastExpr 134 134 135 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) 135 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) 136 136 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {} 137 137 … … 169 169 } 170 170 171 VariableExpr * VariableExpr::functionPointer( 171 VariableExpr * VariableExpr::functionPointer( 172 172 const CodeLocation & loc, const FunctionDecl * decl ) { 173 173 // wrap usually-determined result type in a pointer … … 202 202 203 203 ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) { 204 return new ConstantExpr{ 204 return new ConstantExpr{ 205 205 loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b }; 206 206 } 207 207 208 208 ConstantExpr * ConstantExpr::from_char( const CodeLocation & loc, char c ) { 209 return new ConstantExpr{ 209 return new ConstantExpr{ 210 210 loc, new BasicType{ BasicType::Char }, std::to_string( c ), (unsigned long long)c }; 211 211 } 212 212 213 213 ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) { 214 return new ConstantExpr{ 214 return new ConstantExpr{ 215 215 loc, new BasicType{ BasicType::SignedInt }, std::to_string( i ), (unsigned long long)i }; 216 216 } 217 217 218 218 ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) { 219 return new ConstantExpr{ 220 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), 219 return new ConstantExpr{ 220 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), 221 221 (unsigned long long)i }; 222 222 } … … 229 229 return new ConstantExpr{ 230 230 loc, 231 new ArrayType{ 231 new ArrayType{ 232 232 new BasicType{ BasicType::Char, CV::Const }, 233 233 ConstantExpr::from_int( loc, s.size() + 1 /* null terminator */ ), … … 258 258 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {} 259 259 260 // --- UntypedOffsetofExpr261 262 UntypedOffsetofExpr::UntypedOffsetofExpr(263 const CodeLocation & loc, const Type * ty, const std::string & mem )264 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), type( ty ), member( mem ) {265 assert( type );266 }267 268 260 // --- OffsetofExpr 269 261 … … 277 269 278 270 OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) 279 : Expr( loc, new ArrayType{ 280 new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim } 271 : Expr( loc, new ArrayType{ 272 new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim } 281 273 ), type( ty ) { 282 274 assert( type ); … … 285 277 // --- LogicalExpr 286 278 287 LogicalExpr::LogicalExpr( 279 LogicalExpr::LogicalExpr( 288 280 const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) 289 281 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
Note: See TracChangeset
for help on using the changeset viewer.