Changeset 2e9b59b for src/Common
- Timestamp:
- Apr 19, 2022, 3:00:04 PM (4 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 5b84a321
- Parents:
- ba897d21 (diff), bb7c77d (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. - Location:
- src/Common
- Files:
-
- 6 edited
-
CodeLocationTools.cpp (modified) (5 diffs)
-
CodeLocationTools.hpp (modified) (2 diffs)
-
Eval.cc (modified) (1 diff)
-
Examine.cc (modified) (4 diffs)
-
Examine.h (modified) (1 diff)
-
PassVisitor.impl.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/CodeLocationTools.cpp
rba897d21 r2e9b59b 9 9 // Author : Andrew Beach 10 10 // Created On : Fri Dec 4 15:42:00 2020 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Feb 1 09:14:39202213 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 14 15:14:00 2022 13 // Update Count : 4 14 14 // 15 15 … … 112 112 macro(ForStmt, Stmt) \ 113 113 macro(SwitchStmt, Stmt) \ 114 macro(Case Stmt, Stmt) \114 macro(CaseClause, CaseClause) \ 115 115 macro(BranchStmt, Stmt) \ 116 116 macro(ReturnStmt, Stmt) \ 117 117 macro(ThrowStmt, Stmt) \ 118 118 macro(TryStmt, Stmt) \ 119 macro(Catch Stmt, Stmt) \120 macro(Finally Stmt, Stmt) \119 macro(CatchClause, CatchClause) \ 120 macro(FinallyClause, FinallyClause) \ 121 121 macro(SuspendStmt, Stmt) \ 122 122 macro(WaitForStmt, Stmt) \ … … 147 147 macro(CommaExpr, Expr) \ 148 148 macro(TypeExpr, Expr) \ 149 macro(DimensionExpr, Expr) \ 149 150 macro(AsmExpr, Expr) \ 150 151 macro(ImplicitCopyCtorExpr, Expr) \ … … 239 240 }; 240 241 242 class LocalFillCore : public ast::WithGuards { 243 CodeLocation const * parent; 244 public: 245 LocalFillCore( CodeLocation const & location ) : parent( &location ) { 246 assert( location.isSet() ); 247 } 248 249 template<typename node_t> 250 auto previsit( node_t const * node ) 251 -> typename std::enable_if<has_code_location<node_t>::value, node_t const *>::type { 252 if ( node->location.isSet() ) { 253 GuardValue( parent ) = &node->location; 254 return node; 255 } else { 256 node_t * mut = ast::mutate( node ); 257 mut->location = *parent; 258 return mut; 259 } 260 } 261 }; 262 241 263 } // namespace 242 264 … … 278 300 ast::Pass<FillCore>::run( unit ); 279 301 } 302 303 ast::Node const * localFillCodeLocations( 304 CodeLocation const & location , ast::Node const * node ) { 305 ast::Pass<LocalFillCore> visitor( location ); 306 return node->accept( visitor ); 307 } -
src/Common/CodeLocationTools.hpp
rba897d21 r2e9b59b 10 10 // Created On : Fri Dec 4 15:35:00 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Dec 9 9:53:00 202013 // Update Count : 112 // Last Modified On : Mon Mar 14 15:14:00 2022 13 // Update Count : 2 14 14 // 15 15 16 16 #pragma once 17 17 18 struct CodeLocation; 18 19 namespace ast { 20 class Node; 19 21 class TranslationUnit; 20 22 } … … 28 30 // Assign a nearby code-location to any unset code locations in the forest. 29 31 void forceFillCodeLocations( ast::TranslationUnit & unit ); 32 33 // Fill in code-locations with a parent code location, 34 // using the provided CodeLocation as the base. 35 ast::Node const * 36 localFillCodeLocations( CodeLocation const &, ast::Node const * ); -
src/Common/Eval.cc
rba897d21 r2e9b59b 112 112 } 113 113 114 void postvisit( const ast::VariableExpr * expr ) { 114 void postvisit( const ast::VariableExpr * expr ) { // No hit 115 115 if ( const ast::EnumInstType * inst = dynamic_cast<const ast::EnumInstType *>(expr->result.get()) ) { 116 116 if ( const ast::EnumDecl * decl = inst->base ) { -
src/Common/Examine.cc
rba897d21 r2e9b59b 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Examine. h --7 // Examine.cc -- Helpers for examining AST code. 8 8 // 9 9 // Author : Andrew Beach 10 10 // Created On : Wed Sept 2 14:02 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Sep 8 12:15 202013 // Update Count : 012 // Last Modified On : Fri Dec 10 10:27 2021 13 // Update Count : 1 14 14 // 15 15 16 16 #include "Common/Examine.h" 17 17 18 #include "AST/Type.hpp" 18 19 #include "CodeGen/OperatorTable.h" 20 #include "InitTweak/InitTweak.h" 19 21 20 22 DeclarationWithType * isMainFor( FunctionDecl * func, AggregateDecl::Aggregate kind ) { … … 36 38 37 39 namespace { 40 41 // getTypeofThis but does some extra checks used in this module. 42 const ast::Type * getTypeofThisSolo( const ast::FunctionDecl * func ) { 43 if ( 1 != func->params.size() ) { 44 return nullptr; 45 } 46 auto ref = func->type->params.front().as<ast::ReferenceType>(); 47 return (ref) ? ref->base : nullptr; 48 } 49 50 } 51 52 const ast::DeclWithType * isMainFor( 53 const ast::FunctionDecl * func, ast::AggregateDecl::Aggregate kind ) { 54 if ( "main" != func->name ) return nullptr; 55 if ( 1 != func->params.size() ) return nullptr; 56 57 auto param = func->params.front(); 58 59 auto type = dynamic_cast<const ast::ReferenceType *>( param->get_type() ); 60 if ( !type ) return nullptr; 61 62 auto obj = type->base.as<ast::StructInstType>(); 63 if ( !obj ) return nullptr; 64 65 if ( kind != obj->base->kind ) return nullptr; 66 67 return param; 68 } 69 70 namespace { 38 71 Type * getDestructorParam( FunctionDecl * func ) { 39 72 if ( !CodeGen::isDestructor( func->name ) ) return nullptr; … … 48 81 return nullptr; 49 82 } 83 84 const ast::Type * getDestructorParam( const ast::FunctionDecl * func ) { 85 if ( !CodeGen::isDestructor( func->name ) ) return nullptr; 86 //return InitTweak::getParamThis( func )->type; 87 return getTypeofThisSolo( func ); 88 } 89 50 90 } 51 91 … … 57 97 return false; 58 98 } 99 100 bool isDestructorFor( 101 const ast::FunctionDecl * func, const ast::StructDecl * type_decl ) { 102 if ( const ast::Type * type = getDestructorParam( func ) ) { 103 auto stype = dynamic_cast<const ast::StructInstType *>( type ); 104 return stype && stype->base.get() == type_decl; 105 } 106 return false; 107 } -
src/Common/Examine.h
rba897d21 r2e9b59b 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Examine.h -- 7 // Examine.h -- Helpers for examining AST code. 8 8 // 9 9 // Author : Andrew Beach 10 10 // Created On : Wed Sept 2 13:57 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Sep 8 12:08 202013 // Update Count : 012 // Last Modified On : Fri Dec 10 10:28 2021 13 // Update Count : 1 14 14 // 15 15 16 #include "AST/Decl.hpp" 16 17 #include "SynTree/Declaration.h" 17 18 18 19 /// Check if this is a main function for a type of an aggregate kind. 19 20 DeclarationWithType * isMainFor( FunctionDecl * func, AggregateDecl::Aggregate kind ); 21 const ast::DeclWithType * isMainFor( 22 const ast::FunctionDecl * func, ast::AggregateDecl::Aggregate kind ); 20 23 // Returns a pointer to the parameter if true, nullptr otherwise. 21 24 22 25 /// Check if this function is a destructor for the given structure. 23 26 bool isDestructorFor( FunctionDecl * func, StructDecl * type_decl ); 27 bool isDestructorFor( 28 const ast::FunctionDecl * func, const ast::StructDecl * type ); -
src/Common/PassVisitor.impl.h
rba897d21 r2e9b59b 754 754 755 755 // unlike structs, traits, and unions, enums inject their members into the global scope 756 // if ( node->base ) maybeAccept_impl( node->base, *this ); // Need this? Maybe not? 756 757 maybeAccept_impl( node->parameters, *this ); 757 758 maybeAccept_impl( node->members , *this );
Note:
See TracChangeset
for help on using the changeset viewer.