- Timestamp:
- Feb 5, 2025, 1:45:29 PM (8 weeks ago)
- Branches:
- master
- Children:
- ab94c37
- Parents:
- 92aeae1
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/Expr.cpp ¶
r92aeae1 rd3d54b3 26 26 #include "Stmt.hpp" 27 27 #include "Type.hpp" 28 #include "Util.hpp" // for TranslationDeps 28 29 #include "TypeSubstitution.hpp" 29 30 #include "Common/Utility.hpp" … … 281 282 282 283 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t ) 283 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt }), type( t ) {}284 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {} 284 285 285 286 // --- AlignofExpr 286 287 287 288 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t ) 288 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt }), type( t ) {}289 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {} 289 290 290 291 // --- CountofExpr 291 292 292 293 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t ) 293 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {}294 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {} 294 295 295 296 // --- OffsetofExpr 296 297 297 298 OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem ) 298 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt }), type( ty ), member( mem ) {299 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( ty ), member( mem ) { 299 300 assert( type ); 300 301 assert( member ); … … 305 306 OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) 306 307 : Expr( loc, new ArrayType{ 307 new BasicType{ BasicKind::LongUnsignedInt }, nullptr, FixedLen, DynamicDim }308 ast::TranslationDeps::getSizeType(), nullptr, FixedLen, DynamicDim } 308 309 ), type( ty ) { 309 310 assert( type ); -
TabularUnified src/AST/Type.hpp ¶
r92aeae1 rd3d54b3 344 344 struct TypeEnvKey; 345 345 346 /// instance of named type alias (typedef or variable)346 /// instance of named type alias (typedef, variable, or even, just after parsing, the name of a struct) 347 347 class TypeInstType final : public BaseInstType { 348 348 public: -
TabularUnified src/AST/Util.cpp ¶
r92aeae1 rd3d54b3 22 22 #include "Common/Utility.hpp" 23 23 #include "GenPoly/ScopedSet.hpp" 24 #include "Decl.hpp" 25 #include "Type.hpp" 24 26 25 27 #include <vector> … … 382 384 } 383 385 386 namespace { 387 const TranslationUnit * transUnit = 0; 388 } 389 390 void TranslationDeps::evolve( TranslationUnit & u ) { 391 transUnit = &u; 392 } 393 394 const ast::Type * TranslationDeps::getSizeType() { 395 static const ast::Type * zd_abstract = new TypeInstType{ "size_t", TypeDecl::Kind::Dtype }; 396 static const ast::Type * ld_concrete = new BasicType( BasicKind::LongUnsignedInt ); 397 if ( ! transUnit ) { 398 // early state 399 // as if `size_t` in program text were freshly parsed 400 return zd_abstract; 401 } else if ( transUnit->global.sizeType ) { 402 // late state, normal run 403 // whatever size_t was defined as 404 return transUnit->global.sizeType; 405 } else { 406 // late state, no prelude (-n) 407 // placeholder: cfa-cpp is being used experimentally, stay out of the way 408 return ld_concrete; 409 } 410 } 411 412 384 413 } // namespace ast -
TabularUnified src/AST/Util.hpp ¶
r92aeae1 rd3d54b3 16 16 #pragma once 17 17 18 #include "Fwd.hpp" 19 18 20 namespace ast { 19 21 … … 22 24 /// Check anything that should always be true of the AST between passes. 23 25 /// Insert this whenever you want additional debugging checks. 24 void checkInvariants( TranslationUnit & transUnit ); 26 void checkInvariants( TranslationUnit & ); 27 28 /// Maintains an AST-module state for contextual information needed in 29 /// ast::* implementations, notably constructors: 30 /// early: while parsing, use bootstrap versions 31 /// late: once a whole TranslationUnit exists, use its answers 32 /// When the program is in the later state, ast::* construcors effectively get 33 /// the benefit of WithTranslationUnit, without having to pass them one. 34 class TranslationDeps { 35 36 TranslationDeps() = delete; 37 38 friend class SizeofExpr; 39 friend class AlignofExpr; 40 friend class CountofExpr; 41 friend class OffsetofExpr; 42 friend class OffsetPackExpr; 43 44 /// Appropriate return type for built-in expressions that report on sizes 45 static const Type * getSizeType(); 46 47 public: 48 /// Transition from early to late states 49 static void evolve( TranslationUnit & ); 50 }; 25 51 26 52 } -
TabularUnified src/main.cpp ¶
r92aeae1 rd3d54b3 199 199 Stats::Time::StopBlock(); 200 200 201 ast::TranslationDeps::evolve( transUnit ); 202 201 203 PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit ); 202 204
Note: See TracChangeset
for help on using the changeset viewer.