- Timestamp:
- Jun 23, 2026, 1:57:51 PM (27 hours ago)
- Branches:
- master
- Children:
- 9d7a19f
- Parents:
- 45d0e65
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r45d0e65 r366f5cd 11 11 // Last Modified By : Peter A. Buhr 12 12 // Created On : Wed May 18 13:56:00 2022 13 // Update Count : 1 213 // Update Count : 18 14 14 // 15 15 … … 46 46 // --- ApplicationExpr 47 47 48 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, 49 std::vector<ptr<Expr>> && as ) 50 : Expr( loc ), func( f ), args( std::move(as) ) { 48 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as ) 49 : Expr( loc ), func( f ), args( std::move(as) ) { 51 50 // ensure that `ApplicationExpr` result type is `FuncExpr` 52 51 const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() ); … … 103 102 } 104 103 105 UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc, 106 const std::string & name, std::vector<ptr<Expr>> && args ) { 104 UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc, const std::string & name, std::vector<ptr<Expr>> && args ) { 107 105 return new UntypedExpr( loc, 108 106 new NameExpr( loc, name ), std::move( args ) ); … … 111 109 // --- VariableExpr 112 110 113 VariableExpr::VariableExpr( const CodeLocation & loc ) 114 : Expr( loc ), var( nullptr ) {} 115 116 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) 117 : Expr( loc ), var( v ) { 111 VariableExpr::VariableExpr( const CodeLocation & loc ) : Expr( loc ), var( nullptr ) {} 112 113 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) : Expr( loc ), var( v ) { 118 114 assert( var ); 119 115 assert( var->get_type() ); … … 130 126 } 131 127 132 VariableExpr * VariableExpr::functionPointer( 133 const CodeLocation & loc, const FunctionDecl * decl ) { 128 VariableExpr * VariableExpr::functionPointer( const CodeLocation & loc, const FunctionDecl * decl ) { 134 129 // wrap usually-determined result type in a pointer 135 130 VariableExpr * funcExpr = new VariableExpr{ loc, decl }; … … 178 173 } 179 174 180 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : 181 Expr( loc, addrExprType( loc, a ) ), arg( a ) 182 {} 175 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc, addrExprType( loc, a ) ), arg( a ) {} 183 176 184 177 // --- LabelAddressExpr … … 191 184 192 185 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g, CastKind kind ) 193 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ), kind( kind ) {}186 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ), kind( kind ) {} 194 187 195 188 bool CastExpr::get_lvalue() const { … … 213 206 214 207 MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg ) 215 : Expr( loc ), member( mem ), aggregate( agg ) {208 : Expr( loc ), member( mem ), aggregate( agg ) { 216 209 assert( member ); 217 210 assert( aggregate ); … … 249 242 250 243 ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) { 251 return new ConstantExpr{ 252 loc, new BasicType{ BasicKind::Bool }, b ? "1" : "0", (unsigned long long)b }; 244 return new ConstantExpr{ loc, new BasicType{ BasicKind::Bool }, b ? "1" : "0", (unsigned long long)b }; 253 245 } 254 246 255 247 ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) { 256 return new ConstantExpr{ 257 loc, new BasicType{ BasicKind::SignedInt }, std::to_string( i ), (unsigned long long)i }; 248 return new ConstantExpr{ loc, new BasicType{ BasicKind::SignedInt }, std::to_string( i ), (unsigned long long)i }; 258 249 } 259 250 260 251 ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) { 261 return new ConstantExpr{ 262 loc, new BasicType{ BasicKind::LongUnsignedInt }, std::to_string( i ), 263 (unsigned long long)i }; 252 return new ConstantExpr{ loc, new BasicType{ BasicKind::LongUnsignedInt }, std::to_string( i ), (unsigned long long)i }; 264 253 } 265 254 … … 274 263 275 264 ConstantExpr * ConstantExpr::null( const CodeLocation & loc, const Type * ptrType ) { 276 return new ConstantExpr{ 277 loc, ptrType ? ptrType : new PointerType{ new VoidType{} }, "0", (unsigned long long)0 }; 265 return new ConstantExpr{ loc, ptrType ? ptrType : new PointerType{ new VoidType{} }, "0", (unsigned long long)0 }; 278 266 } 279 267 280 268 // --- SizeofExpr 281 269 282 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type ) 283 : SizeofExpr( loc, type, nullptr ) {} 284 285 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type, const Type * result ) 286 : Expr( loc, result ), type( type ) {} 270 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type ) : SizeofExpr( loc, type, nullptr ) {} 271 272 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type, const Type * result ) : Expr( loc, result ), type( type ) {} 287 273 288 274 // --- AlignofExpr 289 275 290 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type ) 291 : AlignofExpr( loc, type, nullptr ) {} 292 293 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Type * result ) 294 : Expr( loc, result ), type( type ) {} 276 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Alignment kind ) : AlignofExpr( loc, type, nullptr, kind ) {} 277 278 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Type * result, const Alignment kind ) 279 : Expr( loc, result ), type( type ), kind( kind ) {} 295 280 296 281 // --- CountofExpr 297 282 298 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t ) 299 : Expr( loc ), type( t ) {} 283 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t ) : Expr( loc ), type( t ) {} 300 284 301 285 // --- OffsetofExpr 302 286 303 287 OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res ) 304 : Expr( loc, res ), type( ty ), member( mem ) {288 : Expr( loc, res ), type( ty ), member( mem ) { 305 289 assert( type ); 306 290 assert( member ); … … 309 293 // --- OffsetPackExpr 310 294 311 OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) 312 : Expr( loc ), type( ty ) { 295 OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) : Expr( loc ), type( ty ) { 313 296 assert( type ); 314 297 } … … 316 299 // --- LogicalExpr 317 300 318 LogicalExpr::LogicalExpr( 319 const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) 320 : Expr( loc, new BasicType{ BasicKind::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} 301 LogicalExpr::LogicalExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) 302 : Expr( loc, new BasicType{ BasicKind::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} 321 303 322 304 // --- CommaExpr … … 330 312 // --- ConstructorExpr 331 313 332 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) 333 : Expr( loc ), callExpr( call ) { 314 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) : Expr( loc ), callExpr( call ) { 334 315 // allow resolver to type a constructor used as an expression if it has the same type as its 335 316 // first argument … … 342 323 // --- CompoundLiteralExpr 343 324 344 CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ) 345 : Expr( loc ), init( i ) { 325 CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ) : Expr( loc ), init( i ) { 346 326 assert( t && i ); 347 327 result = t; … … 354 334 // --- TupleExpr 355 335 356 TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) 357 : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {} 336 TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {} 358 337 359 338 // --- TupleIndexExpr 360 339 361 TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ) 362 : Expr( loc ), tuple( t ), index( i ) { 340 TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ) : Expr( loc ), tuple( t ), index( i ) { 363 341 const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result.get() ); 364 342 assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested " … … 374 352 // --- TupleAssignExpr 375 353 376 TupleAssignExpr::TupleAssignExpr( 377 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 378 std::vector<ptr<ObjectDecl>> && tempDecls ) 379 : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() { 354 TupleAssignExpr::TupleAssignExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, std::vector<ptr<ObjectDecl>> && tempDecls ) 355 : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() { 380 356 // convert internally into a StmtExpr which contains the declarations and produces the tuple of 381 357 // the assignments … … 392 368 // --- StmtExpr 393 369 394 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) 395 : Expr( loc ), stmts( ss ) { computeResult(); } 370 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) : Expr( loc ), stmts( ss ) { computeResult(); } 396 371 397 372 void StmtExpr::computeResult() { … … 411 386 unsigned long long UniqueExpr::nextId = 0; 412 387 413 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) 414 : Expr( loc, e->result ), expr( e ), id( i ) { 388 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) : Expr( loc, e->result ), expr( e ), id( i ) { 415 389 assert( expr ); 416 390 if ( id == -1ull ) { -
src/AST/Expr.hpp
r45d0e65 r366f5cd 11 11 // Last Modified By : Peter A. Buhr 12 12 // Created On : Fri May 10 10:30:00 2019 13 // Update Count : 813 // Update Count : 24 14 14 // 15 15 … … 495 495 public: 496 496 ptr<Type> type; 497 498 AlignofExpr( const CodeLocation & loc, const Type * t ); 499 AlignofExpr( const CodeLocation & loc, const Type * t, const Type * r ); 497 enum Alignment { Alignof, __Alignof } kind; 498 499 AlignofExpr( const CodeLocation & loc, const Type * t, const Alignment kind ); 500 AlignofExpr( const CodeLocation & loc, const Type * t, const Type * r, const Alignment kind ); 500 501 501 502 const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
Note:
See TracChangeset
for help on using the changeset viewer.