Changes in / [d908563:933f32f]
- Files:
-
- 5 deleted
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/vtable.md
rd908563 r933f32f 220 220 trait iterator(otype T, otype Item) { 221 221 bool has_next(T const &); 222 Item get_next(T &);222 Item get_next(T const *); 223 223 } 224 224 -
libcfa/src/iostream.cfa
rd908563 r933f32f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 21 13:01:26201913 // Update Count : 6 7412 // Last Modified On : Sun May 19 10:48:27 2019 13 // Update Count : 654 14 14 // 15 15 … … 154 154 } // ?|? 155 155 156 #define PrintWithDP( os, format, val, ... ) \ 157 { \ 158 enum { size = 48 }; \ 159 char buf[size]; \ 160 int len = snprintf( buf, size, format, ##__VA_ARGS__, val ); \ 161 fmt( os, "%s", buf ); \ 162 if ( isfinite( val ) ) { /* if number, always print decimal point */ \ 163 for ( int i = 0;; i += 1 ) { \ 164 if ( i == len ) { fmt( os, "." ); break; } \ 165 if ( buf[i] == '.' ) break; \ 166 } /* for */ \ 167 } /* if */ \ 168 } 156 static void checkDecPt( ostype & os, const char * buf, int len ) { 157 for ( int i = 0;; i += 1 ) { 158 if ( i == len ) { fmt( os, "." ); break; } 159 if ( buf[i] == '.' ) break; 160 } // for 161 } // checkDecPt 169 162 170 163 ostype & ?|?( ostype & os, float f ) { 171 164 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 172 PrintWithDP( os, "%g", f ); 165 char buf[48]; 166 int len = snprintf( buf, 48, "%g", f ); 167 fmt( os, "%s", buf ); 168 if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point 173 169 return os; 174 170 } // ?|? … … 179 175 ostype & ?|?( ostype & os, double d ) { 180 176 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 181 PrintWithDP( os, "%.*lg", d, DBL_DIG ); 177 char buf[48]; 178 int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d ); 179 fmt( os, "%s", buf ); 180 if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point 182 181 return os; 183 182 } // ?|? … … 188 187 ostype & ?|?( ostype & os, long double ld ) { 189 188 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 190 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG ); 189 char buf[48]; 190 int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld ); 191 fmt( os, "%s", buf ); 192 if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point 191 193 return os; 192 194 } // ?|? … … 199 201 // os | crealf( fc ) | nonl; 200 202 float f = crealf( fc ); 201 PrintWithDP( os, "%g", f ); 203 char buf[48]; 204 int len = snprintf( buf, 48, "%g", f ); 205 fmt( os, "%s", buf ); 206 if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point 202 207 f = cimagf( fc ); 203 PrintWithDP( os, "%+g", f ); 208 len = snprintf( buf, 48, "%+g", f ); 209 fmt( os, "%s", buf ); 210 if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point 204 211 fmt( os, "i" ); 205 212 return os; … … 213 220 // os | creal( dc ) | nonl; 214 221 double d = creal( dc ); 215 PrintWithDP( os, "%.*lg", d, DBL_DIG ); 222 char buf[48]; 223 int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d ); 224 fmt( os, "%s", buf ); 225 if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point 216 226 d = cimag( dc ); 217 PrintWithDP( os, "%+.*lg", d, DBL_DIG ); 227 len = snprintf( buf, 48, "%+.*lg", DBL_DIG, d ); 228 fmt( os, "%s", buf ); 229 if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point 218 230 fmt( os, "i" ); 219 231 return os; … … 227 239 // os | creall( ldc ) || nonl; 228 240 long double ld = creall( ldc ); 229 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG ); 241 char buf[48]; 242 int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld ); 243 fmt( os, "%s", buf ); 244 if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point 230 245 ld = cimagl( ldc ); 231 PrintWithDP( os, "%+.*Lg", ld, LDBL_DIG ); 246 len = snprintf( buf, 48, "%+.*Lg", LDBL_DIG, ld ); 247 fmt( os, "%s", buf ); 248 if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point 232 249 fmt( os, "i" ); 233 250 return os; -
src/AST/Attribute.cpp
rd908563 r933f32f 28 28 auto end = name.find_last_not_of('_'); 29 29 if ( begin == std::string::npos || end == std::string::npos ) return ""; 30 30 31 31 // convert to lowercase 32 32 std::string ret; -
src/AST/Attribute.hpp
rd908563 r933f32f 30 30 public: 31 31 std::string name; 32 std::vector<ptr<Expr>> param s;32 std::vector<ptr<Expr>> parameters; 33 33 34 34 Attribute( const std::string & name = "", std::vector<ptr<Expr>> && params = {}) 35 : name( name ), param s( params ) {}35 : name( name ), parameters( params ) {} 36 36 virtual ~Attribute() = default; 37 37 -
src/AST/Bitfield.hpp
rd908563 r933f32f 57 57 }; 58 58 59 template<typename T> 60 inline bool operator== ( const bitfield<T> & a, const bitfield<T> & b ) { 61 return a.val == b.val; 62 } 63 64 template<typename T> 65 inline bool operator!= ( const bitfield<T> & a, const bitfield<T> & b ) { 66 return !(a == b); 67 } 59 /// Adds default printing operator to a bitfield type. 60 /// Include in definition to add print function, requires other bitfield operators. 61 /// @param N Number of bits in bitfield 62 #define MakeBitfieldPrint( N ) \ 63 static const char* Names[]; \ 64 \ 65 void print( std::ostream & os ) const { \ 66 if ( (*this).any() ) { \ 67 for ( unsigned int i = 0; i < N; i += 1 ) { \ 68 if ( (*this)[i] ) { \ 69 os << Names[i] << ' '; \ 70 } \ 71 } \ 72 } \ 73 } 68 74 69 75 // Local Variables: // -
src/AST/Convert.cpp
rd908563 r933f32f 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu May 23 16:59:00 201913 // Update Count : 612 // Last Modified On : Fri May 17 16:01:00 2019 13 // Update Count : 4 14 14 // 15 15 16 16 #include "Convert.hpp" 17 18 #include <unordered_map>19 17 20 18 #include "AST/Attribute.hpp" … … 44 42 class ConverterNewToOld : public ast::Visitor { 45 43 BaseSyntaxNode * node = nullptr; 46 using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;47 Cache cache;48 44 49 45 template<typename T> … … 51 47 ConverterNewToOld & visitor; 52 48 53 template<typename U, enum ast::Node::ref_type R> 54 T * accept1( const ast::ptr_base<U, R> & ptr ) { 55 if ( ! ptr ) return nullptr; 49 template<typename U> 50 T * accept1( const ast::ptr<U> & ptr ) { 56 51 ptr->accept( visitor ); 57 52 T * ret = strict_dynamic_cast< T * >( visitor.node ); … … 92 87 } 93 88 94 /// get new qualifiers from old type95 Type::Qualifiers cv( const ast::Type * ty ) { return { ty->qualifiers.val }; }96 97 /// returns true and sets `node` if in cache98 bool inCache( const ast::Node * node ) {99 auto it = cache.find( node );100 if ( it == cache.end() ) return false;101 this->node = it->second;102 return true;103 }104 105 89 public: 106 90 Declaration * decl( const ast::Decl * declNode ) { … … 109 93 110 94 private: 111 void declPostamble( Declaration * decl, const ast::Decl * node ) {112 decl->location = node->location;113 // name comes from constructor114 // linkage comes from constructor115 decl->extension = node->extension;116 decl->uniqueId = node->uniqueId;117 // storageClasses comes from constructor118 this->node = decl;119 }120 121 const ast::DeclWithType * declWithTypePostamble (122 DeclarationWithType * decl, const ast::DeclWithType * node ) {123 cache.emplace( node, decl );124 decl->mangleName = node->mangleName;125 decl->scopeLevel = node->scopeLevel;126 decl->asmName = get<Expression>().accept1( node->asmName );127 // attributes comes from constructor128 decl->isDeleted = node->isDeleted;129 // fs comes from constructor130 declPostamble( decl, node );131 return nullptr;132 }133 134 95 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 135 if ( inCache( node ) ) return nullptr; 136 auto decl = new ObjectDecl( 137 node->name, 138 Type::StorageClasses( node->storage.val ), 139 LinkageSpec::Spec( node->linkage.val ), 140 get<Expression>().accept1( node->bitfieldWidth ), 141 get<Type>().accept1( node->type ), 142 get<Initializer>().accept1( node->init ), 143 get<Attribute>().acceptL( node->attributes ), 144 Type::FuncSpecifiers( node->funcSpec.val ) 145 ); 146 return declWithTypePostamble( decl, node ); 96 (void)node; 97 return nullptr; 147 98 } 148 99 149 100 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 150 if ( inCache( node ) ) return nullptr; 151 auto decl = new FunctionDecl( 152 node->name, 153 Type::StorageClasses( node->storage.val ), 154 LinkageSpec::Spec( node->linkage.val ), 155 get<FunctionType>().accept1( node->type ), 156 get<CompoundStmt>().accept1( node->stmts ), 157 get<Attribute>().acceptL( node->attributes ), 158 Type::FuncSpecifiers( node->funcSpec.val ) 159 ); 160 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 161 return declWithTypePostamble( decl, node ); 162 } 163 164 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 165 // base comes from constructor 166 decl->parameters = get<TypeDecl>().acceptL( node->params ); 167 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 168 declPostamble( decl, node ); 101 (void)node; 102 return nullptr; 103 } 104 105 const ast::Decl * visit( const ast::StructDecl * node ) override final { 106 (void)node; 107 return nullptr; 108 } 109 110 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 111 (void)node; 112 return nullptr; 113 } 114 115 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 116 (void)node; 117 return nullptr; 118 } 119 120 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 121 (void)node; 169 122 return nullptr; 170 123 } 171 124 172 125 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 173 if ( inCache( node ) ) return nullptr; 174 auto decl = new TypeDecl( 175 node->name, 176 Type::StorageClasses( node->storage.val ), 177 get<Type>().accept1( node->base ), 178 (TypeDecl::Kind)(unsigned)node->kind, 179 node->sized, 180 get<Type>().accept1( node->init ) 181 ); 182 cache.emplace( node, decl ); 183 return namedTypePostamble( decl, node ); 126 (void)node; 127 return nullptr; 184 128 } 185 129 186 130 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 187 auto decl = new TypedefDecl( 188 node->name, 189 node->location, 190 Type::StorageClasses( node->storage.val ), 191 get<Type>().accept1( node->base ), 192 LinkageSpec::Spec( node->linkage.val ) 193 ); 194 return namedTypePostamble( decl, node ); 195 } 196 197 const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) { 198 cache.emplace( node, decl ); 199 decl->members = get<Declaration>().acceptL( node->members ); 200 decl->parameters = get<TypeDecl>().acceptL( node->params ); 201 decl->body = node->body; 202 // attributes come from constructor 203 decl->parent = get<AggregateDecl>().accept1( node->parent ); 204 declPostamble( decl, node ); 205 return nullptr; 206 } 207 208 const ast::Decl * visit( const ast::StructDecl * node ) override final { 209 if ( inCache( node ) ) return nullptr; 210 auto decl = new StructDecl( 211 node->name, 212 node->kind, 213 get<Attribute>().acceptL( node->attributes ), 214 LinkageSpec::Spec( node->linkage.val ) 215 ); 216 return aggregatePostamble( decl, node ); 217 } 218 219 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 220 if ( inCache( node ) ) return nullptr; 221 auto decl = new UnionDecl( 222 node->name, 223 get<Attribute>().acceptL( node->attributes ), 224 LinkageSpec::Spec( node->linkage.val ) 225 ); 226 return aggregatePostamble( decl, node ); 227 } 228 229 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 230 if ( inCache( node ) ) return nullptr; 231 auto decl = new EnumDecl( 232 node->name, 233 get<Attribute>().acceptL( node->attributes ), 234 LinkageSpec::Spec( node->linkage.val ) 235 ); 236 return aggregatePostamble( decl, node ); 237 } 238 239 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 240 if ( inCache( node ) ) return nullptr; 241 auto decl = new TraitDecl( 242 node->name, 243 {}, 244 LinkageSpec::Spec( node->linkage.val ) 245 ); 246 return aggregatePostamble( decl, node ); 131 (void)node; 132 return nullptr; 247 133 } 248 134 249 135 const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 250 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); 251 declPostamble( decl, node ); 136 (void)node; 252 137 return nullptr; 253 138 } 254 139 255 140 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 256 auto decl = new StaticAssertDecl( 257 get<Expression>().accept1( node->cond ), 258 get<ConstantExpr>().accept1( node->msg ) 259 ); 260 declPostamble( decl, node ); 261 return nullptr; 262 } 263 264 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 265 cache.emplace( node, stmt ); 266 stmt->location = node->location; 267 stmt->labels = makeLabelL( stmt, node->labels ); 268 this->node = stmt; 141 (void)node; 269 142 return nullptr; 270 143 } 271 144 272 145 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 273 if ( inCache( node ) ) return nullptr;274 146 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 275 stmtPostamble( stmt, node ); 147 stmt->location = node->location; 148 stmt->labels = makeLabelL( stmt, node->labels ); 149 this->node = stmt; 276 150 return nullptr; 277 151 } 278 152 279 153 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 280 if ( inCache( node ) ) return nullptr;281 auto stmt = new ExprStmt( nullptr );282 cache.emplace( node, stmt);283 stmt->expr = get<Expression>().accept1( node->expr );284 return stmtPostamble( stmt, node );154 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 155 stmt->location = node->location; 156 stmt->labels = makeLabelL( stmt, node->labels ); 157 this->node = stmt; 158 return nullptr; 285 159 } 286 160 287 161 const ast::Stmt * visit( const ast::AsmStmt * node ) override final { 288 if ( inCache( node ) ) return nullptr;289 162 auto stmt = new AsmStmt( 290 163 node->isVolatile, … … 295 168 makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? 296 169 ); 297 return stmtPostamble( stmt, node ); 170 stmt->location = node->location; 171 stmt->labels = makeLabelL( stmt, node->labels ); 172 this->node = stmt; 173 return nullptr; 298 174 } 299 175 300 176 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 301 if ( inCache( node ) ) return nullptr;302 177 auto stmt = new DirectiveStmt( node->directive ); 303 return stmtPostamble( stmt, node ); 178 stmt->location = node->location; 179 stmt->labels = makeLabelL( stmt, node->labels ); 180 this->node = stmt; 181 return nullptr; 304 182 } 305 183 306 184 const ast::Stmt * visit( const ast::IfStmt * node ) override final { 307 if ( inCache( node ) ) return nullptr;308 185 auto stmt = new IfStmt( 309 186 get<Expression>().accept1( node->cond ), … … 312 189 get<Statement>().acceptL( node->inits ) 313 190 ); 314 return stmtPostamble( stmt, node ); 191 stmt->location = node->location; 192 stmt->labels = makeLabelL( stmt, node->labels ); 193 this->node = stmt; 194 return nullptr; 315 195 } 316 196 317 197 const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 318 if ( inCache( node ) ) return nullptr;319 198 auto stmt = new SwitchStmt( 320 199 get<Expression>().accept1( node->cond ), 321 200 get<Statement>().acceptL( node->stmts ) 322 201 ); 323 return stmtPostamble( stmt, node ); 202 stmt->location = node->location; 203 stmt->labels = makeLabelL( stmt, node->labels ); 204 this->node = stmt; 205 return nullptr; 324 206 } 325 207 326 208 const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 327 if ( inCache( node ) ) return nullptr;328 209 auto stmt = new CaseStmt( 329 210 get<Expression>().accept1( node->cond ), … … 331 212 node->isDefault() 332 213 ); 333 return stmtPostamble( stmt, node ); 214 stmt->location = node->location; 215 stmt->labels = makeLabelL( stmt, node->labels ); 216 this->node = stmt; 217 return nullptr; 334 218 } 335 219 336 220 const ast::Stmt * visit( const ast::WhileStmt * node ) override final { 337 if ( inCache( node ) ) return nullptr;338 221 auto inits = get<Statement>().acceptL( node->inits ); 339 222 auto stmt = new WhileStmt( … … 343 226 node->isDoWhile 344 227 ); 345 return stmtPostamble( stmt, node ); 228 stmt->location = node->location; 229 stmt->labels = makeLabelL( stmt, node->labels ); 230 this->node = stmt; 231 return nullptr; 346 232 } 347 233 348 234 const ast::Stmt * visit( const ast::ForStmt * node ) override final { 349 if ( inCache( node ) ) return nullptr;350 235 auto stmt = new ForStmt( 351 236 get<Statement>().acceptL( node->inits ), … … 354 239 get<Statement>().accept1( node->body ) 355 240 ); 356 return stmtPostamble( stmt, node ); 241 stmt->location = node->location; 242 stmt->labels = makeLabelL( stmt, node->labels ); 243 this->node = stmt; 244 return nullptr; 357 245 } 358 246 359 247 const ast::Stmt * visit( const ast::BranchStmt * node ) override final { 360 if ( inCache( node ) ) return nullptr;361 248 BranchStmt * stmt; 362 249 if (node->computedTarget) { … … 384 271 stmt->target = makeLabel( stmt, node->target ); 385 272 } 386 return stmtPostamble( stmt, node ); 273 stmt->location = node->location; 274 stmt->labels = makeLabelL( stmt, node->labels ); 275 this->node = stmt; 276 return nullptr; 387 277 } 388 278 389 279 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 390 if ( inCache( node ) ) return nullptr;391 280 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 392 return stmtPostamble( stmt, node ); 281 stmt->location = node->location; 282 stmt->labels = makeLabelL( stmt, node->labels ); 283 this->node = stmt; 284 return nullptr; 393 285 } 394 286 395 287 const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { 396 if ( inCache( node ) ) return nullptr;397 288 ThrowStmt::Kind kind; 398 289 switch (node->kind) { … … 411 302 get<Expression>().accept1( node->target ) 412 303 ); 413 return stmtPostamble( stmt, node ); 304 stmt->location = node->location; 305 stmt->labels = makeLabelL( stmt, node->labels ); 306 this->node = stmt; 307 return nullptr; 414 308 } 415 309 416 310 const ast::Stmt * visit( const ast::TryStmt * node ) override final { 417 if ( inCache( node ) ) return nullptr;418 311 auto handlers = get<CatchStmt>().acceptL( node->handlers ); 419 312 auto stmt = new TryStmt( … … 422 315 get<FinallyStmt>().accept1( node->finally ) 423 316 ); 424 return stmtPostamble( stmt, node ); 317 stmt->location = node->location; 318 stmt->labels = makeLabelL( stmt, node->labels ); 319 this->node = stmt; 320 return nullptr; 425 321 } 426 322 427 323 const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 428 if ( inCache( node ) ) return nullptr;429 324 CatchStmt::Kind kind; 430 325 switch (node->kind) { … … 444 339 get<Statement>().accept1( node->body ) 445 340 ); 446 return stmtPostamble( stmt, node ); 341 stmt->location = node->location; 342 stmt->labels = makeLabelL( stmt, node->labels ); 343 this->node = stmt; 344 return nullptr; 447 345 } 448 346 449 347 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 450 if ( inCache( node ) ) return nullptr;451 348 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 452 return stmtPostamble( stmt, node ); 349 stmt->location = node->location; 350 stmt->labels = makeLabelL( stmt, node->labels ); 351 this->node = stmt; 352 return nullptr; 453 353 } 454 354 455 355 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 456 if ( inCache( node ) ) return nullptr;457 356 auto stmt = new WaitForStmt; 458 357 stmt->clauses.reserve( node->clauses.size() ); 459 358 for ( auto clause : node->clauses ) { 460 359 stmt->clauses.push_back({{ 461 get<Expression>().accept1( clause.target.func ),462 get<Expression>().acceptL( clause.target.arg s ),360 get<Expression>().accept1( clause.target.function ), 361 get<Expression>().acceptL( clause.target.arguments ), 463 362 }, 464 363 get<Statement>().accept1( clause.stmt ), … … 475 374 get<Expression>().accept1( node->orElse.cond ), 476 375 }; 477 return stmtPostamble( stmt, node ); 376 stmt->location = node->location; 377 stmt->labels = makeLabelL( stmt, node->labels ); 378 this->node = stmt; 379 return nullptr; 478 380 } 479 381 480 382 const ast::Stmt * visit( const ast::WithStmt * node ) override final { 481 if ( inCache( node ) ) return nullptr;482 383 auto stmt = new WithStmt( 483 384 get<Expression>().acceptL( node->exprs ), 484 385 get<Statement>().accept1( node->stmt ) 485 386 ); 486 return stmtPostamble( stmt, node ); 387 stmt->location = node->location; 388 stmt->labels = makeLabelL( stmt, node->labels ); 389 this->node = stmt; 390 return nullptr; 487 391 } 488 392 489 393 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 490 if ( inCache( node ) ) return nullptr;491 394 auto stmt = new NullStmt(); 492 stmtPostamble( stmt, node ); 395 stmt->location = node->location; 396 stmt->labels = makeLabelL( stmt, node->labels ); 397 this->node = stmt; 493 398 return nullptr; 494 399 } 495 400 496 401 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 497 if ( inCache( node ) ) return nullptr;498 402 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 499 return stmtPostamble( stmt, node ); 403 stmt->location = node->location; 404 stmt->labels = makeLabelL( stmt, node->labels ); 405 this->node = stmt; 406 return nullptr; 500 407 } 501 408 502 409 const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { 503 if ( inCache( node ) ) return nullptr; 504 auto stmt = new ImplicitCtorDtorStmt{ 505 get<Statement>().accept1( node->callStmt ) 506 }; 507 return stmtPostamble( stmt, node ); 508 } 509 510 TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) { 511 512 if (!src) return nullptr; 513 514 TypeSubstitution *rslt = new TypeSubstitution(); 515 516 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { 517 rslt->add( src_i->first, 518 get<Type>().accept1(src_i->second) ); 519 } 520 521 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) { 522 rslt->addVar( src_i->first, 523 get<Expression>().accept1(src_i->second) ); 524 } 525 526 return rslt; 527 } 528 529 void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams, 530 std::vector<UniqueId> &tgtResnSlots, 531 const ast::Expr::InferUnion &srcInferred ) { 532 533 assert( tgtInferParams.empty() ); 534 assert( tgtResnSlots.empty() ); 535 536 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) { 537 const ast::InferredParams &srcParams = srcInferred.inferParamsConst(); 538 for (auto srcParam : srcParams) { 539 tgtInferParams[srcParam.first] = ParamEntry( 540 srcParam.second.decl, 541 get<Type>().accept1(srcParam.second.actualType), 542 get<Type>().accept1(srcParam.second.formalType), 543 get<Expression>().accept1(srcParam.second.expr) 544 ); 545 } 546 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots ) { 547 const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst(); 548 for (auto srcSlot : srcSlots) { 549 tgtResnSlots.push_back(srcSlot); 550 } 551 } 552 } 553 554 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 555 556 tgt->location = src->location; 557 tgt->env = convertTypeSubstitution(src->env); 558 tgt->extension = src->extension; 559 560 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 561 return tgt; 562 } 563 564 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 565 566 tgt->result = get<Type>().accept1(src->result); 567 return visitBaseExpr_skipResultType(src, tgt); 410 (void)node; 411 return nullptr; 568 412 } 569 413 570 414 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 571 auto expr = visitBaseExpr( node, 572 new ApplicationExpr( 573 get<Expression>().accept1(node->func), 574 get<Expression>().acceptL(node->args) 575 ) 576 ); 577 this->node = expr; 415 (void)node; 578 416 return nullptr; 579 417 } 580 418 581 419 const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 582 auto expr = visitBaseExpr( node, 583 new UntypedExpr( 584 get<Expression>().accept1(node->func), 585 get<Expression>().acceptL(node->args) 586 ) 587 ); 588 this->node = expr; 420 (void)node; 589 421 return nullptr; 590 422 } 591 423 592 424 const ast::Expr * visit( const ast::NameExpr * node ) override final { 593 auto expr = visitBaseExpr( node, 594 new NameExpr( 595 node->name 596 ) 597 ); 598 this->node = expr; 425 (void)node; 599 426 return nullptr; 600 427 } 601 428 602 429 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 603 auto expr = visitBaseExpr( node, 604 new AddressExpr( 605 get<Expression>().accept1(node->arg) 606 ) 607 ); 608 this->node = expr; 430 (void)node; 609 431 return nullptr; 610 432 } 611 433 612 434 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 613 auto expr = visitBaseExpr( node, 614 new LabelAddressExpr( 615 makeLabel(nullptr, node->arg) 616 ) 617 ); 618 this->node = expr; 435 (void)node; 619 436 return nullptr; 620 437 } 621 438 622 439 const ast::Expr * visit( const ast::CastExpr * node ) override final { 623 auto expr = visitBaseExpr( node, 624 new CastExpr( 625 get<Expression>().accept1(node->arg), 626 (node->isGenerated == ast::GeneratedCast) 627 ) 628 ); 629 this->node = expr; 440 (void)node; 630 441 return nullptr; 631 442 } 632 443 633 444 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 634 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS; 635 switch (node->target) { 636 case ast::KeywordCastExpr::Coroutine: 637 castTarget = KeywordCastExpr::Coroutine; 638 break; 639 case ast::KeywordCastExpr::Thread: 640 castTarget = KeywordCastExpr::Thread; 641 break; 642 case ast::KeywordCastExpr::Monitor: 643 castTarget = KeywordCastExpr::Monitor; 644 break; 645 default: 646 break; 647 } 648 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS ); 649 auto expr = visitBaseExpr( node, 650 new KeywordCastExpr( 651 get<Expression>().accept1(node->arg), 652 castTarget 653 ) 654 ); 655 this->node = expr; 445 (void)node; 656 446 return nullptr; 657 447 } 658 448 659 449 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 660 auto expr = visitBaseExpr_skipResultType( node, 661 new VirtualCastExpr( 662 get<Expression>().accept1(node->arg), 663 get<Type>().accept1(node->result) 664 ) 665 ); 666 this->node = expr; 450 (void)node; 667 451 return nullptr; 668 452 } 669 453 670 454 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 671 auto expr = visitBaseExpr( node, 672 new UntypedMemberExpr( 673 get<Expression>().accept1(node->member), 674 get<Expression>().accept1(node->aggregate) 675 ) 676 ); 677 this->node = expr; 455 (void)node; 678 456 return nullptr; 679 457 } 680 458 681 459 const ast::Expr * visit( const ast::MemberExpr * node ) override final { 682 auto expr = visitBaseExpr( node, 683 new MemberExpr( 684 inCache(node->member) ? 685 dynamic_cast<DeclarationWithType *>(this->node) : 686 get<DeclarationWithType>().accept1(node->member), 687 get<Expression>().accept1(node->aggregate) 688 ) 689 ); 690 this->node = expr; 460 (void)node; 691 461 return nullptr; 692 462 } 693 463 694 464 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 695 auto expr = visitBaseExpr( node, 696 new VariableExpr( 697 inCache(node->var) ? 698 dynamic_cast<DeclarationWithType *>(this->node) : 699 get<DeclarationWithType>().accept1(node->var) 700 ) 701 ); 702 this->node = expr; 465 (void)node; 703 466 return nullptr; 704 467 } 705 468 706 469 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 707 ConstantExpr *rslt = nullptr; 708 switch ( node->kind ) { 709 case ast::ConstantExpr::Integer: 710 rslt = new ConstantExpr{Constant{ 711 get<Type>().accept1( node->result ), 712 node->rep, 713 (unsigned long long) node->intValue() 714 }}; 715 break; 716 case ast::ConstantExpr::FloatingPoint: 717 rslt = new ConstantExpr{Constant{ 718 get<Type>().accept1(node->result), 719 node->rep, 720 (double) node->floatValue() 721 }}; 722 break; 723 case ast::ConstantExpr::String: 724 rslt = new ConstantExpr{Constant::from_string( node->rep )}; 725 break; 726 } 727 assert(rslt); 728 auto expr = visitBaseExpr( node, rslt ); 729 this->node = expr; 470 (void)node; 730 471 return nullptr; 731 472 } 732 473 733 474 const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 734 assert (node->expr || node->type); 735 assert (! (node->expr && node->type)); 736 SizeofExpr *rslt; 737 if (node->expr) { 738 rslt = new SizeofExpr( 739 get<Expression>().accept1(node->expr) 740 ); 741 assert (!rslt->isType); 742 } 743 if (node->type) { 744 rslt = new SizeofExpr( 745 get<Type>().accept1(node->type) 746 ); 747 assert (rslt->isType); 748 } 749 auto expr = visitBaseExpr( node, rslt ); 750 this->node = expr; 475 (void)node; 751 476 return nullptr; 752 477 } 753 478 754 479 const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 755 assert (node->expr || node->type); 756 assert (! (node->expr && node->type)); 757 AlignofExpr *rslt; 758 if (node->expr) { 759 rslt = new AlignofExpr( 760 get<Expression>().accept1(node->expr) 761 ); 762 assert (!rslt->isType); 763 } 764 if (node->type) { 765 rslt = new AlignofExpr( 766 get<Type>().accept1(node->type) 767 ); 768 assert (rslt->isType); 769 } 770 auto expr = visitBaseExpr( node, rslt ); 771 this->node = expr; 480 (void)node; 772 481 return nullptr; 773 482 } 774 483 775 484 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 776 auto expr = visitBaseExpr( node, 777 new UntypedOffsetofExpr( 778 get<Type>().accept1(node->type), 779 node->member 780 ) 781 ); 782 this->node = expr; 485 (void)node; 783 486 return nullptr; 784 487 } 785 488 786 489 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 787 auto expr = visitBaseExpr( node, 788 new OffsetofExpr( 789 get<Type>().accept1(node->type), 790 inCache(node->member) ? 791 dynamic_cast<DeclarationWithType *>(this->node) : 792 get<DeclarationWithType>().accept1(node->member) 793 ) 794 ); 795 this->node = expr; 490 (void)node; 796 491 return nullptr; 797 492 } 798 493 799 494 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 800 auto expr = visitBaseExpr( node, 801 new OffsetPackExpr( 802 get<StructInstType>().accept1(node->type) 803 ) 804 ); 805 this->node = expr; 495 (void)node; 806 496 return nullptr; 807 497 } 808 498 809 499 const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 810 assert (node->isAnd == ast::LogicalFlag::AndExpr || 811 node->isAnd == ast::LogicalFlag::OrExpr ); 812 auto expr = visitBaseExpr( node, 813 new LogicalExpr( 814 get<Expression>().accept1(node->arg1), 815 get<Expression>().accept1(node->arg2), 816 (node->isAnd == ast::LogicalFlag::AndExpr) 817 ) 818 ); 819 this->node = expr; 500 (void)node; 820 501 return nullptr; 821 502 } 822 503 823 504 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 824 auto expr = visitBaseExpr( node, 825 new ConditionalExpr( 826 get<Expression>().accept1(node->arg1), 827 get<Expression>().accept1(node->arg2), 828 get<Expression>().accept1(node->arg3) 829 ) 830 ); 831 this->node = expr; 505 (void)node; 832 506 return nullptr; 833 507 } 834 508 835 509 const ast::Expr * visit( const ast::CommaExpr * node ) override final { 836 auto expr = visitBaseExpr( node, 837 new CommaExpr( 838 get<Expression>().accept1(node->arg1), 839 get<Expression>().accept1(node->arg2) 840 ) 841 ); 842 this->node = expr; 510 (void)node; 843 511 return nullptr; 844 512 } 845 513 846 514 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 847 auto expr = visitBaseExpr( node, 848 new TypeExpr( 849 get<Type>().accept1(node->type) 850 ) 851 ); 852 this->node = expr; 515 (void)node; 853 516 return nullptr; 854 517 } 855 518 856 519 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 857 auto expr = visitBaseExpr( node, 858 new AsmExpr( 859 get<Expression>().accept1(node->inout), 860 get<Expression>().accept1(node->constraint), 861 get<Expression>().accept1(node->operand) 862 ) 863 ); 864 this->node = expr; 520 (void)node; 865 521 return nullptr; 866 522 } 867 523 868 524 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 869 auto rslt = new ImplicitCopyCtorExpr( 870 get<ApplicationExpr>().accept1(node->callExpr) 871 ); 872 873 auto expr = visitBaseExpr( node, rslt ); 874 this->node = expr; 525 (void)node; 875 526 return nullptr; 876 527 } 877 528 878 529 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 879 auto expr = visitBaseExpr( node, 880 new ConstructorExpr( 881 get<Expression>().accept1(node->callExpr) 882 ) 883 ); 884 this->node = expr; 530 (void)node; 885 531 return nullptr; 886 532 } 887 533 888 534 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 889 auto expr = visitBaseExpr_skipResultType( node, 890 new CompoundLiteralExpr( 891 get<Type>().accept1(node->result), 892 get<Initializer>().accept1(node->init) 893 ) 894 ); 895 this->node = expr; 535 (void)node; 896 536 return nullptr; 897 537 } 898 538 899 539 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 900 auto expr = visitBaseExpr( node, 901 new RangeExpr( 902 get<Expression>().accept1(node->low), 903 get<Expression>().accept1(node->high) 904 ) 905 ); 906 this->node = expr; 540 (void)node; 907 541 return nullptr; 908 542 } 909 543 910 544 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 911 auto expr = visitBaseExpr( node, 912 new UntypedTupleExpr( 913 get<Expression>().acceptL(node->exprs) 914 ) 915 ); 916 this->node = expr; 545 (void)node; 917 546 return nullptr; 918 547 } 919 548 920 549 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 921 auto expr = visitBaseExpr( node, 922 new UntypedTupleExpr( 923 get<Expression>().acceptL(node->exprs) 924 ) 925 ); 926 this->node = expr; 550 (void)node; 927 551 return nullptr; 928 552 } 929 553 930 554 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 931 auto expr = visitBaseExpr( node, 932 new TupleIndexExpr( 933 get<Expression>().accept1(node->tuple), 934 node->index 935 ) 936 ); 937 this->node = expr; 555 (void)node; 938 556 return nullptr; 939 557 } 940 558 941 559 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 942 auto expr = visitBaseExpr( node, 943 new TupleAssignExpr( 944 get<StmtExpr>().accept1(node->stmtExpr) 945 ) 946 ); 947 this->node = expr; 560 (void)node; 948 561 return nullptr; 949 562 } 950 563 951 564 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 952 auto rslt = new StmtExpr( 953 get<CompoundStmt>().accept1(node->stmts) 954 ); 955 956 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 957 rslt->dtors = get<Expression>().acceptL(node->dtors); 958 959 auto expr = visitBaseExpr( node, rslt ); 960 this->node = expr; 565 (void)node; 961 566 return nullptr; 962 567 } 963 568 964 569 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 965 auto rslt = new UniqueExpr( 966 get<Expression>().accept1(node->expr) 967 ); 968 969 rslt->object = get<ObjectDecl> ().accept1(node->object); 970 rslt->var = get<VariableExpr>().accept1(node->var); 971 972 auto expr = visitBaseExpr( node, rslt ); 973 this->node = expr; 570 (void)node; 974 571 return nullptr; 975 572 } 976 573 977 574 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 978 std::list<InitAlternative> initAlts; 979 for (auto ia : node->initAlts) { 980 initAlts.push_back(InitAlternative( 981 get<Type> ().accept1(ia.type), 982 get<Designation>().accept1(ia.designation) 983 )); 984 } 985 auto expr = visitBaseExpr( node, 986 new UntypedInitExpr( 987 get<Expression>().accept1(node->expr), 988 initAlts 989 ) 990 ); 991 this->node = expr; 575 (void)node; 992 576 return nullptr; 993 577 } 994 578 995 579 const ast::Expr * visit( const ast::InitExpr * node ) override final { 996 auto expr = visitBaseExpr( node, 997 new InitExpr( 998 get<Expression>().accept1(node->expr), 999 get<Designation>().accept1(node->designation) 1000 ) 1001 ); 1002 this->node = expr; 580 (void)node; 1003 581 return nullptr; 1004 582 } 1005 583 1006 584 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 1007 auto expr = visitBaseExpr( node, 1008 new DeletedExpr( 1009 get<Expression>().accept1(node->expr), 1010 inCache(node->deleteStmt) ? 1011 this->node : 1012 get<BaseSyntaxNode>().accept1(node->deleteStmt) 1013 ) 1014 ); 1015 this->node = expr; 585 (void)node; 1016 586 return nullptr; 1017 587 } 1018 588 1019 589 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 1020 auto expr = visitBaseExpr( node, 1021 new DefaultArgExpr( 1022 get<Expression>().accept1(node->expr) 1023 ) 1024 ); 1025 this->node = expr; 590 (void)node; 1026 591 return nullptr; 1027 592 } 1028 593 1029 594 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 1030 std::list<GenericExpr::Association> associations; 1031 for (auto association : node->associations) { 1032 associations.push_back(GenericExpr::Association( 1033 get<Type> ().accept1(association.type), 1034 get<Expression>().accept1(association.expr) 1035 )); 1036 } 1037 auto expr = visitBaseExpr( node, 1038 new GenericExpr( 1039 get<Expression>().accept1(node->control), 1040 associations 1041 ) 1042 ); 1043 this->node = expr; 595 (void)node; 1044 596 return nullptr; 1045 597 } 1046 598 1047 599 const ast::Type * visit( const ast::VoidType * node ) override final { 1048 this->node = new VoidType{ cv( node ) };600 (void)node; 1049 601 return nullptr; 1050 602 } 1051 603 1052 604 const ast::Type * visit( const ast::BasicType * node ) override final { 1053 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };605 (void)node; 1054 606 return nullptr; 1055 607 } 1056 608 1057 609 const ast::Type * visit( const ast::PointerType * node ) override final { 1058 this->node = new PointerType{ 1059 cv( node ), 1060 get<Type>().accept1( node->base ), 1061 get<Expression>().accept1( node->dimension ), 1062 (bool)node->isVarLen, 1063 (bool)node->isStatic 1064 }; 610 (void)node; 1065 611 return nullptr; 1066 612 } 1067 613 1068 614 const ast::Type * visit( const ast::ArrayType * node ) override final { 1069 this->node = new ArrayType{ 1070 cv( node ), 1071 get<Type>().accept1( node->base ), 1072 get<Expression>().accept1( node->dimension ), 1073 (bool)node->isVarLen, 1074 (bool)node->isStatic 1075 }; 615 (void)node; 1076 616 return nullptr; 1077 617 } 1078 618 1079 619 const ast::Type * visit( const ast::ReferenceType * node ) override final { 1080 this->node = new ReferenceType{ 1081 cv( node ), 1082 get<Type>().accept1( node->base ) 1083 }; 620 (void)node; 1084 621 return nullptr; 1085 622 } 1086 623 1087 624 const ast::Type * visit( const ast::QualifiedType * node ) override final { 1088 this->node = new QualifiedType{ 1089 cv( node ), 1090 get<Type>().accept1( node->parent ), 1091 get<Type>().accept1( node->child ) 1092 }; 625 (void)node; 1093 626 return nullptr; 1094 627 } 1095 628 1096 629 const ast::Type * visit( const ast::FunctionType * node ) override final { 1097 auto ty = new FunctionType { 1098 cv( node ), 1099 (bool)node->isVarArgs 1100 }; 1101 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1102 ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1103 ty->forall = get<TypeDecl>().acceptL( node->forall ); 1104 this->node = ty; 1105 return nullptr; 1106 } 1107 1108 void postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) { 1109 ty->forall = get<TypeDecl>().acceptL( old->forall ); 1110 ty->parameters = get<Expression>().acceptL( old->params ); 1111 ty->hoistType = old->hoistType; 630 (void)node; 631 return nullptr; 1112 632 } 1113 633 1114 634 const ast::Type * visit( const ast::StructInstType * node ) override final { 1115 StructInstType * ty; 1116 if ( node->base ) { 1117 ty = new StructInstType{ 1118 cv( node ), 1119 get<StructDecl>().accept1( node->base ), 1120 get<Attribute>().acceptL( node->attributes ) 1121 }; 1122 } else { 1123 ty = new StructInstType{ 1124 cv( node ), 1125 node->name, 1126 get<Attribute>().acceptL( node->attributes ) 1127 }; 1128 } 1129 postvisit( node, ty ); 1130 this->node = ty; 635 (void)node; 1131 636 return nullptr; 1132 637 } 1133 638 1134 639 const ast::Type * visit( const ast::UnionInstType * node ) override final { 1135 UnionInstType * ty; 1136 if ( node->base ) { 1137 ty = new UnionInstType{ 1138 cv( node ), 1139 get<UnionDecl>().accept1( node->base ), 1140 get<Attribute>().acceptL( node->attributes ) 1141 }; 1142 } else { 1143 ty = new UnionInstType{ 1144 cv( node ), 1145 node->name, 1146 get<Attribute>().acceptL( node->attributes ) 1147 }; 1148 } 1149 postvisit( node, ty ); 1150 this->node = ty; 640 (void)node; 1151 641 return nullptr; 1152 642 } 1153 643 1154 644 const ast::Type * visit( const ast::EnumInstType * node ) override final { 1155 EnumInstType * ty; 1156 if ( node->base ) { 1157 ty = new EnumInstType{ 1158 cv( node ), 1159 get<EnumDecl>().accept1( node->base ), 1160 get<Attribute>().acceptL( node->attributes ) 1161 }; 1162 } else { 1163 ty = new EnumInstType{ 1164 cv( node ), 1165 node->name, 1166 get<Attribute>().acceptL( node->attributes ) 1167 }; 1168 } 1169 postvisit( node, ty ); 1170 this->node = ty; 645 (void)node; 1171 646 return nullptr; 1172 647 } 1173 648 1174 649 const ast::Type * visit( const ast::TraitInstType * node ) override final { 1175 TraitInstType * ty; 1176 if ( node->base ) { 1177 ty = new TraitInstType{ 1178 cv( node ), 1179 get<TraitDecl>().accept1( node->base ), 1180 get<Attribute>().acceptL( node->attributes ) 1181 }; 1182 } else { 1183 ty = new TraitInstType{ 1184 cv( node ), 1185 node->name, 1186 get<Attribute>().acceptL( node->attributes ) 1187 }; 1188 } 1189 postvisit( node, ty ); 1190 this->node = ty; 650 (void)node; 1191 651 return nullptr; 1192 652 } 1193 653 1194 654 const ast::Type * visit( const ast::TypeInstType * node ) override final { 1195 TypeInstType * ty; 1196 if ( node->base ) { 1197 ty = new TypeInstType{ 1198 cv( node ), 1199 node->name, 1200 get<TypeDecl>().accept1( node->base ), 1201 get<Attribute>().acceptL( node->attributes ) 1202 }; 1203 } else { 1204 ty = new TypeInstType{ 1205 cv( node ), 1206 node->name, 1207 node->kind == ast::TypeVar::Ftype, 1208 get<Attribute>().acceptL( node->attributes ) 1209 }; 1210 } 1211 postvisit( node, ty ); 1212 this->node = ty; 655 (void)node; 1213 656 return nullptr; 1214 657 } 1215 658 1216 659 const ast::Type * visit( const ast::TupleType * node ) override final { 1217 this->node = new TupleType{ 1218 cv( node ), 1219 get<Type>().acceptL( node->types ) 1220 // members generated by TupleType c'tor 1221 }; 660 (void)node; 1222 661 return nullptr; 1223 662 } 1224 663 1225 664 const ast::Type * visit( const ast::TypeofType * node ) override final { 1226 this->node = new TypeofType{ 1227 cv( node ), 1228 get<Expression>().accept1( node->expr ), 1229 (bool)node->kind 1230 }; 665 (void)node; 1231 666 return nullptr; 1232 667 } 1233 668 1234 669 const ast::Type * visit( const ast::VarArgsType * node ) override final { 1235 this->node = new VarArgsType{ cv( node ) };670 (void)node; 1236 671 return nullptr; 1237 672 } 1238 673 1239 674 const ast::Type * visit( const ast::ZeroType * node ) override final { 1240 this->node = new ZeroType{ cv( node ) };675 (void)node; 1241 676 return nullptr; 1242 677 } 1243 678 1244 679 const ast::Type * visit( const ast::OneType * node ) override final { 1245 this->node = new OneType{ cv( node ) };1246 return nullptr; 1247 } 1248 1249 const ast::Type * visit( const ast::GlobalScopeType * ) override final {1250 this->node = new GlobalScopeType{};680 (void)node; 681 return nullptr; 682 } 683 684 const ast::Type * visit( const ast::GlobalScopeType * node ) override final { 685 (void)node; 1251 686 return nullptr; 1252 687 } 1253 688 1254 689 const ast::Designation * visit( const ast::Designation * node ) override final { 1255 auto designation = new Designation( get<Expression>().acceptL( node->designators ) ); 1256 designation->location = node->location; 1257 this->node = designation; 690 (void)node; 1258 691 return nullptr; 1259 692 } 1260 693 1261 694 const ast::Init * visit( const ast::SingleInit * node ) override final { 1262 auto init = new SingleInit( 1263 get<Expression>().accept1( node->value ), 1264 ast::MaybeConstruct == node->maybeConstructed 1265 ); 1266 init->location = node->location; 1267 this->node = init; 695 (void)node; 1268 696 return nullptr; 1269 697 } 1270 698 1271 699 const ast::Init * visit( const ast::ListInit * node ) override final { 1272 auto init = new ListInit( 1273 get<Initializer>().acceptL( node->initializers ), 1274 get<Designation>().acceptL( node->designations ), 1275 ast::MaybeConstruct == node->maybeConstructed 1276 ); 1277 init->location = node->location; 1278 this->node = init; 700 (void)node; 1279 701 return nullptr; 1280 702 } 1281 703 1282 704 const ast::Init * visit( const ast::ConstructorInit * node ) override final { 1283 auto init = new ConstructorInit( 1284 get<Statement>().accept1( node->ctor ), 1285 get<Statement>().accept1( node->dtor ), 1286 get<Initializer>().accept1( node->init ) 1287 ); 1288 init->location = node->location; 1289 this->node = init; 705 (void)node; 1290 706 return nullptr; 1291 707 } 1292 708 1293 709 const ast::Attribute * visit( const ast::Attribute * node ) override final { 1294 auto attr = new Attribute( 1295 node->name, 1296 get<Expression>().acceptL(node->params) 1297 ); 1298 this->node = attr; 710 (void)node; 1299 711 return nullptr; 1300 712 } 1301 713 1302 714 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { 1303 // Handled by convertTypeSubstitution helper instead.1304 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node.1305 assert( 0 );1306 715 (void)node; 1307 716 return nullptr; … … 1309 718 }; 1310 719 1311 std::list< Declaration * > convert( conststd::list< ast::ptr< ast::Decl > > && translationUnit ) {720 std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) { 1312 721 ConverterNewToOld c; 1313 722 std::list< Declaration * > decls; 1314 723 for(auto d : translationUnit) { 1315 724 decls.emplace_back( c.decl( d ) ); 725 delete d; 1316 726 } 1317 727 return decls; … … 1326 736 } 1327 737 private: 1328 /// conversion output1329 738 ast::Node * node; 1330 /// cache of nodes that might be referenced by readonly<> for de-duplication1331 std::unordered_map< BaseSyntaxNode *, ast::Node * > cache;1332 739 1333 740 // Local Utilities: … … 1335 742 template<typename NewT, typename OldT> 1336 743 NewT * getAccept1( OldT old ) { 1337 if ( ! old ) return nullptr;1338 744 old->accept(*this); 1339 745 return strict_dynamic_cast< NewT * >( node ); … … 1377 783 to<std::vector>::from( make_labels( std::move( labels ) ) ) 1378 784 1379 static ast::CV::Qualifiers cv( Type * ty ) { return { ty->get_qualifiers().val }; }1380 1381 /// returns true and sets `node` if in cache1382 bool inCache( BaseSyntaxNode * old ) {1383 auto it = cache.find( old );1384 if ( it == cache.end() ) return false;1385 node = it->second;1386 return true;1387 }1388 1389 785 // Now all the visit functions: 1390 786 1391 787 virtual void visit( ObjectDecl * old ) override final { 1392 if ( inCache( old ) ) return;1393 788 auto decl = new ast::ObjectDecl( 1394 789 old->location, … … 1402 797 { old->get_funcSpec().val } 1403 798 ); 1404 cache.emplace( old, decl );1405 799 decl->scopeLevel = old->scopeLevel; 1406 800 decl->mangleName = old->mangleName; … … 1412 806 } 1413 807 1414 virtual void visit( FunctionDecl * old ) override final { 1415 if ( inCache( old ) ) return; 1416 auto decl = new ast::FunctionDecl{ 1417 old->location, 1418 old->name, 1419 GET_ACCEPT_1(type, FunctionType), 1420 GET_ACCEPT_1(statements, CompoundStmt), 1421 { old->storageClasses.val }, 1422 { old->linkage.val }, 1423 GET_ACCEPT_V(attributes, Attribute), 1424 { old->get_funcSpec().val } 1425 }; 1426 cache.emplace( old, decl ); 1427 decl->scopeLevel = old->scopeLevel; 1428 decl->mangleName = old->mangleName; 1429 decl->isDeleted = old->isDeleted; 1430 decl->uniqueId = old->uniqueId; 1431 decl->extension = old->extension; 1432 1433 this->node = decl; 808 virtual void visit( FunctionDecl * ) override final { 809 1434 810 } 1435 811 1436 812 virtual void visit( StructDecl * old ) override final { 1437 if ( inCache( old ) ) return;1438 813 auto decl = new ast::StructDecl( 1439 814 old->location, … … 1443 818 { old->linkage.val } 1444 819 ); 1445 cache.emplace( old, decl );1446 820 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 1447 821 decl->body = old->body; … … 1456 830 1457 831 virtual void visit( UnionDecl * old ) override final { 1458 if ( inCache( old ) ) return;1459 832 auto decl = new ast::UnionDecl( 1460 833 old->location, … … 1463 836 { old->linkage.val } 1464 837 ); 1465 cache.emplace( old, decl );1466 838 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 1467 839 decl->body = old->body; … … 1476 848 1477 849 virtual void visit( EnumDecl * old ) override final { 1478 if ( inCache( old ) ) return;1479 850 auto decl = new ast::UnionDecl( 1480 851 old->location, … … 1483 854 { old->linkage.val } 1484 855 ); 1485 cache.emplace( old, decl );1486 856 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 1487 857 decl->body = old->body; … … 1496 866 1497 867 virtual void visit( TraitDecl * old ) override final { 1498 if ( inCache( old ) ) return;1499 868 auto decl = new ast::UnionDecl( 1500 869 old->location, … … 1503 872 { old->linkage.val } 1504 873 ); 1505 cache.emplace( old, decl );1506 874 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 1507 875 decl->body = old->body; … … 1515 883 } 1516 884 1517 virtual void visit( TypeDecl * old ) override final { 1518 if ( inCache( old ) ) return; 1519 auto decl = new ast::TypeDecl{ 1520 old->location, 1521 old->name, 1522 { old->storageClasses.val }, 1523 GET_ACCEPT_1(base, Type), 1524 (ast::TypeVar::Kind)(unsigned)old->kind, 1525 old->sized, 1526 GET_ACCEPT_1(init, Type) 1527 }; 1528 cache.emplace( old, decl ); 1529 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1530 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1531 decl->extension = old->extension; 1532 decl->uniqueId = old->uniqueId; 1533 1534 this->node = decl; 885 virtual void visit( TypeDecl * ) override final { 886 1535 887 } 1536 888 … … 1552 904 } 1553 905 1554 virtual void visit( AsmDecl * old ) override final { 1555 auto decl = new ast::AsmDecl{ 1556 old->location, 1557 GET_ACCEPT_1(stmt, AsmStmt) 1558 }; 1559 decl->extension = old->extension; 1560 decl->uniqueId = old->uniqueId; 1561 decl->storage = { old->storageClasses.val }; 1562 1563 this->node = decl; 1564 } 1565 1566 virtual void visit( StaticAssertDecl * old ) override final { 1567 auto decl = new ast::StaticAssertDecl{ 1568 old->location, 1569 GET_ACCEPT_1(condition, Expr), 1570 GET_ACCEPT_1(message, ConstantExpr) 1571 }; 1572 decl->extension = old->extension; 1573 decl->uniqueId = old->uniqueId; 1574 decl->storage = { old->storageClasses.val }; 1575 1576 this->node = decl; 906 virtual void visit( AsmDecl * ) override final { 907 908 } 909 910 virtual void visit( StaticAssertDecl * ) override final { 911 1577 912 } 1578 913 1579 914 virtual void visit( CompoundStmt * old ) override final { 1580 if ( inCache( old ) ) return;1581 915 auto stmt = new ast::CompoundStmt( 1582 916 old->location, … … 1586 920 1587 921 this->node = stmt; 1588 cache.emplace( old, this->node );1589 922 } 1590 923 1591 924 virtual void visit( ExprStmt * old ) override final { 1592 if ( inCache( old ) ) return;1593 925 this->node = new ast::ExprStmt( 1594 926 old->location, … … 1596 928 GET_LABELS_V(old->labels) 1597 929 ); 1598 cache.emplace( old, this->node );1599 930 } 1600 931 1601 932 virtual void visit( AsmStmt * old ) override final { 1602 if ( inCache( old ) ) return;1603 933 this->node = new ast::AsmStmt( 1604 934 old->location, … … 1611 941 GET_LABELS_V(old->labels) 1612 942 ); 1613 cache.emplace( old, this->node );1614 943 } 1615 944 1616 945 virtual void visit( DirectiveStmt * old ) override final { 1617 if ( inCache( old ) ) return;1618 946 this->node = new ast::DirectiveStmt( 1619 947 old->location, … … 1621 949 GET_LABELS_V(old->labels) 1622 950 ); 1623 cache.emplace( old, this->node );1624 951 } 1625 952 1626 953 virtual void visit( IfStmt * old ) override final { 1627 if ( inCache( old ) ) return;1628 954 this->node = new ast::IfStmt( 1629 955 old->location, … … 1634 960 GET_LABELS_V(old->labels) 1635 961 ); 1636 cache.emplace( old, this->node );1637 962 } 1638 963 1639 964 virtual void visit( SwitchStmt * old ) override final { 1640 if ( inCache( old ) ) return;1641 965 this->node = new ast::SwitchStmt( 1642 966 old->location, … … 1645 969 GET_LABELS_V(old->labels) 1646 970 ); 1647 cache.emplace( old, this->node );1648 971 } 1649 972 1650 973 virtual void visit( CaseStmt * old ) override final { 1651 if ( inCache( old ) ) return;1652 974 this->node = new ast::CaseStmt( 1653 975 old->location, … … 1656 978 GET_LABELS_V(old->labels) 1657 979 ); 1658 cache.emplace( old, this->node );1659 980 } 1660 981 1661 982 virtual void visit( WhileStmt * old ) override final { 1662 if ( inCache( old ) ) return;1663 983 this->node = new ast::WhileStmt( 1664 984 old->location, … … 1669 989 GET_LABELS_V(old->labels) 1670 990 ); 1671 cache.emplace( old, this->node );1672 991 } 1673 992 1674 993 virtual void visit( ForStmt * old ) override final { 1675 if ( inCache( old ) ) return;1676 994 this->node = new ast::ForStmt( 1677 995 old->location, … … 1682 1000 GET_LABELS_V(old->labels) 1683 1001 ); 1684 cache.emplace( old, this->node );1685 1002 } 1686 1003 1687 1004 virtual void visit( BranchStmt * old ) override final { 1688 if ( inCache( old ) ) return;1689 1005 if (old->computedTarget) { 1690 1006 this->node = new ast::BranchStmt( … … 1720 1036 this->node = stmt; 1721 1037 } 1722 cache.emplace( old, this->node );1723 1038 } 1724 1039 1725 1040 virtual void visit( ReturnStmt * old ) override final { 1726 if ( inCache( old ) ) return;1727 1041 this->node = new ast::ReturnStmt( 1728 1042 old->location, … … 1730 1044 GET_LABELS_V(old->labels) 1731 1045 ); 1732 cache.emplace( old, this->node );1733 1046 } 1734 1047 1735 1048 virtual void visit( ThrowStmt * old ) override final { 1736 if ( inCache( old ) ) return;1737 1049 ast::ThrowStmt::Kind kind; 1738 1050 switch (old->kind) { … … 1754 1066 GET_LABELS_V(old->labels) 1755 1067 ); 1756 cache.emplace( old, this->node );1757 1068 } 1758 1069 1759 1070 virtual void visit( TryStmt * old ) override final { 1760 if ( inCache( old ) ) return;1761 1071 this->node = new ast::TryStmt( 1762 1072 old->location, … … 1766 1076 GET_LABELS_V(old->labels) 1767 1077 ); 1768 cache.emplace( old, this->node );1769 1078 } 1770 1079 1771 1080 virtual void visit( CatchStmt * old ) override final { 1772 if ( inCache( old ) ) return;1773 1081 ast::CatchStmt::Kind kind; 1774 1082 switch (old->kind) { … … 1791 1099 GET_LABELS_V(old->labels) 1792 1100 ); 1793 cache.emplace( old, this->node );1794 1101 } 1795 1102 1796 1103 virtual void visit( FinallyStmt * old ) override final { 1797 if ( inCache( old ) ) return;1798 1104 this->node = new ast::FinallyStmt( 1799 1105 old->location, … … 1801 1107 GET_LABELS_V(old->labels) 1802 1108 ); 1803 cache.emplace( old, this->node );1804 1109 } 1805 1110 1806 1111 virtual void visit( WaitForStmt * old ) override final { 1807 if ( inCache( old ) ) return;1808 1112 ast::WaitForStmt * stmt = new ast::WaitForStmt( 1809 1113 old->location, … … 1833 1137 1834 1138 this->node = stmt; 1835 cache.emplace( old, this->node );1836 1139 } 1837 1140 1838 1141 virtual void visit( WithStmt * old ) override final { 1839 if ( inCache( old ) ) return;1840 1142 this->node = new ast::WithStmt( 1841 1143 old->location, … … 1844 1146 GET_LABELS_V(old->labels) 1845 1147 ); 1846 cache.emplace( old, this->node );1847 1148 } 1848 1149 1849 1150 virtual void visit( NullStmt * old ) override final { 1850 if ( inCache( old ) ) return;1851 1151 this->node = new ast::NullStmt( 1852 1152 old->location, 1853 1153 GET_LABELS_V(old->labels) 1854 1154 ); 1855 cache.emplace( old, this->node );1856 1155 } 1857 1156 1858 1157 virtual void visit( DeclStmt * old ) override final { 1859 if ( inCache( old ) ) return;1860 1158 this->node = new ast::DeclStmt( 1861 1159 old->location, … … 1863 1161 GET_LABELS_V(old->labels) 1864 1162 ); 1865 cache.emplace( old, this->node );1866 1163 } 1867 1164 1868 1165 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 1869 if ( inCache( old ) ) return; 1870 auto stmt = new ast::ImplicitCtorDtorStmt( 1871 old->location, 1872 nullptr, 1873 GET_LABELS_V(old->labels) 1874 ); 1875 this->node = stmt; 1876 cache.emplace( old, this->node ); 1877 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt); 1166 this->node = new ast::ImplicitCtorDtorStmt( 1167 old->location, 1168 GET_ACCEPT_1(callStmt, Stmt), 1169 GET_LABELS_V(old->labels) 1170 ); 1878 1171 } 1879 1172 1880 1173 ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) { 1881 1882 if (!old) return nullptr;1883 1174 1884 1175 ast::TypeSubstitution *rslt = new ast::TypeSubstitution(); … … 1893 1184 getAccept1<ast::Expr>(old_i->second) ); 1894 1185 } 1895 1896 return rslt; 1897 } 1898 1899 void convertInferUnion(ast::Expr::InferUnion &newInferred, 1900 const std::map<UniqueId,ParamEntry> &oldInferParams, 1901 const std::vector<UniqueId> &oldResnSlots) { 1902 1903 assert( oldInferParams.empty() || oldResnSlots.empty() ); 1904 assert( newInferred.mode == ast::Expr::InferUnion::Empty ); 1905 1906 if ( !oldInferParams.empty() ) { 1907 ast::InferredParams &tgt = newInferred.inferParams(); 1908 for (auto old : oldInferParams) { 1909 tgt[old.first] = ast::ParamEntry( 1910 old.second.decl, 1911 getAccept1<ast::Type>(old.second.actualType), 1912 getAccept1<ast::Type>(old.second.formalType), 1913 getAccept1<ast::Expr>(old.second.expr) 1914 ); 1915 } 1916 } else if ( !oldResnSlots.empty() ) { 1917 ast::ResnSlots &tgt = newInferred.resnSlots(); 1918 for (auto old : oldResnSlots) { 1919 tgt.push_back(old); 1920 } 1921 } 1922 } 1923 1924 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1925 1186 } 1187 1188 void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) { 1189 1190 (void) nwInferred; 1191 (void) oldInferParams; 1192 (void) oldResnSlots; 1193 1194 // TODO 1195 } 1196 1197 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1198 1199 nw->result = GET_ACCEPT_1(result, Type); 1926 1200 nw->env = convertTypeSubstitution(old->env); 1927 1201 … … 1932 1206 } 1933 1207 1934 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1935 1936 nw->result = GET_ACCEPT_1(result, Type); 1937 return visitBaseExpr_SkipResultType(old, nw);; 1938 } 1939 1940 virtual void visit( ApplicationExpr * old ) override final { 1941 this->node = visitBaseExpr( old, 1942 new ast::ApplicationExpr( 1943 old->location, 1944 GET_ACCEPT_1(function, Expr), 1945 GET_ACCEPT_V(args, Expr) 1946 ) 1947 ); 1948 } 1949 1950 virtual void visit( UntypedExpr * old ) override final { 1951 this->node = visitBaseExpr( old, 1952 new ast::UntypedExpr( 1953 old->location, 1954 GET_ACCEPT_1(function, Expr), 1955 GET_ACCEPT_V(args, Expr) 1956 ) 1957 ); 1208 virtual void visit( ApplicationExpr * ) override final { 1209 // TODO 1210 } 1211 1212 virtual void visit( UntypedExpr * ) override final { 1213 // TODO 1958 1214 } 1959 1215 … … 1967 1223 } 1968 1224 1969 virtual void visit( CastExpr * old ) override final { 1970 this->node = visitBaseExpr( old, 1971 new ast::CastExpr( 1972 old->location, 1973 GET_ACCEPT_1(arg, Expr), 1974 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 1975 ) 1976 ); 1977 } 1978 1979 virtual void visit( KeywordCastExpr * old) override final { 1980 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS; 1981 switch (old->target) { 1982 case KeywordCastExpr::Coroutine: 1983 castTarget = ast::KeywordCastExpr::Coroutine; 1984 break; 1985 case KeywordCastExpr::Thread: 1986 castTarget = ast::KeywordCastExpr::Thread; 1987 break; 1988 case KeywordCastExpr::Monitor: 1989 castTarget = ast::KeywordCastExpr::Monitor; 1990 break; 1991 default: 1992 break; 1993 } 1994 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS ); 1995 this->node = visitBaseExpr( old, 1996 new ast::KeywordCastExpr( 1997 old->location, 1998 GET_ACCEPT_1(arg, Expr), 1999 castTarget 2000 ) 2001 ); 2002 } 2003 2004 virtual void visit( VirtualCastExpr * old ) override final { 2005 this->node = visitBaseExpr_SkipResultType( old, 2006 new ast::VirtualCastExpr( 2007 old->location, 2008 GET_ACCEPT_1(arg, Expr), 2009 GET_ACCEPT_1(result, Type) 2010 ) 2011 ); 2012 } 2013 2014 virtual void visit( AddressExpr * old ) override final { 2015 this->node = visitBaseExpr( old, 2016 new ast::AddressExpr( 2017 old->location, 2018 GET_ACCEPT_1(arg, Expr) 2019 ) 2020 ); 2021 } 2022 2023 virtual void visit( LabelAddressExpr * old ) override final { 2024 this->node = visitBaseExpr( old, 2025 new ast::LabelAddressExpr( 2026 old->location, 2027 make_label(&old->arg) 2028 ) 2029 ); 2030 } 2031 2032 virtual void visit( UntypedMemberExpr * old ) override final { 2033 this->node = visitBaseExpr( old, 2034 new ast::UntypedMemberExpr( 2035 old->location, 2036 GET_ACCEPT_1(member, Expr), 2037 GET_ACCEPT_1(aggregate, Expr) 2038 ) 2039 ); 2040 } 2041 2042 virtual void visit( MemberExpr * old ) override final { 2043 this->node = visitBaseExpr( old, 2044 new ast::MemberExpr( 2045 old->location, 2046 inCache(old->member) ? 2047 dynamic_cast<ast::DeclWithType *>(this->node) : 2048 GET_ACCEPT_1(member, DeclWithType), 2049 GET_ACCEPT_1(aggregate, Expr) 2050 ) 2051 ); 2052 } 2053 2054 virtual void visit( VariableExpr * old ) override final { 2055 this->node = visitBaseExpr( old, 2056 new ast::VariableExpr( 2057 old->location, 2058 inCache(old->var) ? 2059 dynamic_cast<ast::DeclWithType *>(this->node) : 2060 GET_ACCEPT_1(var, DeclWithType) 2061 ) 2062 ); 2063 } 2064 2065 bool isIntlikeConstantType(const Type *t) { 2066 if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) { 2067 if ( basicType->isInteger() ) { 2068 return true; 2069 } 2070 } else if ( dynamic_cast< const OneType * >( t ) ) { 2071 return true; 2072 } else if ( dynamic_cast< const ZeroType * >( t ) ) { 2073 return true; 2074 } else if ( dynamic_cast< const PointerType * >( t ) ) { 2075 // null pointer constants, with zero int-values 2076 return true; 2077 } 2078 return false; 2079 } 2080 2081 int isFloatlikeConstantType(const Type *t) { 2082 if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) { 2083 if ( ! bty->isInteger() ) { 2084 return true; 2085 } 2086 } 2087 return false; 2088 } 2089 2090 int isStringlikeConstantType(const Type *t) { 2091 if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) { 2092 if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) { 2093 if ( bty->kind == BasicType::Kind::Char ) { 2094 return true; 2095 } 2096 } 2097 } 2098 return false; 2099 } 2100 2101 virtual void visit( ConstantExpr * old ) override final { 2102 ast::ConstantExpr *rslt = nullptr; 2103 if (isIntlikeConstantType(old->result)) { 2104 rslt = new ast::ConstantExpr( 2105 old->location, 2106 GET_ACCEPT_1(result, Type), 2107 old->constant.get_value(), 2108 (unsigned long long) old->intValue() 2109 ); 2110 } else if (isFloatlikeConstantType(old->result)) { 2111 rslt = new ast::ConstantExpr( 2112 old->location, 2113 GET_ACCEPT_1(result, Type), 2114 old->constant.get_value(), 2115 (double) old->constant.get_dval() 2116 ); 2117 } else if (isStringlikeConstantType(old->result)) { 2118 rslt = ast::ConstantExpr::from_string( 2119 old->location, 2120 old->constant.get_value() 2121 ); 2122 } 2123 assert(rslt); 2124 this->node = visitBaseExpr( old, rslt ); 2125 } 2126 2127 virtual void visit( SizeofExpr * old ) override final { 2128 assert (old->expr || old->type); 2129 assert (! (old->expr && old->type)); 2130 ast::SizeofExpr *rslt; 2131 if (old->expr) { 2132 assert(!old->isType); 2133 rslt = new ast::SizeofExpr( 2134 old->location, 2135 GET_ACCEPT_1(expr, Expr) 2136 ); 2137 } 2138 if (old->type) { 2139 assert(old->isType); 2140 rslt = new ast::SizeofExpr( 2141 old->location, 2142 GET_ACCEPT_1(type, Type) 2143 ); 2144 } 2145 this->node = visitBaseExpr( old, rslt ); 2146 } 2147 2148 virtual void visit( AlignofExpr * old ) override final { 2149 assert (old->expr || old->type); 2150 assert (! (old->expr && old->type)); 2151 ast::AlignofExpr *rslt; 2152 if (old->expr) { 2153 assert(!old->isType); 2154 rslt = new ast::AlignofExpr( 2155 old->location, 2156 GET_ACCEPT_1(expr, Expr) 2157 ); 2158 } 2159 if (old->type) { 2160 assert(old->isType); 2161 rslt = new ast::AlignofExpr( 2162 old->location, 2163 GET_ACCEPT_1(type, Type) 2164 ); 2165 } 2166 this->node = visitBaseExpr( old, rslt ); 2167 } 2168 2169 virtual void visit( UntypedOffsetofExpr * old ) override final { 2170 this->node = visitBaseExpr( old, 2171 new ast::UntypedOffsetofExpr( 2172 old->location, 2173 GET_ACCEPT_1(type, Type), 2174 old->member 2175 ) 2176 ); 2177 } 2178 2179 virtual void visit( OffsetofExpr * old ) override final { 2180 this->node = visitBaseExpr( old, 2181 new ast::OffsetofExpr( 2182 old->location, 2183 GET_ACCEPT_1(type, Type), 2184 inCache(old->member) ? 2185 dynamic_cast<ast::DeclWithType *>(this->node) : 2186 GET_ACCEPT_1(member, DeclWithType) 2187 ) 2188 ); 2189 } 2190 2191 virtual void visit( OffsetPackExpr * old ) override final { 2192 this->node = visitBaseExpr( old, 2193 new ast::OffsetPackExpr( 2194 old->location, 2195 GET_ACCEPT_1(type, StructInstType) 2196 ) 2197 ); 2198 } 2199 2200 virtual void visit( LogicalExpr * old ) override final { 2201 this->node = visitBaseExpr( old, 2202 new ast::LogicalExpr( 2203 old->location, 2204 GET_ACCEPT_1(arg1, Expr), 2205 GET_ACCEPT_1(arg2, Expr), 2206 old->get_isAnd() ? 2207 ast::LogicalFlag::AndExpr : 2208 ast::LogicalFlag::OrExpr 2209 ) 2210 ); 2211 } 2212 2213 virtual void visit( ConditionalExpr * old ) override final { 2214 this->node = visitBaseExpr( old, 2215 new ast::ConditionalExpr( 2216 old->location, 2217 GET_ACCEPT_1(arg1, Expr), 2218 GET_ACCEPT_1(arg2, Expr), 2219 GET_ACCEPT_1(arg3, Expr) 2220 ) 2221 ); 2222 } 2223 2224 virtual void visit( CommaExpr * old ) override final { 2225 this->node = visitBaseExpr( old, 2226 new ast::CommaExpr( 2227 old->location, 2228 GET_ACCEPT_1(arg1, Expr), 2229 GET_ACCEPT_1(arg2, Expr) 2230 ) 2231 ); 2232 } 2233 2234 virtual void visit( TypeExpr * old ) override final { 2235 this->node = visitBaseExpr( old, 2236 new ast::TypeExpr( 2237 old->location, 2238 GET_ACCEPT_1(type, Type) 2239 ) 2240 ); 2241 } 2242 2243 virtual void visit( AsmExpr * old ) override final { 2244 this->node = visitBaseExpr( old, 2245 new ast::AsmExpr( 2246 old->location, 2247 GET_ACCEPT_1(inout, Expr), 2248 GET_ACCEPT_1(constraint, Expr), 2249 GET_ACCEPT_1(operand, Expr) 2250 ) 2251 ); 2252 } 2253 2254 virtual void visit( ImplicitCopyCtorExpr * old ) override final { 2255 auto rslt = new ast::ImplicitCopyCtorExpr( 2256 old->location, 2257 GET_ACCEPT_1(callExpr, ApplicationExpr) 2258 ); 2259 2260 this->node = visitBaseExpr( old, rslt ); 2261 } 2262 2263 virtual void visit( ConstructorExpr * old ) override final { 2264 this->node = visitBaseExpr( old, 2265 new ast::ConstructorExpr( 2266 old->location, 2267 GET_ACCEPT_1(callExpr, Expr) 2268 ) 2269 ); 2270 } 2271 2272 virtual void visit( CompoundLiteralExpr * old ) override final { 2273 this->node = visitBaseExpr_SkipResultType( old, 2274 new ast::CompoundLiteralExpr( 2275 old->location, 2276 GET_ACCEPT_1(result, Type), 2277 GET_ACCEPT_1(initializer, Init) 2278 ) 2279 ); 2280 } 2281 2282 virtual void visit( RangeExpr * old ) override final { 2283 this->node = visitBaseExpr( old, 2284 new ast::RangeExpr( 2285 old->location, 2286 GET_ACCEPT_1(low, Expr), 2287 GET_ACCEPT_1(high, Expr) 2288 ) 2289 ); 2290 } 2291 2292 virtual void visit( UntypedTupleExpr * old ) override final { 2293 this->node = visitBaseExpr( old, 2294 new ast::UntypedTupleExpr( 2295 old->location, 2296 GET_ACCEPT_V(exprs, Expr) 2297 ) 2298 ); 2299 } 2300 2301 virtual void visit( TupleExpr * old ) override final { 2302 this->node = visitBaseExpr( old, 2303 new ast::TupleExpr( 2304 old->location, 2305 GET_ACCEPT_V(exprs, Expr) 2306 ) 2307 ); 2308 } 2309 2310 virtual void visit( TupleIndexExpr * old ) override final { 2311 this->node = visitBaseExpr( old, 2312 new ast::TupleIndexExpr( 2313 old->location, 2314 GET_ACCEPT_1(tuple, Expr), 2315 old->index 2316 ) 2317 ); 2318 } 2319 2320 virtual void visit( TupleAssignExpr * old ) override final { 2321 this->node = visitBaseExpr_SkipResultType( old, 2322 new ast::TupleAssignExpr( 2323 old->location, 2324 GET_ACCEPT_1(result, Type), 2325 GET_ACCEPT_1(stmtExpr, StmtExpr) 2326 ) 2327 ); 2328 } 2329 2330 virtual void visit( StmtExpr * old ) override final { 2331 auto rslt = new ast::StmtExpr( 2332 old->location, 2333 GET_ACCEPT_1(statements, CompoundStmt) 2334 ); 2335 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2336 rslt->dtors = GET_ACCEPT_V(dtors , Expr); 2337 2338 this->node = visitBaseExpr_SkipResultType( old, rslt ); 2339 } 2340 2341 virtual void visit( UniqueExpr * old ) override final { 2342 auto rslt = new ast::UniqueExpr( 2343 old->location, 2344 GET_ACCEPT_1(expr, Expr) 2345 ); 2346 rslt->object = GET_ACCEPT_1(object, ObjectDecl); 2347 rslt->var = GET_ACCEPT_1(var , VariableExpr); 2348 2349 this->node = visitBaseExpr( old, rslt ); 2350 } 2351 2352 virtual void visit( UntypedInitExpr * old ) override final { 2353 std::vector<ast::InitAlternative> initAlts; 2354 for (auto ia : old->initAlts) { 2355 initAlts.push_back(ast::InitAlternative( 2356 getAccept1< ast::Type, Type * >( ia.type ), 2357 getAccept1< ast::Designation, Designation * >( ia.designation ) 2358 )); 2359 } 2360 this->node = visitBaseExpr( old, 2361 new ast::UntypedInitExpr( 2362 old->location, 2363 GET_ACCEPT_1(expr, Expr), 2364 std::move(initAlts) 2365 ) 2366 ); 2367 } 2368 2369 virtual void visit( InitExpr * old ) override final { 2370 this->node = visitBaseExpr( old, 2371 new ast::InitExpr( 2372 old->location, 2373 GET_ACCEPT_1(expr, Expr), 2374 GET_ACCEPT_1(designation, Designation) 2375 ) 2376 ); 2377 } 2378 2379 virtual void visit( DeletedExpr * old ) override final { 2380 this->node = visitBaseExpr( old, 2381 new ast::DeletedExpr( 2382 old->location, 2383 GET_ACCEPT_1(expr, Expr), 2384 inCache(old->deleteStmt) ? 2385 this->node : 2386 GET_ACCEPT_1(deleteStmt, Node) 2387 ) 2388 ); 2389 } 2390 2391 virtual void visit( DefaultArgExpr * old ) override final { 2392 this->node = visitBaseExpr( old, 2393 new ast::DefaultArgExpr( 2394 old->location, 2395 GET_ACCEPT_1(expr, Expr) 2396 ) 2397 ); 2398 } 2399 2400 virtual void visit( GenericExpr * old ) override final { 2401 std::vector<ast::GenericExpr::Association> associations; 2402 for (auto association : old->associations) { 2403 associations.push_back(ast::GenericExpr::Association( 2404 getAccept1< ast::Type, Type * >( association.type ), 2405 getAccept1< ast::Expr, Expression * >( association.expr ) 2406 )); 2407 } 2408 this->node = visitBaseExpr( old, 2409 new ast::GenericExpr( 2410 old->location, 2411 GET_ACCEPT_1(control, Expr), 2412 std::move(associations) 2413 ) 2414 ); 2415 } 2416 2417 virtual void visit( VoidType * old ) override final { 2418 this->node = new ast::VoidType{ cv( old ) }; 2419 } 2420 2421 virtual void visit( BasicType * old ) override final { 2422 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) }; 2423 } 2424 2425 virtual void visit( PointerType * old ) override final { 2426 this->node = new ast::PointerType{ 2427 GET_ACCEPT_1( base, Type ), 2428 GET_ACCEPT_1( dimension, Expr ), 2429 (ast::LengthFlag)old->isVarLen, 2430 (ast::DimensionFlag)old->isStatic, 2431 cv( old ) 2432 }; 2433 } 2434 2435 virtual void visit( ArrayType * old ) override final { 2436 this->node = new ast::ArrayType{ 2437 GET_ACCEPT_1( base, Type ), 2438 GET_ACCEPT_1( dimension, Expr ), 2439 (ast::LengthFlag)old->isVarLen, 2440 (ast::DimensionFlag)old->isStatic, 2441 cv( old ) 2442 }; 2443 } 2444 2445 virtual void visit( ReferenceType * old ) override final { 2446 this->node = new ast::ReferenceType{ 2447 GET_ACCEPT_1( base, Type ), 2448 cv( old ) 2449 }; 2450 } 2451 2452 virtual void visit( QualifiedType * old ) override final { 2453 this->node = new ast::QualifiedType{ 2454 GET_ACCEPT_1( parent, Type ), 2455 GET_ACCEPT_1( child, Type ), 2456 cv( old ) 2457 }; 2458 } 2459 2460 virtual void visit( FunctionType * old ) override final { 2461 auto ty = new ast::FunctionType { 2462 (ast::ArgumentFlag)old->isVarArgs, 2463 cv( old ) 2464 }; 2465 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 2466 ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2467 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2468 this->node = ty; 2469 } 2470 2471 void postvisit( ReferenceToType * old, ast::ReferenceToType * ty ) { 2472 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2473 ty->params = GET_ACCEPT_V( parameters, Expr ); 2474 ty->hoistType = old->hoistType; 2475 } 2476 2477 virtual void visit( StructInstType * old ) override final { 2478 ast::StructInstType * ty; 2479 if ( old->baseStruct ) { 2480 ty = new ast::StructInstType{ 2481 GET_ACCEPT_1( baseStruct, StructDecl ), 2482 cv( old ), 2483 GET_ACCEPT_V( attributes, Attribute ) 2484 }; 2485 } else { 2486 ty = new ast::StructInstType{ 2487 old->name, 2488 cv( old ), 2489 GET_ACCEPT_V( attributes, Attribute ) 2490 }; 2491 } 2492 postvisit( old, ty ); 2493 this->node = ty; 2494 } 2495 2496 virtual void visit( UnionInstType * old ) override final { 2497 ast::UnionInstType * ty; 2498 if ( old->baseUnion ) { 2499 ty = new ast::UnionInstType{ 2500 GET_ACCEPT_1( baseUnion, UnionDecl ), 2501 cv( old ), 2502 GET_ACCEPT_V( attributes, Attribute ) 2503 }; 2504 } else { 2505 ty = new ast::UnionInstType{ 2506 old->name, 2507 cv( old ), 2508 GET_ACCEPT_V( attributes, Attribute ) 2509 }; 2510 } 2511 postvisit( old, ty ); 2512 this->node = ty; 2513 } 2514 2515 virtual void visit( EnumInstType * old ) override final { 2516 ast::EnumInstType * ty; 2517 if ( old->baseEnum ) { 2518 ty = new ast::EnumInstType{ 2519 GET_ACCEPT_1( baseEnum, EnumDecl ), 2520 cv( old ), 2521 GET_ACCEPT_V( attributes, Attribute ) 2522 }; 2523 } else { 2524 ty = new ast::EnumInstType{ 2525 old->name, 2526 cv( old ), 2527 GET_ACCEPT_V( attributes, Attribute ) 2528 }; 2529 } 2530 postvisit( old, ty ); 2531 this->node = ty; 2532 } 2533 2534 virtual void visit( TraitInstType * old ) override final { 2535 ast::TraitInstType * ty; 2536 if ( old->baseTrait ) { 2537 ty = new ast::TraitInstType{ 2538 GET_ACCEPT_1( baseTrait, TraitDecl ), 2539 cv( old ), 2540 GET_ACCEPT_V( attributes, Attribute ) 2541 }; 2542 } else { 2543 ty = new ast::TraitInstType{ 2544 old->name, 2545 cv( old ), 2546 GET_ACCEPT_V( attributes, Attribute ) 2547 }; 2548 } 2549 postvisit( old, ty ); 2550 this->node = ty; 2551 } 2552 2553 virtual void visit( TypeInstType * old ) override final { 2554 ast::TypeInstType * ty; 2555 if ( old->baseType ) { 2556 ty = new ast::TypeInstType{ 2557 old->name, 2558 GET_ACCEPT_1( baseType, TypeDecl ), 2559 cv( old ), 2560 GET_ACCEPT_V( attributes, Attribute ) 2561 }; 2562 } else { 2563 ty = new ast::TypeInstType{ 2564 old->name, 2565 old->isFtype ? ast::TypeVar::Ftype : ast::TypeVar::Dtype, 2566 cv( old ), 2567 GET_ACCEPT_V( attributes, Attribute ) 2568 }; 2569 } 2570 postvisit( old, ty ); 2571 this->node = ty; 2572 } 2573 2574 virtual void visit( TupleType * old ) override final { 2575 this->node = new ast::TupleType{ 2576 GET_ACCEPT_V( types, Type ), 2577 // members generated by TupleType c'tor 2578 cv( old ) 2579 }; 2580 } 2581 2582 virtual void visit( TypeofType * old ) override final { 2583 this->node = new ast::TypeofType{ 2584 GET_ACCEPT_1( expr, Expr ), 2585 (ast::TypeofType::Kind)old->is_basetypeof, 2586 cv( old ) 2587 }; 1225 virtual void visit( CastExpr * ) override final { 1226 // TODO ... (rest) 1227 } 1228 1229 virtual void visit( KeywordCastExpr * ) override final { 1230 1231 } 1232 1233 virtual void visit( VirtualCastExpr * ) override final { 1234 1235 } 1236 1237 virtual void visit( AddressExpr * ) override final { 1238 1239 } 1240 1241 virtual void visit( LabelAddressExpr * ) override final { 1242 1243 } 1244 1245 virtual void visit( UntypedMemberExpr * ) override final { 1246 1247 } 1248 1249 virtual void visit( MemberExpr * ) override final { 1250 1251 } 1252 1253 virtual void visit( VariableExpr * ) override final { 1254 1255 } 1256 1257 virtual void visit( ConstantExpr * ) override final { 1258 1259 } 1260 1261 virtual void visit( SizeofExpr * ) override final { 1262 1263 } 1264 1265 virtual void visit( AlignofExpr * ) override final { 1266 1267 } 1268 1269 virtual void visit( UntypedOffsetofExpr * ) override final { 1270 1271 } 1272 1273 virtual void visit( OffsetofExpr * ) override final { 1274 1275 } 1276 1277 virtual void visit( OffsetPackExpr * ) override final { 1278 1279 } 1280 1281 virtual void visit( LogicalExpr * ) override final { 1282 1283 } 1284 1285 virtual void visit( ConditionalExpr * ) override final { 1286 1287 } 1288 1289 virtual void visit( CommaExpr * ) override final { 1290 1291 } 1292 1293 virtual void visit( TypeExpr * ) override final { 1294 1295 } 1296 1297 virtual void visit( AsmExpr * ) override final { 1298 1299 } 1300 1301 virtual void visit( ImplicitCopyCtorExpr * ) override final { 1302 1303 } 1304 1305 virtual void visit( ConstructorExpr * ) override final { 1306 1307 } 1308 1309 virtual void visit( CompoundLiteralExpr * ) override final { 1310 1311 } 1312 1313 virtual void visit( RangeExpr * ) override final { 1314 1315 } 1316 1317 virtual void visit( UntypedTupleExpr * ) override final { 1318 1319 } 1320 1321 virtual void visit( TupleExpr * ) override final { 1322 1323 } 1324 1325 virtual void visit( TupleIndexExpr * ) override final { 1326 1327 } 1328 1329 virtual void visit( TupleAssignExpr * ) override final { 1330 1331 } 1332 1333 virtual void visit( StmtExpr * ) override final { 1334 1335 } 1336 1337 virtual void visit( UniqueExpr * ) override final { 1338 1339 } 1340 1341 virtual void visit( UntypedInitExpr * ) override final { 1342 1343 } 1344 1345 virtual void visit( InitExpr * ) override final { 1346 1347 } 1348 1349 virtual void visit( DeletedExpr * ) override final { 1350 1351 } 1352 1353 virtual void visit( DefaultArgExpr * ) override final { 1354 1355 } 1356 1357 virtual void visit( GenericExpr * ) override final { 1358 1359 } 1360 1361 virtual void visit( VoidType * ) override final { 1362 1363 } 1364 1365 virtual void visit( BasicType * ) override final { 1366 1367 } 1368 1369 virtual void visit( PointerType * ) override final { 1370 1371 } 1372 1373 virtual void visit( ArrayType * ) override final { 1374 1375 } 1376 1377 virtual void visit( ReferenceType * ) override final { 1378 1379 } 1380 1381 virtual void visit( QualifiedType * ) override final { 1382 1383 } 1384 1385 virtual void visit( FunctionType * ) override final { 1386 1387 } 1388 1389 virtual void visit( StructInstType * ) override final { 1390 1391 } 1392 1393 virtual void visit( UnionInstType * ) override final { 1394 1395 } 1396 1397 virtual void visit( EnumInstType * ) override final { 1398 1399 } 1400 1401 virtual void visit( TraitInstType * ) override final { 1402 1403 } 1404 1405 virtual void visit( TypeInstType * ) override final { 1406 1407 } 1408 1409 virtual void visit( TupleType * ) override final { 1410 1411 } 1412 1413 virtual void visit( TypeofType * ) override final { 1414 2588 1415 } 2589 1416 2590 1417 virtual void visit( AttrType * ) override final { 2591 assertf( false, "AttrType deprecated in new AST." ); 2592 } 2593 2594 virtual void visit( VarArgsType * old) override final {2595 this->node = new ast::VarArgsType{ cv( old ) }; 2596 } 2597 2598 virtual void visit( ZeroType * old) override final {2599 this->node = new ast::ZeroType{ cv( old ) }; 2600 } 2601 2602 virtual void visit( OneType * old) override final {2603 this->node = new ast::OneType{ cv( old ) }; 1418 1419 } 1420 1421 virtual void visit( VarArgsType * ) override final { 1422 1423 } 1424 1425 virtual void visit( ZeroType * ) override final { 1426 1427 } 1428 1429 virtual void visit( OneType * ) override final { 1430 2604 1431 } 2605 1432 2606 1433 virtual void visit( GlobalScopeType * ) override final { 2607 this->node = new ast::GlobalScopeType{}; 2608 } 2609 2610 virtual void visit( Designation * old ) override final { 2611 this->node = new ast::Designation( 2612 old->location, 2613 GET_ACCEPT_V(designators, Expr) 2614 ); 2615 } 2616 2617 virtual void visit( SingleInit * old ) override final { 2618 this->node = new ast::SingleInit( 2619 old->location, 2620 GET_ACCEPT_1(value, Expr), 2621 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2622 ); 2623 } 2624 2625 virtual void visit( ListInit * old ) override final { 2626 this->node = new ast::ListInit( 2627 old->location, 2628 GET_ACCEPT_V(initializers, Init), 2629 GET_ACCEPT_V(designations, Designation), 2630 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2631 ); 2632 } 2633 2634 virtual void visit( ConstructorInit * old ) override final { 2635 this->node = new ast::ConstructorInit( 2636 old->location, 2637 GET_ACCEPT_1(ctor, Stmt), 2638 GET_ACCEPT_1(dtor, Stmt), 2639 GET_ACCEPT_1(init, Init) 2640 ); 1434 1435 } 1436 1437 virtual void visit( Designation * ) override final { 1438 1439 } 1440 1441 virtual void visit( SingleInit * ) override final { 1442 1443 } 1444 1445 virtual void visit( ListInit * ) override final { 1446 1447 } 1448 1449 virtual void visit( ConstructorInit * ) override final { 1450 2641 1451 } 2642 1452 2643 1453 virtual void visit( Constant * ) override final { 2644 // Handled in visit( ConstantEpxr * ). 2645 // In the new tree, Constant fields are inlined into containing ConstantExpression. 1454 1455 } 1456 1457 virtual void visit( Attribute * ) override final { 1458 1459 } 1460 1461 virtual void visit( AttrExpr * ) override final { 1462 2646 1463 assert( 0 ); 2647 }2648 2649 virtual void visit( Attribute * old ) override final {2650 this->node = new ast::Attribute(2651 old->name,2652 GET_ACCEPT_V( parameters, Expr )2653 );2654 }2655 2656 virtual void visit( AttrExpr * ) override final {2657 assertf( false, "AttrExpr deprecated in new AST." );2658 1464 } 2659 1465 }; … … 2669 1475 d->accept( c ); 2670 1476 decls.emplace_back( c.decl() ); 2671 }2672 deleteAll(translationUnit);1477 delete d; 1478 } 2673 1479 return decls; 2674 1480 } -
src/AST/Decl.cpp
rd908563 r933f32f 72 72 // --- EnumDecl 73 73 74 bool EnumDecl::valueOf( const Decl* enumerator, long long& value ) const {74 bool EnumDecl::valueOf( Decl* enumerator, long long& value ) const { 75 75 if ( enumValues.empty() ) { 76 76 long long crntVal = 0; 77 for ( const Decl 77 for ( const Decl* member : members ) { 78 78 const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member ); 79 79 if ( field->init ) { … … 81 81 auto result = eval( init->value ); 82 82 if ( ! result.second ) { 83 SemanticError( init->location, ::toString( "Non-constexpr in initialization of "83 SemanticError( init->location, toString( "Non-constexpr in initialization of " 84 84 "enumerator: ", field ) ); 85 85 } … … 87 87 } 88 88 if ( enumValues.count( field->name ) != 0 ) { 89 SemanticError( location, ::toString( "Enum ", name, " has multiple members with the " "name ", field->name ) );89 SemanticError( location, toString( "Enum ", name, " has multiple members with the " "name ", field->name ) ); 90 90 } 91 91 enumValues[ field->name ] = crntVal; -
src/AST/Decl.hpp
rd908563 r933f32f 232 232 AggregateDecl* set_body( bool b ) { body = b; return this; } 233 233 234 private: 235 AggregateDecl * clone() const override = 0; 236 MUTATE_FRIEND 237 238 protected: 234 239 /// Produces a name for the kind of aggregate 235 240 virtual std::string typeString() const = 0; 236 237 private:238 AggregateDecl * clone() const override = 0;239 MUTATE_FRIEND240 241 }; 241 242 … … 255 256 256 257 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 258 private: 259 StructDecl * clone() const override { return new StructDecl{ *this }; } 260 MUTATE_FRIEND 257 261 258 262 std::string typeString() const override { return "struct"; } 259 260 private:261 StructDecl * clone() const override { return new StructDecl{ *this }; }262 MUTATE_FRIEND263 263 }; 264 264 … … 271 271 272 272 const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 273 private: 274 UnionDecl * clone() const override { return new UnionDecl{ *this }; } 275 MUTATE_FRIEND 273 276 274 277 std::string typeString() const override { return "union"; } 275 276 private:277 UnionDecl * clone() const override { return new UnionDecl{ *this }; }278 MUTATE_FRIEND279 278 }; 280 279 … … 287 286 288 287 /// gets the integer value for this enumerator, returning true iff value found 289 bool valueOf( const Decl * enumerator, long long& value ) const; 290 291 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 288 bool valueOf( Decl* enumerator, long long& value ) const; 289 290 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 291 private: 292 EnumDecl * clone() const override { return new EnumDecl{ *this }; } 293 MUTATE_FRIEND 292 294 293 295 std::string typeString() const override { return "enum"; } 294 295 private:296 EnumDecl * clone() const override { return new EnumDecl{ *this }; }297 MUTATE_FRIEND298 296 299 297 /// Map from names to enumerator values; kept private for lazy initialization … … 309 307 310 308 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 309 private: 310 TraitDecl * clone() const override { return new TraitDecl{ *this }; } 311 MUTATE_FRIEND 311 312 312 313 std::string typeString() const override { return "trait"; } 313 314 private:315 TraitDecl * clone() const override { return new TraitDecl{ *this }; }316 MUTATE_FRIEND317 314 }; 318 315 … … 332 329 class StaticAssertDecl : public Decl { 333 330 public: 334 ptr<Expr> cond ;331 ptr<Expr> condition; 335 332 ptr<ConstantExpr> msg; // string literal 336 333 337 334 StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg ) 338 : Decl( loc, "", {}, {} ), cond ( condition ), msg( msg ) {}335 : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {} 339 336 340 337 const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); } -
src/AST/DeclReplacer.cpp
rd908563 r933f32f 14 14 // 15 15 16 #include "DeclReplacer.hpp" 17 #include "Expr.hpp" 18 #include "Type.hpp" 19 20 #include "Pass.hpp" 21 22 namespace ast { 23 24 namespace DeclReplacer { 25 namespace { 26 struct DeclReplacer { 27 private: 28 const DeclMap & declMap; 29 const TypeMap & typeMap; 30 bool debug; 31 32 public: 33 DeclReplacer(const DeclMap & declMap, const TypeMap & typeMap, bool debug) 34 : declMap( declMap ), typeMap( typeMap ), debug( debug ) 35 {} 36 37 const ast::VariableExpr * previsit( const ast::VariableExpr * ); 38 const ast::TypeInstType * previsit( const ast::TypeInstType * ); 39 }; 40 } 41 42 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 43 if(!node) return nullptr; 44 Pass<DeclReplacer> replacer = { declMap, typeMap, debug }; 45 return node->accept( replacer ); 46 } 47 48 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug ) { 49 TypeMap typeMap; 50 return replace( node, declMap, typeMap, debug ); 51 } 52 53 const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) { 54 DeclMap declMap; 55 return replace( node, declMap, typeMap, debug ); 56 } 57 58 namespace { 59 // replace variable with new node from decl map 60 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) { 61 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 62 if ( !declMap.count( varExpr->var ) ) return varExpr; 63 64 auto replacement = declMap.at( varExpr->var ); 65 if ( debug ) { 66 std::cerr << "replacing variable reference: " 67 << (void*)varExpr->var.get() << " " << varExpr->var 68 << " with " << (void*)replacement << " " << replacement 69 << std::endl; 70 } 71 auto nexpr = mutate(varExpr); 72 nexpr->var = replacement; 73 return nexpr; 74 } 75 76 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) { 77 if ( !typeMap.count( inst->base ) ) return inst; 78 79 auto replacement = typeMap.at( inst->base ); 80 if ( debug ) { 81 std::cerr << "replacing type reference: " 82 << (void*)inst->base.get() << " " << inst->base 83 << " with " << (void*)replacement << " " << replacement 84 << std::endl; 85 } 86 auto ninst = mutate(inst); 87 ninst->base = replacement; 88 return ninst; 89 } 90 } 91 } 92 93 } 16 #warning unimplemented 94 17 95 18 // Local Variables: // -
src/AST/DeclReplacer.hpp
rd908563 r933f32f 25 25 26 26 namespace DeclReplacer { 27 using DeclMap = std::unordered_map< const DeclWithType *, const DeclWithType* >;28 using TypeMap = std::unordered_map< const TypeDecl *, const TypeDecl* >;27 using DeclMap = std::unordered_map< DeclWithType*, DeclWithType* >; 28 using TypeMap = std::unordered_map< TypeDecl*, TypeDecl* >; 29 29 30 const Node * replace( const Node * node, const DeclMap & declMap, bool debug = false);31 const Node * replace( const Node * node, const TypeMap & typeMap, bool debug = false);32 const Node * replace( const Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false);30 void replace( Node* node, const DeclMap& declMap ); 31 void replace( Node* node, const TypeMap& typeMap ); 32 void replace( Node* node, const DeclMap& declMap, const TypeMap& typeMap ); 33 33 } 34 34 } -
src/AST/Expr.cpp
rd908563 r933f32f 20 20 #include <vector> 21 21 22 #include "GenericSubstitution.hpp"23 22 #include "Stmt.hpp" 24 23 #include "Type.hpp" 25 #include "TypeSubstitution.hpp"26 #include "Common/utility.h"27 24 #include "Common/SemanticError.h" 28 25 #include "GenPoly/Lvalue.h" // for referencesPermissable … … 159 156 assert( aggregate->result ); 160 157 161 // take ownership of member type 162 result = mem->get_type(); 163 // substitute aggregate generic parameters into member type 164 genericSubsitution( aggregate->result ).apply( result ); 165 // ensure lvalue and appropriate restrictions from aggregate type 166 result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue; 158 assert(!"unimplemented; need TypeSubstitution, genericSubstitution"); 167 159 } 168 160 … … 241 233 FixedLen, DynamicDim }, 242 234 std::string{"\""} + s + "\"", 243 (unsigned long long)0, 244 ConstantExpr::String }; 235 (unsigned long long)0 }; 245 236 } 246 237 … … 341 332 stmts.emplace_back( new ExprStmt{ loc, tupleExpr } ); 342 333 stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } }; 343 }344 345 TupleAssignExpr::TupleAssignExpr(346 const CodeLocation & loc, const Type * result, const StmtExpr * s )347 : Expr( loc, result ), stmtExpr() {348 stmtExpr = s;349 334 } 350 335 -
src/AST/Expr.hpp
rd908563 r933f32f 30 30 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 31 31 32 class ConverterOldToNew;33 34 32 namespace ast { 35 33 … … 108 106 case Params: assert(!"Cannot return to resnSlots from Params"); 109 107 } 110 return *((ResnSlots*)nullptr);111 }112 113 const ResnSlots& resnSlotsConst() const {114 if (mode == Slots) {115 return data.resnSlots;116 }117 assert(!"Mode was not already resnSlots");118 return *((ResnSlots*)nullptr);119 108 } 120 109 … … 125 114 case Params: return data.inferParams; 126 115 } 127 return *((InferredParams*)nullptr);128 }129 130 const InferredParams& inferParamsConst() const {131 if (mode == Params) {132 return data.inferParams;133 }134 assert(!"Mode was not already Params");135 return *((InferredParams*)nullptr);136 116 } 137 117 }; … … 337 317 public: 338 318 std::string rep; 339 enum Kind { Integer, FloatingPoint, String } kind;340 319 341 320 ConstantExpr( 342 const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v, 343 Kind k = Integer ) 344 : Expr( loc, ty ), val( v ), rep( r ), kind( k ) {} 321 const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v ) 322 : Expr( loc, ty ), val( v ), rep( r ) {} 345 323 ConstantExpr( const CodeLocation & loc, const Type * ty, const std::string & r, double v ) 346 : Expr( loc, ty ), val( v ), rep( r ) , kind( FloatingPoint ){}324 : Expr( loc, ty ), val( v ), rep( r ) {} 347 325 348 326 /// Gets the value of this constant as an integer … … 525 503 }; 526 504 527 /// The application of a function to a set of parameters, along with a set of copy constructor 505 /// The application of a function to a set of parameters, along with a set of copy constructor 528 506 /// calls, one for each argument 529 507 class ImplicitCopyCtorExpr final : public Expr { 530 508 public: 531 509 ptr<ApplicationExpr> callExpr; 510 std::vector<ptr<ObjectDecl>> tempDecls; 511 std::vector<ptr<ObjectDecl>> returnDecls; 512 std::vector<ptr<ObjectDecl>> dtors; 532 513 533 514 ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call ) 534 : Expr( loc, call->result ) { assert( call ); }515 : Expr( loc, call->result ), tempDecls(), returnDecls(), dtors() { assert( call ); } 535 516 536 517 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } … … 622 603 }; 623 604 624 /// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression. 625 /// multiple-assignment: both sides of the assignment have tuple type, 605 /// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression. 606 /// multiple-assignment: both sides of the assignment have tuple type, 626 607 /// e.g. `[a, b, c] = [d, e, f];` 627 608 /// mass-assignment: left-hand side has tuple type and right-hand side does not: … … 631 612 ptr<StmtExpr> stmtExpr; 632 613 633 TupleAssignExpr( 634 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 614 TupleAssignExpr( 615 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 635 616 std::vector<ptr<ObjectDecl>> && tempDecls ); 636 637 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 638 639 friend class ::ConverterOldToNew; 640 617 618 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 641 619 private: 642 620 TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; } 643 TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );644 645 621 MUTATE_FRIEND 646 622 }; -
src/AST/Fwd.hpp
rd908563 r933f32f 131 131 class TypeSubstitution; 132 132 133 std::string toString( const Node * ); 134 135 template < typename ... Params > 136 std::string toString( const Params & ... params ); 137 133 138 typedef unsigned int UniqueId; 134 139 -
src/AST/Label.hpp
rd908563 r933f32f 39 39 40 40 operator std::string () const { return name; } 41 bool empty() const{ return name.empty(); }41 bool empty() { return name.empty(); } 42 42 }; 43 43 -
src/AST/Node.cpp
rd908563 r933f32f 16 16 #include "Node.hpp" 17 17 #include "Fwd.hpp" 18 19 #include <iostream>20 18 21 19 #include "Attribute.hpp" … … 27 25 #include "TypeSubstitution.hpp" 28 26 29 #include "Print.hpp"30 31 27 template< typename node_t, enum ast::Node::ref_type ref_t > 32 28 void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) { node->increment(ref_t); } … … 35 31 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); } 36 32 33 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere. 34 /// Returns a mutable version of the pointer in this node. 37 35 template< typename node_t, enum ast::Node::ref_type ref_t > 38 node_t * ast::ptr_base<node_t, ref_t>::get_and_mutate() { 36 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) { 37 // ensure ownership of `n` by this node to avoid spurious single-owner mutates 38 assign( n ); 39 39 // get mutable version of `n` 40 40 auto r = mutate( node ); … … 42 42 assign( r ); 43 43 return r; 44 }45 46 template< typename node_t, enum ast::Node::ref_type ref_t >47 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {48 // ensure ownership of `n` by this node to avoid spurious single-owner mutates49 assign( n );50 // return mutable version51 return get_and_mutate();52 }53 54 std::ostream & ast::operator<< ( std::ostream & out, const ast::Node * node ) {55 print(out, node);56 return out;57 44 } 58 45 -
src/AST/Node.hpp
rd908563 r933f32f 10 10 // Created On : Wed May 8 10:27:04 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu May 23 16:00:00 201913 // Update Count : 412 // Last Modified On : Wed May 15 16:02:00 2019 13 // Update Count : 3 14 14 // 15 15 … … 94 94 std::ostream& operator<< ( std::ostream& out, const Node * node ); 95 95 96 /// Call a visitor on a possibly-null node97 template<typename node_t>98 auto maybe_accept( const node_t * n, Visitor & v ) -> decltype( n->accept(v) ) {99 return n ? n->accept( v ) : nullptr;100 }101 102 96 /// Base class for the smart pointer types 103 97 /// should never really be used. … … 108 102 ptr_base( const node_t * n ) : node(n) { if( node ) _inc(node); } 109 103 ~ptr_base() { if( node ) _dec(node); } 110 111 ptr_base( const ptr_base & o ) : node(o.node) {112 if( node ) _inc(node);113 }114 115 ptr_base( ptr_base && o ) : node(o.node) {116 if( node ) _inc(node);117 }118 104 119 105 template< enum Node::ref_type o_ref_t > … … 129 115 template<typename o_node_t> 130 116 ptr_base & operator=( const o_node_t * node ) { 131 assign( node ? strict_dynamic_cast<const node_t *>(node) : nullptr ); 132 return *this; 133 } 134 135 ptr_base & operator=( const ptr_base & o ) { 136 assign(o.node); 137 return *this; 138 } 139 140 ptr_base & operator=( ptr_base && o ) { 141 assign(o.node); 117 assign(strict_dynamic_cast<const node_t *>(node)); 142 118 return *this; 143 119 } … … 164 140 template<typename o_node_t> 165 141 const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); } 166 167 /// Returns a mutable version of the pointer in this node.168 node_t * get_and_mutate();169 142 170 143 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere. -
src/AST/Pass.hpp
rd908563 r933f32f 178 178 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) override final; 179 179 180 template<typename pass_type> 181 friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor ); 180 friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor ); 182 181 private: 183 182 … … 224 223 }; 225 224 226 /// Apply a pass to an entire translation unit227 225 template<typename pass_t> 228 226 void accept_all( std::list< ast::ptr<ast::Decl> > &, ast::Pass<pass_t> & visitor ); -
src/AST/Pass.impl.hpp
rd908563 r933f32f 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ast::Pass.impl.hpp --7 // Pass.impl.hpp -- 8 8 // 9 9 // Author : Thierry Delisle … … 121 121 template< typename pass_t > 122 122 template< typename node_t > 123 auto ast::Pass< pass_t >::call_accept( const node_t * node )123 auto Pass< pass_t >::call_accept( const node_t * node ) 124 124 -> typename std::enable_if< 125 125 !std::is_base_of<ast::Expr, node_t>::value && … … 139 139 140 140 template< typename pass_t > 141 const ast::Expr * ast::Pass< pass_t >::call_accept( const ast::Expr * expr ) {141 const ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) { 142 142 __pedantic_pass_assert( __visit_children() ); 143 143 __pedantic_pass_assert( expr ); … … 152 152 153 153 template< typename pass_t > 154 const ast::Stmt * ast::Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {154 const ast::Stmt * Pass< pass_t >::call_accept( const ast::Stmt * stmt ) { 155 155 __pedantic_pass_assert( __visit_children() ); 156 156 __pedantic_pass_assert( stmt ); … … 204 204 template< typename pass_t > 205 205 template< template <class...> class container_t > 206 container_t< ptr<Stmt> > ast::Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {206 container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { 207 207 __pedantic_pass_assert( __visit_children() ); 208 208 if( statements.empty() ) return {}; … … 270 270 template< typename pass_t > 271 271 template< template <class...> class container_t, typename node_t > 272 container_t< ast::ptr<node_t> > ast::Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {272 container_t< ast::ptr<node_t> > Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { 273 273 __pedantic_pass_assert( __visit_children() ); 274 274 if( container.empty() ) return {}; … … 301 301 template< typename pass_t > 302 302 template<typename node_t, typename parent_t, typename child_t> 303 void ast::Pass< pass_t >::maybe_accept(303 void Pass< pass_t >::maybe_accept( 304 304 const node_t * & parent, 305 305 child_t parent_t::*child … … 571 571 __pass::indexer::addType( pass, 0, node ); 572 572 573 VISIT( maybe_accept( node, &TypedefDecl::assertions ); )573 maybe_accept( node, &TypedefDecl::assertions ); 574 574 575 575 VISIT_END( Decl, node ); … … 596 596 597 597 VISIT( 598 maybe_accept( node, &StaticAssertDecl::cond );599 maybe_accept( node, &StaticAssertDecl::msg );598 maybe_accept( node, &StaticAssertDecl::condition ); 599 maybe_accept( node, &StaticAssertDecl::msg ); 600 600 ) 601 601 … … 626 626 // ExprStmt 627 627 template< typename pass_t > 628 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ExprStmt * node ) {628 const ast::Stmt * ast::Pass< pass_t >::visit( const ExprStmt * node ) { 629 629 VISIT_START( node ); 630 630 … … 666 666 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::IfStmt * node ) { 667 667 VISIT_START( node ); 668 669 668 VISIT({ 670 669 // if statements introduce a level of scope (for the initialization) … … 675 674 maybe_accept( node, &IfStmt::elsePart ); 676 675 }) 677 678 676 VISIT_END( Stmt, node ); 679 677 } … … 682 680 // WhileStmt 683 681 template< typename pass_t > 684 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WhileStmt * node ) {682 const ast::Stmt * ast::Pass< pass_t >::visit( const WhileStmt * node ) { 685 683 VISIT_START( node ); 686 684 … … 835 833 // } 836 834 837 VISIT({838 std::vector<WaitForStmt::Clause> new_clauses;839 new_clauses.reserve( node->clauses.size() );840 bool mutated = false;841 for( const auto & clause : node->clauses ) {842 843 const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;844 if(func != clause.target.func) mutated = true;845 846 std::vector<ptr<Expr>> new_args;847 new_args.reserve(clause.target.args.size());848 for( const auto & arg : clause.target.args ) {849 auto a = arg->accept(*this);850 new_args.push_back( a );851 if( a != arg ) mutated = true;852 }853 854 const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;855 if(stmt != clause.stmt) mutated = true;856 857 const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;858 if(cond != clause.cond) mutated = true;859 860 new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } );861 }862 863 if(mutated) {864 auto n = mutate(node);865 n->clauses = std::move( new_clauses );866 node = n;867 }868 })869 870 835 #define maybe_accept(field) \ 871 836 if(node->field) { \ … … 945 910 } 946 911 947 //-------------------------------------------------------------------------- 948 // ApplicationExpr 949 template< typename pass_t > 950 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ApplicationExpr * node ) { 951 VISIT_START( node ); 952 953 VISIT( 954 { 955 guard_indexer guard { *this }; 956 maybe_accept( node, &ApplicationExpr::result ); 957 } 958 maybe_accept( node, &ApplicationExpr::func ); 959 maybe_accept( node, &ApplicationExpr::args ); 960 ) 961 962 VISIT_END( Expr, node ); 963 } 964 965 //-------------------------------------------------------------------------- 966 // UntypedExpr 967 template< typename pass_t > 968 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedExpr * node ) { 969 VISIT_START( node ); 970 971 VISIT( 972 { 973 guard_indexer guard { *this }; 974 maybe_accept( node, &UntypedExpr::result ); 975 } 976 977 maybe_accept( node, &UntypedExpr::args ); 978 ) 979 980 VISIT_END( Expr, node ); 981 } 982 983 //-------------------------------------------------------------------------- 984 // NameExpr 985 template< typename pass_t > 986 const ast::Expr * ast::Pass< pass_t >::visit( const ast::NameExpr * node ) { 987 VISIT_START( node ); 988 989 VISIT({ 990 guard_indexer guard { *this }; 991 maybe_accept( node, &NameExpr::result ); 992 }) 993 994 VISIT_END( Expr, node ); 995 } 996 997 //-------------------------------------------------------------------------- 998 // CastExpr 999 template< typename pass_t > 1000 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CastExpr * node ) { 1001 VISIT_START( node ); 1002 1003 VISIT({ 1004 guard_indexer guard { *this }; 1005 maybe_accept( node, &CastExpr::result ); 1006 } 1007 maybe_accept( node, &CastExpr::arg ); 1008 ) 1009 1010 VISIT_END( Expr, node ); 1011 } 1012 1013 //-------------------------------------------------------------------------- 1014 // KeywordCastExpr 1015 template< typename pass_t > 1016 const ast::Expr * ast::Pass< pass_t >::visit( const ast::KeywordCastExpr * node ) { 1017 VISIT_START( node ); 1018 1019 VISIT({ 1020 guard_indexer guard { *this }; 1021 maybe_accept( node, &KeywordCastExpr::result ); 1022 } 1023 maybe_accept( node, &KeywordCastExpr::arg ); 1024 ) 1025 1026 VISIT_END( Expr, node ); 1027 } 1028 1029 //-------------------------------------------------------------------------- 1030 // VirtualCastExpr 1031 template< typename pass_t > 1032 const ast::Expr * ast::Pass< pass_t >::visit( const ast::VirtualCastExpr * node ) { 1033 VISIT_START( node ); 1034 1035 VISIT({ 1036 guard_indexer guard { *this }; 1037 maybe_accept( node, &VirtualCastExpr::result ); 1038 } 1039 maybe_accept( node, &VirtualCastExpr::arg ); 1040 ) 1041 1042 VISIT_END( Expr, node ); 1043 } 1044 1045 //-------------------------------------------------------------------------- 1046 // AddressExpr 1047 template< typename pass_t > 1048 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AddressExpr * node ) { 1049 VISIT_START( node ); 1050 1051 VISIT({ 1052 guard_indexer guard { *this }; 1053 maybe_accept( node, &AddressExpr::result ); 1054 } 1055 maybe_accept( node, &AddressExpr::arg ); 1056 ) 1057 1058 VISIT_END( Expr, node ); 1059 } 1060 1061 //-------------------------------------------------------------------------- 1062 // LabelAddressExpr 1063 template< typename pass_t > 1064 const ast::Expr * ast::Pass< pass_t >::visit( const ast::LabelAddressExpr * node ) { 1065 VISIT_START( node ); 1066 1067 VISIT({ 1068 guard_indexer guard { *this }; 1069 maybe_accept( node, &LabelAddressExpr::result ); 1070 }) 1071 1072 VISIT_END( Expr, node ); 1073 } 1074 1075 //-------------------------------------------------------------------------- 1076 // UntypedMemberExpr 1077 template< typename pass_t > 1078 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedMemberExpr * node ) { 1079 VISIT_START( node ); 1080 1081 VISIT({ 1082 guard_indexer guard { *this }; 1083 maybe_accept( node, &UntypedMemberExpr::result ); 1084 } 1085 maybe_accept( node, &UntypedMemberExpr::aggregate ); 1086 maybe_accept( node, &UntypedMemberExpr::member ); 1087 ) 1088 1089 VISIT_END( Expr, node ); 1090 } 1091 1092 //-------------------------------------------------------------------------- 1093 // MemberExpr 1094 template< typename pass_t > 1095 const ast::Expr * ast::Pass< pass_t >::visit( const ast::MemberExpr * node ) { 1096 VISIT_START( node ); 1097 1098 VISIT({ 1099 guard_indexer guard { *this }; 1100 maybe_accept( node, &MemberExpr::result ); 1101 } 1102 maybe_accept( node, &MemberExpr::aggregate ); 1103 ) 1104 1105 VISIT_END( Expr, node ); 1106 } 1107 1108 //-------------------------------------------------------------------------- 1109 // VariableExpr 1110 template< typename pass_t > 1111 const ast::Expr * ast::Pass< pass_t >::visit( const ast::VariableExpr * node ) { 1112 VISIT_START( node ); 1113 1114 VISIT({ 1115 guard_indexer guard { *this }; 1116 maybe_accept( node, &VariableExpr::result ); 1117 }) 1118 1119 VISIT_END( Expr, node ); 1120 } 1121 1122 //-------------------------------------------------------------------------- 1123 // ConstantExpr 1124 template< typename pass_t > 1125 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstantExpr * node ) { 1126 VISIT_START( node ); 1127 1128 VISIT({ 1129 guard_indexer guard { *this }; 1130 maybe_accept( node, &ConstantExpr::result ); 1131 }) 1132 1133 VISIT_END( Expr, node ); 1134 } 1135 1136 //-------------------------------------------------------------------------- 1137 // SizeofExpr 1138 template< typename pass_t > 1139 const ast::Expr * ast::Pass< pass_t >::visit( const ast::SizeofExpr * node ) { 1140 VISIT_START( node ); 1141 1142 VISIT({ 1143 guard_indexer guard { *this }; 1144 maybe_accept( node, &SizeofExpr::result ); 1145 } 1146 if ( node->type ) { 1147 maybe_accept( node, &SizeofExpr::type ); 1148 } else { 1149 maybe_accept( node, &SizeofExpr::expr ); 1150 } 1151 ) 1152 1153 VISIT_END( Expr, node ); 1154 } 1155 1156 //-------------------------------------------------------------------------- 1157 // AlignofExpr 1158 template< typename pass_t > 1159 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AlignofExpr * node ) { 1160 VISIT_START( node ); 1161 1162 VISIT({ 1163 guard_indexer guard { *this }; 1164 maybe_accept( node, &AlignofExpr::result ); 1165 } 1166 if ( node->type ) { 1167 maybe_accept( node, &AlignofExpr::type ); 1168 } else { 1169 maybe_accept( node, &AlignofExpr::expr ); 1170 } 1171 ) 1172 1173 VISIT_END( Expr, node ); 1174 } 1175 1176 //-------------------------------------------------------------------------- 1177 // UntypedOffsetofExpr 1178 template< typename pass_t > 1179 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedOffsetofExpr * node ) { 1180 VISIT_START( node ); 1181 1182 VISIT({ 1183 guard_indexer guard { *this }; 1184 maybe_accept( node, &UntypedOffsetofExpr::result ); 1185 } 1186 maybe_accept( node, &UntypedOffsetofExpr::type ); 1187 ) 1188 1189 VISIT_END( Expr, node ); 1190 } 1191 1192 //-------------------------------------------------------------------------- 1193 // OffsetofExpr 1194 template< typename pass_t > 1195 const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetofExpr * node ) { 1196 VISIT_START( node ); 1197 1198 VISIT({ 1199 guard_indexer guard { *this }; 1200 maybe_accept( node, &OffsetofExpr::result ); 1201 } 1202 maybe_accept( node, &OffsetofExpr::type ); 1203 ) 1204 1205 VISIT_END( Expr, node ); 1206 } 1207 1208 //-------------------------------------------------------------------------- 1209 // OffsetPackExpr 1210 template< typename pass_t > 1211 const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetPackExpr * node ) { 1212 VISIT_START( node ); 1213 1214 VISIT({ 1215 guard_indexer guard { *this }; 1216 maybe_accept( node, &OffsetPackExpr::result ); 1217 } 1218 maybe_accept( node, &OffsetPackExpr::type ); 1219 ) 1220 1221 VISIT_END( Expr, node ); 1222 } 1223 1224 //-------------------------------------------------------------------------- 1225 // LogicalExpr 1226 template< typename pass_t > 1227 const ast::Expr * ast::Pass< pass_t >::visit( const ast::LogicalExpr * node ) { 1228 VISIT_START( node ); 1229 1230 VISIT({ 1231 guard_indexer guard { *this }; 1232 maybe_accept( node, &LogicalExpr::result ); 1233 } 1234 maybe_accept( node, &LogicalExpr::arg1 ); 1235 maybe_accept( node, &LogicalExpr::arg2 ); 1236 ) 1237 1238 VISIT_END( Expr, node ); 1239 } 1240 1241 //-------------------------------------------------------------------------- 1242 // ConditionalExpr 1243 template< typename pass_t > 1244 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConditionalExpr * node ) { 1245 VISIT_START( node ); 1246 1247 VISIT({ 1248 guard_indexer guard { *this }; 1249 maybe_accept( node, &ConditionalExpr::result ); 1250 } 1251 maybe_accept( node, &ConditionalExpr::arg1 ); 1252 maybe_accept( node, &ConditionalExpr::arg2 ); 1253 maybe_accept( node, &ConditionalExpr::arg3 ); 1254 ) 1255 1256 VISIT_END( Expr, node ); 1257 } 1258 1259 //-------------------------------------------------------------------------- 1260 // CommaExpr 1261 template< typename pass_t > 1262 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CommaExpr * node ) { 1263 VISIT_START( node ); 1264 1265 VISIT({ 1266 guard_indexer guard { *this }; 1267 maybe_accept( node, &CommaExpr::result ); 1268 } 1269 maybe_accept( node, &CommaExpr::arg1 ); 1270 maybe_accept( node, &CommaExpr::arg2 ); 1271 ) 1272 1273 VISIT_END( Expr, node ); 1274 } 1275 1276 //-------------------------------------------------------------------------- 1277 // TypeExpr 1278 template< typename pass_t > 1279 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TypeExpr * node ) { 1280 VISIT_START( node ); 1281 1282 VISIT({ 1283 guard_indexer guard { *this }; 1284 maybe_accept( node, &TypeExpr::result ); 1285 } 1286 maybe_accept( node, &TypeExpr::type ); 1287 ) 1288 1289 VISIT_END( Expr, node ); 1290 } 1291 1292 //-------------------------------------------------------------------------- 1293 // AsmExpr 1294 template< typename pass_t > 1295 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AsmExpr * node ) { 1296 VISIT_START( node ); 1297 1298 VISIT({ 1299 guard_indexer guard { *this }; 1300 maybe_accept( node, &AsmExpr::result ); 1301 } 1302 maybe_accept( node, &AsmExpr::inout ); 1303 maybe_accept( node, &AsmExpr::constraint ); 1304 maybe_accept( node, &AsmExpr::operand ); 1305 ) 1306 1307 VISIT_END( Expr, node ); 1308 } 1309 1310 //-------------------------------------------------------------------------- 1311 // ImplicitCopyCtorExpr 1312 template< typename pass_t > 1313 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ImplicitCopyCtorExpr * node ) { 1314 VISIT_START( node ); 1315 1316 VISIT({ 1317 guard_indexer guard { *this }; 1318 maybe_accept( node, &ImplicitCopyCtorExpr::result ); 1319 } 1320 maybe_accept( node, &ImplicitCopyCtorExpr::callExpr ); 1321 ) 1322 1323 VISIT_END( Expr, node ); 1324 } 1325 1326 //-------------------------------------------------------------------------- 1327 // ConstructorExpr 1328 template< typename pass_t > 1329 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstructorExpr * node ) { 1330 VISIT_START( node ); 1331 1332 VISIT({ 1333 guard_indexer guard { *this }; 1334 maybe_accept( node, &ConstructorExpr::result ); 1335 } 1336 maybe_accept( node, &ConstructorExpr::callExpr ); 1337 ) 1338 1339 VISIT_END( Expr, node ); 1340 } 1341 1342 //-------------------------------------------------------------------------- 1343 // CompoundLiteralExpr 1344 template< typename pass_t > 1345 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CompoundLiteralExpr * node ) { 1346 VISIT_START( node ); 1347 1348 VISIT({ 1349 guard_indexer guard { *this }; 1350 maybe_accept( node, &CompoundLiteralExpr::result ); 1351 } 1352 maybe_accept( node, &CompoundLiteralExpr::init ); 1353 ) 1354 1355 VISIT_END( Expr, node ); 1356 } 1357 1358 //-------------------------------------------------------------------------- 1359 // RangeExpr 1360 template< typename pass_t > 1361 const ast::Expr * ast::Pass< pass_t >::visit( const ast::RangeExpr * node ) { 1362 VISIT_START( node ); 1363 1364 VISIT({ 1365 guard_indexer guard { *this }; 1366 maybe_accept( node, &RangeExpr::result ); 1367 } 1368 maybe_accept( node, &RangeExpr::low ); 1369 maybe_accept( node, &RangeExpr::high ); 1370 ) 1371 1372 VISIT_END( Expr, node ); 1373 } 1374 1375 //-------------------------------------------------------------------------- 1376 // UntypedTupleExpr 1377 template< typename pass_t > 1378 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedTupleExpr * node ) { 1379 VISIT_START( node ); 1380 1381 VISIT({ 1382 guard_indexer guard { *this }; 1383 maybe_accept( node, &UntypedTupleExpr::result ); 1384 } 1385 maybe_accept( node, &UntypedTupleExpr::exprs ); 1386 ) 1387 1388 VISIT_END( Expr, node ); 1389 } 1390 1391 //-------------------------------------------------------------------------- 1392 // TupleExpr 1393 template< typename pass_t > 1394 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleExpr * node ) { 1395 VISIT_START( node ); 1396 1397 VISIT({ 1398 guard_indexer guard { *this }; 1399 maybe_accept( node, &TupleExpr::result ); 1400 } 1401 maybe_accept( node, &TupleExpr::exprs ); 1402 ) 1403 1404 VISIT_END( Expr, node ); 1405 } 1406 1407 //-------------------------------------------------------------------------- 1408 // TupleIndexExpr 1409 template< typename pass_t > 1410 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleIndexExpr * node ) { 1411 VISIT_START( node ); 1412 1413 VISIT({ 1414 guard_indexer guard { *this }; 1415 maybe_accept( node, &TupleIndexExpr::result ); 1416 } 1417 maybe_accept( node, &TupleIndexExpr::tuple ); 1418 ) 1419 1420 VISIT_END( Expr, node ); 1421 } 1422 1423 //-------------------------------------------------------------------------- 1424 // TupleAssignExpr 1425 template< typename pass_t > 1426 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleAssignExpr * node ) { 1427 VISIT_START( node ); 1428 1429 VISIT({ 1430 guard_indexer guard { *this }; 1431 maybe_accept( node, &TupleAssignExpr::result ); 1432 } 1433 maybe_accept( node, &TupleAssignExpr::stmtExpr ); 1434 ) 1435 1436 VISIT_END( Expr, node ); 1437 } 1438 1439 //-------------------------------------------------------------------------- 1440 // StmtExpr 1441 template< typename pass_t > 1442 const ast::Expr * ast::Pass< pass_t >::visit( const ast::StmtExpr * node ) { 1443 VISIT_START( node ); 1444 1445 VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr 1446 // get the stmts that will need to be spliced in 1447 auto stmts_before = __pass::stmtsToAddBefore( pass, 0); 1448 auto stmts_after = __pass::stmtsToAddAfter ( pass, 0); 1449 1450 // These may be modified by subnode but most be restored once we exit this statemnet. 1451 ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::env( pass, 0) ); 1452 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); 1453 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); 1454 1455 { 1456 guard_indexer guard { *this }; 1457 maybe_accept( node, &StmtExpr::result ); 1458 } 1459 maybe_accept( node, &StmtExpr::stmts ); 1460 maybe_accept( node, &StmtExpr::returnDecls ); 1461 maybe_accept( node, &StmtExpr::dtors ); 1462 ) 1463 1464 VISIT_END( Expr, node ); 1465 } 1466 1467 //-------------------------------------------------------------------------- 1468 // UniqueExpr 1469 template< typename pass_t > 1470 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UniqueExpr * node ) { 1471 VISIT_START( node ); 1472 1473 VISIT({ 1474 guard_indexer guard { *this }; 1475 maybe_accept( node, &UniqueExpr::result ); 1476 } 1477 maybe_accept( node, &UniqueExpr::expr ); 1478 ) 1479 1480 VISIT_END( Expr, node ); 1481 } 1482 1483 //-------------------------------------------------------------------------- 1484 // UntypedInitExpr 1485 template< typename pass_t > 1486 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedInitExpr * node ) { 1487 VISIT_START( node ); 1488 1489 VISIT({ 1490 guard_indexer guard { *this }; 1491 maybe_accept( node, &UntypedInitExpr::result ); 1492 } 1493 maybe_accept( node, &UntypedInitExpr::expr ); 1494 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. 1495 ) 1496 1497 VISIT_END( Expr, node ); 1498 } 1499 1500 //-------------------------------------------------------------------------- 1501 // InitExpr 1502 template< typename pass_t > 1503 const ast::Expr * ast::Pass< pass_t >::visit( const ast::InitExpr * node ) { 1504 VISIT_START( node ); 1505 1506 VISIT({ 1507 guard_indexer guard { *this }; 1508 maybe_accept( node, &InitExpr::result ); 1509 } 1510 maybe_accept( node, &InitExpr::expr ); 1511 maybe_accept( node, &InitExpr::designation ); 1512 ) 1513 1514 VISIT_END( Expr, node ); 1515 } 1516 1517 //-------------------------------------------------------------------------- 1518 // DeletedExpr 1519 template< typename pass_t > 1520 const ast::Expr * ast::Pass< pass_t >::visit( const ast::DeletedExpr * node ) { 1521 VISIT_START( node ); 1522 1523 VISIT({ 1524 guard_indexer guard { *this }; 1525 maybe_accept( node, &DeletedExpr::result ); 1526 } 1527 maybe_accept( node, &DeletedExpr::expr ); 1528 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. 1529 ) 1530 1531 VISIT_END( Expr, node ); 1532 } 1533 1534 //-------------------------------------------------------------------------- 1535 // DefaultArgExpr 1536 template< typename pass_t > 1537 const ast::Expr * ast::Pass< pass_t >::visit( const ast::DefaultArgExpr * node ) { 1538 VISIT_START( node ); 1539 1540 VISIT({ 1541 guard_indexer guard { *this }; 1542 maybe_accept( node, &DefaultArgExpr::result ); 1543 } 1544 maybe_accept( node, &DefaultArgExpr::expr ); 1545 ) 1546 1547 VISIT_END( Expr, node ); 1548 } 1549 1550 //-------------------------------------------------------------------------- 1551 // GenericExpr 1552 template< typename pass_t > 1553 const ast::Expr * ast::Pass< pass_t >::visit( const ast::GenericExpr * node ) { 1554 VISIT_START( node ); 1555 1556 VISIT({ 1557 guard_indexer guard { *this }; 1558 maybe_accept( node, &GenericExpr::result ); 1559 } 1560 maybe_accept( node, &GenericExpr::control ); 1561 1562 std::vector<GenericExpr::Association> new_kids; 1563 new_kids.reserve(node->associations.size()); 1564 bool mutated = false; 1565 for( const auto & assoc : node->associations ) { 1566 const Type * type = nullptr; 1567 if( assoc.type ) { 1568 guard_indexer guard { *this }; 1569 type = assoc.type->accept( *this ); 1570 if( type != assoc.type ) mutated = true; 1571 } 1572 const Expr * expr = nullptr; 1573 if( assoc.expr ) { 1574 expr = assoc.expr->accept( *this ); 1575 if( expr != assoc.expr ) mutated = true; 1576 } 1577 new_kids.emplace_back( type, expr ); 1578 } 1579 1580 if(mutated) { 1581 auto n = mutate(node); 1582 n->associations = std::move( new_kids ); 1583 node = n; 1584 } 1585 ) 1586 1587 VISIT_END( Expr, node ); 1588 } 1589 1590 //-------------------------------------------------------------------------- 1591 // VoidType 1592 template< typename pass_t > 1593 const ast::Type * ast::Pass< pass_t >::visit( const ast::VoidType * node ) { 1594 VISIT_START( node ); 1595 1596 VISIT_END( Type, node ); 1597 } 1598 1599 //-------------------------------------------------------------------------- 1600 // BasicType 1601 template< typename pass_t > 1602 const ast::Type * ast::Pass< pass_t >::visit( const ast::BasicType * node ) { 1603 VISIT_START( node ); 1604 1605 VISIT_END( Type, node ); 1606 } 1607 1608 //-------------------------------------------------------------------------- 1609 // PointerType 1610 template< typename pass_t > 1611 const ast::Type * ast::Pass< pass_t >::visit( const ast::PointerType * node ) { 1612 VISIT_START( node ); 1613 1614 VISIT( 1615 // xxx - should PointerType visit/mutate dimension? 1616 maybe_accept( node, &PointerType::base ); 1617 ) 1618 1619 VISIT_END( Type, node ); 1620 } 1621 1622 //-------------------------------------------------------------------------- 1623 // ArrayType 1624 template< typename pass_t > 1625 const ast::Type * ast::Pass< pass_t >::visit( const ast::ArrayType * node ) { 1626 VISIT_START( node ); 1627 1628 VISIT( 1629 maybe_accept( node, &ArrayType::dimension ); 1630 maybe_accept( node, &ArrayType::base ); 1631 ) 1632 1633 VISIT_END( Type, node ); 1634 } 1635 1636 //-------------------------------------------------------------------------- 1637 // ReferenceType 1638 template< typename pass_t > 1639 const ast::Type * ast::Pass< pass_t >::visit( const ast::ReferenceType * node ) { 1640 VISIT_START( node ); 1641 1642 VISIT( 1643 maybe_accept( node, &ReferenceType::base ); 1644 ) 1645 1646 VISIT_END( Type, node ); 1647 } 1648 1649 //-------------------------------------------------------------------------- 1650 // QualifiedType 1651 template< typename pass_t > 1652 const ast::Type * ast::Pass< pass_t >::visit( const ast::QualifiedType * node ) { 1653 VISIT_START( node ); 1654 1655 VISIT( 1656 maybe_accept( node, &QualifiedType::parent ); 1657 maybe_accept( node, &QualifiedType::child ); 1658 ) 1659 1660 VISIT_END( Type, node ); 1661 } 1662 1663 //-------------------------------------------------------------------------- 1664 // FunctionType 1665 template< typename pass_t > 1666 const ast::Type * ast::Pass< pass_t >::visit( const ast::FunctionType * node ) { 1667 VISIT_START( node ); 1668 1669 VISIT( 1670 maybe_accept( node, &FunctionType::forall ); 1671 maybe_accept( node, &FunctionType::returns ); 1672 maybe_accept( node, &FunctionType::params ); 1673 ) 1674 1675 VISIT_END( Type, node ); 1676 } 1677 1678 //-------------------------------------------------------------------------- 1679 // StructInstType 1680 template< typename pass_t > 1681 const ast::Type * ast::Pass< pass_t >::visit( const ast::StructInstType * node ) { 1682 VISIT_START( node ); 1683 1684 __pass::indexer::addStruct( pass, 0, node->name ); 1685 1686 VISIT({ 1687 guard_indexer guard { *this }; 1688 maybe_accept( node, &StructInstType::forall ); 1689 maybe_accept( node, &StructInstType::params ); 1690 }) 1691 1692 VISIT_END( Type, node ); 1693 } 1694 1695 //-------------------------------------------------------------------------- 1696 // UnionInstType 1697 template< typename pass_t > 1698 const ast::Type * ast::Pass< pass_t >::visit( const ast::UnionInstType * node ) { 1699 VISIT_START( node ); 1700 1701 __pass::indexer::addStruct( pass, 0, node->name ); 1702 1703 { 1704 guard_indexer guard { *this }; 1705 maybe_accept( node, &UnionInstType::forall ); 1706 maybe_accept( node, &UnionInstType::params ); 1707 } 1708 1709 VISIT_END( Type, node ); 1710 } 1711 1712 //-------------------------------------------------------------------------- 1713 // EnumInstType 1714 template< typename pass_t > 1715 const ast::Type * ast::Pass< pass_t >::visit( const ast::EnumInstType * node ) { 1716 VISIT_START( node ); 1717 1718 VISIT( 1719 maybe_accept( node, &EnumInstType::forall ); 1720 maybe_accept( node, &EnumInstType::params ); 1721 ) 1722 1723 VISIT_END( Type, node ); 1724 } 1725 1726 //-------------------------------------------------------------------------- 1727 // TraitInstType 1728 template< typename pass_t > 1729 const ast::Type * ast::Pass< pass_t >::visit( const ast::TraitInstType * node ) { 1730 VISIT_START( node ); 1731 1732 VISIT( 1733 maybe_accept( node, &TraitInstType::forall ); 1734 maybe_accept( node, &TraitInstType::params ); 1735 ) 1736 1737 VISIT_END( Type, node ); 1738 } 1739 1740 //-------------------------------------------------------------------------- 1741 // TypeInstType 1742 template< typename pass_t > 1743 const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeInstType * node ) { 1744 VISIT_START( node ); 1745 1746 VISIT( 1747 maybe_accept( node, &TypeInstType::forall ); 1748 maybe_accept( node, &TypeInstType::params ); 1749 ) 1750 1751 VISIT_END( Type, node ); 1752 } 1753 1754 //-------------------------------------------------------------------------- 1755 // TupleType 1756 template< typename pass_t > 1757 const ast::Type * ast::Pass< pass_t >::visit( const ast::TupleType * node ) { 1758 VISIT_START( node ); 1759 1760 VISIT( 1761 maybe_accept( node, &TupleType::types ); 1762 maybe_accept( node, &TupleType::members ); 1763 ) 1764 1765 VISIT_END( Type, node ); 1766 } 1767 1768 //-------------------------------------------------------------------------- 1769 // TypeofType 1770 template< typename pass_t > 1771 const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeofType * node ) { 1772 VISIT_START( node ); 1773 1774 VISIT( 1775 maybe_accept( node, &TypeofType::expr ); 1776 ) 1777 1778 VISIT_END( Type, node ); 1779 } 1780 1781 //-------------------------------------------------------------------------- 1782 // VarArgsType 1783 template< typename pass_t > 1784 const ast::Type * ast::Pass< pass_t >::visit( const ast::VarArgsType * node ) { 1785 VISIT_START( node ); 1786 1787 VISIT_END( Type, node ); 1788 } 1789 1790 //-------------------------------------------------------------------------- 1791 // ZeroType 1792 template< typename pass_t > 1793 const ast::Type * ast::Pass< pass_t >::visit( const ast::ZeroType * node ) { 1794 VISIT_START( node ); 1795 1796 VISIT_END( Type, node ); 1797 } 1798 1799 //-------------------------------------------------------------------------- 1800 // OneType 1801 template< typename pass_t > 1802 const ast::Type * ast::Pass< pass_t >::visit( const ast::OneType * node ) { 1803 VISIT_START( node ); 1804 1805 VISIT_END( Type, node ); 1806 } 1807 1808 //-------------------------------------------------------------------------- 1809 // GlobalScopeType 1810 template< typename pass_t > 1811 const ast::Type * ast::Pass< pass_t >::visit( const ast::GlobalScopeType * node ) { 1812 VISIT_START( node ); 1813 1814 VISIT_END( Type, node ); 1815 } 1816 1817 1818 //-------------------------------------------------------------------------- 1819 // Designation 1820 template< typename pass_t > 1821 const ast::Designation * ast::Pass< pass_t >::visit( const ast::Designation * node ) { 1822 VISIT_START( node ); 1823 1824 VISIT( maybe_accept( node, &Designation::designators ); ) 1825 1826 VISIT_END( Designation, node ); 1827 } 912 913 914 915 1828 916 1829 917 //-------------------------------------------------------------------------- … … 1876 964 1877 965 VISIT( 1878 maybe_accept( node, &Attribute::param s );966 maybe_accept( node, &Attribute::parameters ); 1879 967 ) 1880 968 -
src/AST/Pass.proto.hpp
rd908563 r933f32f 107 107 bool * m_prev; 108 108 bool_ref * m_ref; 109 };110 111 /// "Short hand" to check if this is a valid previsit function112 /// Mostly used to make the static_assert look (and print) prettier113 template<typename pass_t, typename node_t>114 struct is_valid_previsit {115 using ret_t = decltype( ((pass_t*)nullptr)->previsit( (const node_t *)nullptr ) );116 117 static constexpr bool value = std::is_void< ret_t >::value ||118 std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;119 };120 121 /// Used by previsit implementation122 /// We need to reassign the result to 'node', unless the function123 /// returns void, then we just leave 'node' unchanged124 template<bool is_void>125 struct __assign;126 127 template<>128 struct __assign<true> {129 template<typename pass_t, typename node_t>130 static inline void result( pass_t & pass, const node_t * & node ) {131 pass.previsit( node );132 }133 };134 135 template<>136 struct __assign<false> {137 template<typename pass_t, typename node_t>138 static inline void result( pass_t & pass, const node_t * & node ) {139 node = pass.previsit( node );140 assertf(node, "Previsit must not return NULL");141 }142 };143 144 /// Used by postvisit implementation145 /// We need to return the result unless the function146 /// returns void, then we just return the original node147 template<bool is_void>148 struct __return;149 150 template<>151 struct __return<true> {152 template<typename pass_t, typename node_t>153 static inline const node_t * result( pass_t & pass, const node_t * & node ) {154 pass.postvisit( node );155 return node;156 }157 };158 159 template<>160 struct __return<false> {161 template<typename pass_t, typename node_t>162 static inline auto result( pass_t & pass, const node_t * & node ) {163 return pass.postvisit( node );164 }165 109 }; 166 110 … … 182 126 template<typename pass_t, typename node_t> 183 127 static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) { 184 static_assert( 185 is_valid_previsit<pass_t, node_t>::value, 186 "Previsit may not change the type of the node. It must return its paremeter or void." 187 ); 188 189 __assign< 190 std::is_void< 191 decltype( pass.previsit( node ) ) 192 >::value 193 >::result( pass, node ); 128 node = pass.previsit( node ); 129 assert(node); 194 130 } 195 131 … … 199 135 // PostVisit : never mutates the passed pointer but may return a different node 200 136 template<typename pass_t, typename node_t> 201 static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> 202 decltype( pass.postvisit( node ), node->accept( *(Visitor*)nullptr ) ) 203 { 204 return __return< 205 std::is_void< 206 decltype( pass.postvisit( node ) ) 207 >::value 208 >::result( pass, node ); 137 static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) { 138 return pass.postvisit( node ); 209 139 } 210 140 -
src/AST/Stmt.cpp
rd908563 r933f32f 16 16 #include "Stmt.hpp" 17 17 18 19 18 #include "DeclReplacer.hpp" 20 #include "Type.hpp"21 19 22 20 namespace ast { 23 21 24 22 // --- CompoundStmt 25 CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids(other.kids) { 26 // when cloning a compound statement, we may end up cloning declarations which 27 // are referred to by VariableExprs throughout the block. Cloning a VariableExpr 28 // does a shallow copy, so the VariableExpr will end up pointing to the original 29 // declaration. If the original declaration is deleted, e.g. because the original 30 // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case, 31 // find all DeclarationWithType nodes (since a VariableExpr must point to a 32 // DeclarationWithType) in the original CompoundStmt and map them to the cloned 33 // node in the new CompoundStmt ('this'), then replace the Declarations referred to 34 // by each VariableExpr according to the constructed map. Note that only the declarations 35 // in the current level are collected into the map, because child CompoundStmts will 36 // recursively execute this routine. There may be more efficient ways of doing 37 // this. 38 DeclReplacer::DeclMap declMap; 39 auto origit = other.kids.begin(); 40 for ( const Stmt * s : kids ) { 41 assert( origit != other.kids.end() ); 42 const Stmt * origStmt = *origit++; 43 if ( const DeclStmt * declStmt = dynamic_cast< const DeclStmt * >( s ) ) { 44 const DeclStmt * origDeclStmt = strict_dynamic_cast< const DeclStmt * >( origStmt ); 45 if ( const DeclWithType * dwt = dynamic_cast< const DeclWithType * > ( declStmt->decl.get() ) ) { 46 const DeclWithType * origdwt = strict_dynamic_cast< const DeclWithType * > ( origDeclStmt->decl.get() ); 47 assert( dwt->name == origdwt->name ); 48 declMap[ origdwt ] = dwt; 49 } else assert( ! dynamic_cast< const DeclWithType * > ( origDeclStmt->decl.get() ) ); 50 } else assert( ! dynamic_cast< const DeclStmt * > ( s ) ); 51 } 52 if ( ! declMap.empty() ) { 53 DeclReplacer::replace( this, declMap ); 54 } 23 CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) { 24 assert(!"implemented"); 55 25 } 56 26 -
src/AST/Stmt.hpp
rd908563 r933f32f 96 96 }; 97 97 98 /// Assembly statement `asm ... ( "..." : ... )`99 98 class AsmStmt final : public Stmt { 100 99 public: … … 119 118 }; 120 119 121 /// C-preprocessor directive `#...`122 120 class DirectiveStmt final : public Stmt { 123 121 public: … … 134 132 }; 135 133 136 /// If conditional statement `if (...) ... else ...`137 134 class IfStmt final : public Stmt { 138 135 public: … … 154 151 }; 155 152 156 /// Switch or choose conditional statement `switch (...) { ... }`157 153 class SwitchStmt final : public Stmt { 158 154 public: … … 170 166 }; 171 167 172 /// Case label `case ...:` `default:`173 168 class CaseStmt final : public Stmt { 174 169 public: … … 188 183 }; 189 184 190 /// While loop `while (...) ...` `do ... while (...);191 185 class WhileStmt final : public Stmt { 192 186 public: … … 207 201 }; 208 202 209 /// For loop `for (... ; ... ; ...) ...`210 203 class ForStmt final : public Stmt { 211 204 public: … … 226 219 }; 227 220 228 /// Branch control flow statement `goto ...` `break` `continue` `fallthru`229 221 class BranchStmt final : public Stmt { 230 222 public: … … 244 236 computedTarget(computedTarget), kind(Goto) {} 245 237 246 const char * kindName() const{ return kindNames[kind]; }238 const char * kindName() { return kindNames[kind]; } 247 239 248 240 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } … … 254 246 }; 255 247 256 /// Return statement `return ...`257 248 class ReturnStmt final : public Stmt { 258 249 public: … … 268 259 }; 269 260 270 /// Throw statement `throw ...`271 261 class ThrowStmt final : public Stmt { 272 262 public: … … 287 277 }; 288 278 289 /// Try statement `try { ... } ...`290 279 class TryStmt final : public Stmt { 291 280 public: … … 305 294 }; 306 295 307 /// Catch clause of try statement308 296 class CatchStmt final : public Stmt { 309 297 public: … … 325 313 }; 326 314 327 /// Finally clause of try statement328 315 class FinallyStmt final : public Stmt { 329 316 public: … … 340 327 }; 341 328 342 /// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`343 329 class WaitForStmt final : public Stmt { 344 330 public: 345 331 struct Target { 346 ptr<Expr> func ;347 std::vector<ptr<Expr>> arg s;332 ptr<Expr> function; 333 std::vector<ptr<Expr>> arguments; 348 334 }; 349 335 … … 378 364 }; 379 365 380 /// With statement `with (...) ...`381 366 class WithStmt final : public Stmt { 382 367 public: … … 394 379 }; 395 380 396 /// Any declaration in a (compound) statement.397 381 class DeclStmt final : public Stmt { 398 382 public: … … 408 392 }; 409 393 410 /// Represents an implicit application of a constructor or destructor.411 394 class ImplicitCtorDtorStmt final : public Stmt { 412 395 public: -
src/AST/Type.cpp
rd908563 r933f32f 141 141 bool EnumInstType::isComplete() const { return base ? base->body : false; } 142 142 143 // --- TraitInstType144 145 TraitInstType::TraitInstType( const TraitDecl * b, CV::Qualifiers q,146 std::vector<ptr<Attribute>>&& as )147 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}148 149 143 // --- TypeInstType 150 144 -
src/AST/Type.hpp
rd908563 r933f32f 47 47 bool is_atomic() const { return qualifiers.is_atomic; } 48 48 49 Type * set_const( bool v ) { qualifiers.is_const = v; return this; }50 Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; }51 Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; }52 Type * set_mutex( bool v ) { qualifiers.is_mutex = v; return this; }53 Type * set_atomic( bool v ) { qualifiers.is_atomic = v; return this; }49 void set_const( bool v ) { qualifiers.is_const = v; } 50 void set_restrict( bool v ) { qualifiers.is_restrict = v; } 51 void set_lvalue( bool v ) { qualifiers.is_lvalue = v; } 52 void set_mutex( bool v ) { qualifiers.is_mutex = v; } 53 void set_atomic( bool v ) { qualifiers.is_atomic = v; } 54 54 55 55 /// How many elemental types are represented by this type … … 308 308 virtual ReferenceToType * clone() const override = 0; 309 309 MUTATE_FRIEND 310 311 protected: 312 /// Name for the kind of type this is 313 virtual std::string typeString() const = 0; 310 314 }; 311 315 … … 329 333 StructInstType * clone() const override { return new StructInstType{ *this }; } 330 334 MUTATE_FRIEND 335 336 std::string typeString() const override { return "struct"; } 331 337 }; 332 338 … … 350 356 UnionInstType * clone() const override { return new UnionInstType{ *this }; } 351 357 MUTATE_FRIEND 358 359 std::string typeString() const override { return "union"; } 352 360 }; 353 361 … … 371 379 EnumInstType * clone() const override { return new EnumInstType{ *this }; } 372 380 MUTATE_FRIEND 381 382 std::string typeString() const override { return "enum"; } 373 383 }; 374 384 … … 393 403 TraitInstType * clone() const override { return new TraitInstType{ *this }; } 394 404 MUTATE_FRIEND 405 406 std::string typeString() const override { return "trait"; } 395 407 }; 396 408 … … 420 432 TypeInstType * clone() const override { return new TypeInstType{ *this }; } 421 433 MUTATE_FRIEND 434 435 std::string typeString() const override { return "type"; } 422 436 }; 423 437 … … 500 514 class GlobalScopeType final : public Type { 501 515 public: 502 GlobalScopeType( ) : Type() {}516 GlobalScopeType( CV::Qualifiers q = {} ) : Type( q ) {} 503 517 504 518 const Type * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/TypeSubstitution.hpp
rd908563 r933f32f 25 25 #include "Fwd.hpp" // for UniqueId 26 26 #include "ParseNode.hpp" 27 #include "Type.hpp" 27 #include "Type.hpp" // for ptr<Type> 28 28 #include "Common/SemanticError.h" // for SemanticError 29 29 #include "Visitor.hpp" 30 30 #include "Decl.hpp" 31 31 #include "Expr.hpp" 32 #include "Node.hpp"33 32 34 33 namespace ast { … … 44 43 TypeSubstitution &operator=( const TypeSubstitution &other ); 45 44 46 template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const; 47 template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const; 48 49 template< typename node_t, enum Node::ref_type ref_t > 50 int apply( ptr_base< node_t, ref_t > & input ) const { 51 const node_t * p = input.get(); 52 int ret = apply(p); 53 input = p; 54 return ret; 55 } 56 57 template< typename node_t, enum Node::ref_type ref_t > 58 int applyFree( ptr_base< node_t, ref_t > & input ) const { 59 const node_t * p = input.get(); 60 int ret = applyFree(p); 61 input = p; 62 return ret; 63 } 45 template< typename SynTreeClass > int apply( SynTreeClass *&input ) const; 46 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const; 64 47 65 48 void add( std::string formalType, const Type *actualType ); … … 179 162 180 163 template< typename SynTreeClass > 181 int TypeSubstitution::apply( const SynTreeClass *&input ) const {164 int TypeSubstitution::apply( SynTreeClass *&input ) const { 182 165 assert( input ); 183 166 Pass<Substituter> sub( *this, false ); 184 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 167 input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) ); 168 assert( input ); 185 169 /// std::cerr << "substitution result is: "; 186 170 /// newType->print( std::cerr ); … … 190 174 191 175 template< typename SynTreeClass > 192 int TypeSubstitution::applyFree( const SynTreeClass *&input ) const {176 int TypeSubstitution::applyFree( SynTreeClass *&input ) const { 193 177 assert( input ); 194 178 Pass<Substituter> sub( *this, true ); 195 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 179 input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) ); 180 assert( input ); 196 181 /// std::cerr << "substitution result is: "; 197 182 /// newType->print( std::cerr ); -
src/AST/module.mk
rd908563 r933f32f 1 ######################### -*- Mode: Makefile-Gmake -*- ######################## 1 ######################### -*- Mode: Makefile-Gmake -*- 2 ######################## 2 3 ## 3 4 ## Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo … … 16 17 17 18 SRC_AST = \ 18 AST/Attribute.cpp \ 19 AST/Convert.cpp \ 20 AST/Decl.cpp \ 21 AST/DeclReplacer.cpp \ 22 AST/Expr.cpp \ 23 AST/GenericSubstitution.cpp \ 24 AST/Init.cpp \ 25 AST/LinkageSpec.cpp \ 26 AST/Node.cpp \ 27 AST/Pass.cpp \ 28 AST/Print.cpp \ 29 AST/Stmt.cpp \ 30 AST/Type.cpp \ 31 AST/TypeSubstitution.cpp 19 AST/Convert.cpp \ 20 AST/Node.cpp \ 21 AST/TypeSubstitution.cpp 32 22 33 23 … … 35 25 SRC += $(SRC_AST) 36 26 SRCDEMANGLE += $(SRC_AST) 27 -
src/AST/porting.md
rd908563 r933f32f 38 38 39 39 `N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class 40 * **TODO** `Declaration::printShort` should also be integrated 40 * **TODO** write this visitor 41 * **TODO** write `std::ostream& operator<< ( std::ostream& out, const Node* node )` in `Node.hpp` in terms of `ast::Print` 42 * `Declaration::printShort` should also be integrated 41 43 42 44 `clone` is private to `Node` now … … 110 112 111 113 ## Specific Nodes ## 112 `Attribute`113 * `parameters` => `params`114 115 114 `Decl` 116 115 * `storageClasses` => `storage` … … 209 208 210 209 `CompoundStmt` 210 * **TODO** port copy operator 211 * Needs to be an almost-shallow clone, where the declarations are cloned only if needed 212 * **TODO** port `DeclReplacer` 211 213 * Still a `std::list` for children, rather than `std::vector` 212 214 * allows more-efficient splicing for purposes of later code generation … … 227 229 * `getAggr()` => `aggr()` 228 230 * also now returns `const AggregateDecl *` 229 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` 231 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write 230 232 231 233 `BasicType` -
src/Common/Eval.cc
rd908563 r933f32f 17 17 18 18 #include "Common/PassVisitor.h" 19 #include "AST/Pass.hpp"20 19 #include "InitTweak/InitTweak.h" 21 20 #include "SynTree/Expression.h" 22 21 23 //------------------------------------------------------------- 24 // Old AST 25 struct EvalOld : public WithShortCircuiting { 22 struct Eval : public WithShortCircuiting { 26 23 long long int value = 0; 27 24 bool valid = true; … … 83 80 }; 84 81 85 //-------------------------------------------------------------86 // New AST87 struct EvalNew : public ast::WithShortCircuiting {88 long long int value = 0;89 bool valid = true;90 91 void previsit( const ast::Node * ) { visit_children = false; }92 void postvisit( const ast::Node * ) { valid = false; }93 94 void postvisit( const ast::ConstantExpr * expr ) {95 value = expr->intValue();96 }97 98 void postvisit( const ast::CastExpr * expr ) {99 auto arg = eval(expr->arg);100 valid = arg.second;101 value = arg.first;102 // TODO: perform type conversion on value if valid103 }104 105 void postvisit( const ast::VariableExpr * expr ) {106 if ( const ast::EnumInstType * inst = dynamic_cast<const ast::EnumInstType *>(expr->result.get()) ) {107 if ( const ast::EnumDecl * decl = inst->base ) {108 if ( decl->valueOf( expr->var, value ) ) { // value filled by valueOf109 return;110 }111 }112 }113 valid = false;114 }115 116 void postvisit( const ast::ApplicationExpr * expr ) {117 const ast::DeclWithType * function = InitTweak::getFunction(expr);118 if ( ! function || function->linkage != ast::Linkage::Intrinsic ) { valid = false; return; }119 const std::string & fname = function->name;120 assertf( expr->args.size() == 1 || expr->args.size() == 2, "Intrinsic function with %zd arguments: %s", expr->args.size(), fname.c_str() );121 std::pair<long long int, bool> arg1, arg2;122 arg1 = eval(expr->args.front());123 valid = valid && arg1.second;124 if ( ! valid ) return;125 if ( expr->args.size() == 2 ) {126 arg2 = eval(expr->args.back());127 valid = valid && arg2.second;128 if ( ! valid ) return;129 }130 if (fname == "?+?") {131 value = arg1.first + arg2.first;132 } else if (fname == "?-?") {133 value = arg1.first - arg2.first;134 } else if (fname == "?*?") {135 value = arg1.first * arg2.first;136 } else if (fname == "?/?") {137 value = arg1.first / arg2.first;138 } else if (fname == "?%?") {139 value = arg1.first % arg2.first;140 } else {141 valid = false;142 }143 // TODO: implement other intrinsic functions144 }145 };146 147 82 std::pair<long long int, bool> eval(Expression * expr) { 148 PassVisitor<EvalOld> ev; 149 if (expr) { 150 expr->accept(ev); 151 return std::make_pair(ev.pass.value, ev.pass.valid); 152 } else { 153 return std::make_pair(0, false); 154 } 155 } 156 157 std::pair<long long int, bool> eval(const ast::Expr * expr) { 158 ast::Pass<EvalNew> ev; 83 PassVisitor<Eval> ev; 159 84 if (expr) { 160 85 expr->accept(ev); -
src/Common/PassVisitor.impl.h
rd908563 r933f32f 23 23 assert( __return ); \ 24 24 return __return; 25 26 27 #define VISIT_BODY( node ) \ 28 VISIT_START( node ); \ 29 if( children_guard ) { \ 30 Visitor::visit( node ); \ 31 } \ 32 VISIT_END( node ); \ 33 34 35 #define MUTATE_BODY( type, node ) \ 36 MUTATE_START( node ); \ 37 if( children_guard ) { \ 38 Mutator::mutate( node ); \ 39 } \ 40 MUTATE_END( type, node ); \ 41 25 42 26 43 … … 2739 2756 MUTATE_END( TypeSubstitution, node ); 2740 2757 } 2741 2742 #undef VISIT_START2743 #undef VISIT_END2744 2745 #undef MUTATE_START2746 #undef MUTATE_END -
src/Common/utility.h
rd908563 r933f32f 74 74 75 75 template< typename Container > 76 void deleteAll( constContainer &container ) {77 for ( const auto &i : container) {78 delete i;76 void deleteAll( Container &container ) { 77 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 78 delete *i; 79 79 } // for 80 80 } -
src/InitTweak/InitTweak.cc
rd908563 r933f32f 346 346 namespace { 347 347 DeclarationWithType * getCalledFunction( Expression * expr ); 348 const ast::DeclWithType * getCalledFunction( const ast::Expr * expr );349 348 350 349 template<typename CallExpr> … … 356 355 return getCalledFunction( expr->get_args().front() ); 357 356 } 358 359 template<typename CallExpr>360 const ast::DeclWithType * handleDerefCalledFunction( const CallExpr * expr ) {361 // (*f)(x) => should get "f"362 std::string name = getFunctionName( expr );363 assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );364 assertf( ! expr->args.empty(), "Cannot get called function from dereference with no arguments" );365 return getCalledFunction( expr->args.front() );366 }367 368 357 369 358 DeclarationWithType * getCalledFunction( Expression * expr ) { … … 386 375 return nullptr; 387 376 } 388 389 const ast::DeclWithType * getCalledFunction( const ast::Expr * expr ) {390 assert( expr );391 if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( expr ) ) {392 return varExpr->var;393 } else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( expr ) ) {394 return memberExpr->member;395 } else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( expr ) ) {396 return getCalledFunction( castExpr->arg );397 } else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * >( expr ) ) {398 return handleDerefCalledFunction( untypedExpr );399 } else if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * > ( expr ) ) {400 return handleDerefCalledFunction( appExpr );401 } else if ( const ast::AddressExpr * addrExpr = dynamic_cast< const ast::AddressExpr * >( expr ) ) {402 return getCalledFunction( addrExpr->arg );403 } else if ( const ast::CommaExpr * commaExpr = dynamic_cast< const ast::CommaExpr * >( expr ) ) {404 return getCalledFunction( commaExpr->arg2 );405 }406 return nullptr;407 }408 377 } 409 378 … … 413 382 } else if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * > ( expr ) ) { 414 383 return getCalledFunction( untyped->get_function() ); 415 }416 assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() );417 }418 419 const ast::DeclWithType * getFunction( const ast::Expr * expr ) {420 if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr ) ) {421 return getCalledFunction( appExpr->func );422 } else if ( const ast::UntypedExpr * untyped = dynamic_cast< const ast::UntypedExpr * > ( expr ) ) {423 return getCalledFunction( untyped->func );424 384 } 425 385 assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() ); … … 474 434 } 475 435 476 template<typename CallExpr>477 const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) {478 if( pos >= call->args.size() ) {479 assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.",480 pos, toString( call ).c_str() );481 }482 for ( const ast::Expr * arg : call->args ) {483 if ( pos == 0 ) return arg;484 --pos;485 }486 assert( false );487 }436 // template<typename CallExpr> 437 // const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) { 438 // if( pos >= call->args.size() ) { 439 // assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.", 440 // pos, toString( call ).c_str() ); 441 // } 442 // for ( const ast::Expr * arg : call->args ) { 443 // if ( pos == 0 ) return arg; 444 // --pos; 445 // } 446 // assert( false ); 447 // } 488 448 } 489 449 … … 506 466 } 507 467 } 508 509 468 const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ) { 510 if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) { 511 return callArg( app, pos ); 512 } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) { 513 return callArg( untyped, pos ); 514 } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) { 515 const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids; 516 assertf( ! stmts.empty(), "TupleAssignExpr missing statements." ); 517 auto stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back().get() ); 518 auto tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr.get() ); 519 assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr."); 520 return getCallArg( tuple->exprs.front(), pos ); 521 } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) { 522 return getCallArg( ctor->callExpr, pos ); 523 } else { 524 assertf( false, "Unexpected expression type passed to getCallArg: %s", 525 toString( call ).c_str() ); 526 } 469 (void)call; 470 (void)pos; 471 #warning unimplemented; needs to build AST/Expr.cpp 472 assertf(false, "unimplemented; needs to build AST/Expr.cpp"); 473 // if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) { 474 // return callArg( app, pos ); 475 // } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) { 476 // return callArg( untyped, pos ); 477 // } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) { 478 // const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids; 479 // assertf( ! stmts.empty(), "TupleAssignExpr missing statements." ); 480 // const ExprStmt * stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back() ); 481 // const TupleExpr * tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr ); 482 // assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr."); 483 // return getCallArg( tuple->exprs.front(), pos ); 484 // } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) { 485 // return getCallArg( ctor->callExpr, pos ); 486 // } else { 487 // assertf( false, "Unexpected expression type passed to getCallArg: %s", 488 // toString( call ).c_str() ); 489 // } 527 490 } 528 491 529 492 namespace { 530 493 std::string funcName( Expression * func ); 531 std::string funcName( const ast::Expr * func );532 494 533 495 template<typename CallExpr> … … 538 500 assertf( ! expr->get_args().empty(), "Cannot get function name from dereference with no arguments" ); 539 501 return funcName( expr->get_args().front() ); 540 }541 542 template<typename CallExpr>543 std::string handleDerefName( const CallExpr * expr ) {544 // (*f)(x) => should get name "f"545 std::string name = getFunctionName( expr );546 assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );547 assertf( ! expr->args.empty(), "Cannot get function name from dereference with no arguments" );548 return funcName( expr->args.front() );549 502 } 550 503 … … 570 523 } 571 524 } 572 573 std::string funcName( const ast::Expr * func ) {574 if ( const ast::NameExpr * nameExpr = dynamic_cast< const ast::NameExpr * >( func ) ) {575 return nameExpr->name;576 } else if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( func ) ) {577 return varExpr->var->name;578 } else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( func ) ) {579 return funcName( castExpr->arg );580 } else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( func ) ) {581 return memberExpr->member->name;582 } else if ( const ast::UntypedMemberExpr * memberExpr = dynamic_cast< const ast::UntypedMemberExpr * > ( func ) ) {583 return funcName( memberExpr->member );584 } else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * >( func ) ) {585 return handleDerefName( untypedExpr );586 } else if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( func ) ) {587 return handleDerefName( appExpr );588 } else if ( const ast::ConstructorExpr * ctorExpr = dynamic_cast< const ast::ConstructorExpr * >( func ) ) {589 return funcName( getCallArg( ctorExpr->callExpr, 0 ) );590 } else {591 assertf( false, "Unexpected expression type being called as a function in call expression: %s", toString( func ).c_str() );592 }593 }594 525 } 595 526 … … 608 539 } 609 540 610 std::string getFunctionName( const ast::Expr * expr ) {611 // there's some unforunate overlap here with getCalledFunction. Ideally this would be able to use getCalledFunction and612 // return the name of the DeclarationWithType, but this needs to work for NameExpr and UntypedMemberExpr, where getCalledFunction613 // can't possibly do anything reasonable.614 if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr ) ) {615 return funcName( appExpr->func );616 } else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * > ( expr ) ) {617 return funcName( untypedExpr->func );618 } else {619 std::cerr << expr << std::endl;620 assertf( false, "Unexpected expression type passed to getFunctionName" );621 }622 }623 624 541 Type * getPointerBase( Type * type ) { 625 542 if ( PointerType * ptrType = dynamic_cast< PointerType * >( type ) ) { … … 634 551 } 635 552 const ast::Type* getPointerBase( const ast::Type* t ) { 636 if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) { 637 return p->base; 638 } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) { 639 return a->base; 640 } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) { 641 return r->base; 642 } else return nullptr; 553 (void)t; 554 #warning needs to build Type.cpp before inclusion 555 assertf(false, "needs to build Type.cpp before inclusion"); 556 // if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) { 557 // return p->base; 558 // } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) { 559 // return a->base; 560 // } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) { 561 // return r->base; 562 // } else return nullptr; 643 563 } 644 564 -
src/InitTweak/InitTweak.h
rd908563 r933f32f 58 58 /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr) 59 59 DeclarationWithType * getFunction( Expression * expr ); 60 const ast::DeclWithType * getFunction( const ast::Expr * expr );61 60 62 61 /// Non-Null if expr is a call expression whose target function is intrinsic … … 79 78 /// returns the name of the function being called 80 79 std::string getFunctionName( Expression * expr ); 81 std::string getFunctionName( const ast::Expr * expr );82 80 83 81 /// returns the argument to a call expression in position N indexed from 0 -
src/Makefile.am
rd908563 r933f32f 37 37 endif 38 38 39 include AST/module.mk40 39 include CodeGen/module.mk 41 40 include CodeTools/module.mk -
src/Makefile.in
rd908563 r933f32f 16 16 17 17 ######################## -*- Mode: Makefile-Automake -*- ###################### 18 ###############################################################################19 20 ######################### -*- Mode: Makefile-Gmake -*- ########################21 18 ############################################################################### 22 19 … … 165 162 libdemangle_a_LIBADD = 166 163 am__dirstamp = $(am__leading_dot)dirstamp 167 am__objects_1 = AST/Attribute.$(OBJEXT) AST/Convert.$(OBJEXT) \ 168 AST/Decl.$(OBJEXT) AST/DeclReplacer.$(OBJEXT) \ 169 AST/Expr.$(OBJEXT) AST/GenericSubstitution.$(OBJEXT) \ 170 AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \ 171 AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \ 172 AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \ 173 AST/TypeSubstitution.$(OBJEXT) 174 am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \ 164 am__objects_1 = CodeGen/CodeGenerator.$(OBJEXT) \ 175 165 CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \ 176 166 CodeGen/OperatorTable.$(OBJEXT) 177 am__objects_ 3= Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \167 am__objects_2 = Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \ 178 168 Common/PassVisitor.$(OBJEXT) Common/SemanticError.$(OBJEXT) \ 179 169 Common/Stats/Counter.$(OBJEXT) Common/Stats/Heap.$(OBJEXT) \ 180 170 Common/Stats/Stats.$(OBJEXT) Common/Stats/Time.$(OBJEXT) \ 181 171 Common/UniqueName.$(OBJEXT) 182 am__objects_ 4= ControlStruct/ForExprMutator.$(OBJEXT) \172 am__objects_3 = ControlStruct/ForExprMutator.$(OBJEXT) \ 183 173 ControlStruct/LabelFixer.$(OBJEXT) \ 184 174 ControlStruct/LabelGenerator.$(OBJEXT) \ 185 175 ControlStruct/MLEMutator.$(OBJEXT) \ 186 176 ControlStruct/Mutate.$(OBJEXT) 187 am__objects_ 5= ResolvExpr/AdjustExprType.$(OBJEXT) \177 am__objects_4 = ResolvExpr/AdjustExprType.$(OBJEXT) \ 188 178 ResolvExpr/Alternative.$(OBJEXT) \ 189 179 ResolvExpr/AlternativeFinder.$(OBJEXT) \ … … 203 193 ResolvExpr/TypeEnvironment.$(OBJEXT) \ 204 194 ResolvExpr/Unify.$(OBJEXT) 205 am__objects_ 6= SymTab/Autogen.$(OBJEXT) SymTab/FixFunction.$(OBJEXT) \195 am__objects_5 = SymTab/Autogen.$(OBJEXT) SymTab/FixFunction.$(OBJEXT) \ 206 196 SymTab/Indexer.$(OBJEXT) SymTab/Mangler.$(OBJEXT) \ 207 197 SymTab/ManglerCommon.$(OBJEXT) SymTab/Validate.$(OBJEXT) 208 am__objects_ 7= SynTree/Type.$(OBJEXT) SynTree/VoidType.$(OBJEXT) \198 am__objects_6 = SynTree/Type.$(OBJEXT) SynTree/VoidType.$(OBJEXT) \ 209 199 SynTree/BasicType.$(OBJEXT) SynTree/PointerType.$(OBJEXT) \ 210 200 SynTree/ArrayType.$(OBJEXT) SynTree/ReferenceType.$(OBJEXT) \ … … 226 216 SynTree/TypeSubstitution.$(OBJEXT) SynTree/Attribute.$(OBJEXT) \ 227 217 SynTree/DeclReplacer.$(OBJEXT) 228 am__objects_ 8= CompilationState.$(OBJEXT) $(am__objects_1) \229 $(am__objects_2) Concurrency/Keywords.$(OBJEXT) \230 $(am__objects_3) $(am__objects_4)GenPoly/GenPoly.$(OBJEXT) \218 am__objects_7 = CompilationState.$(OBJEXT) $(am__objects_1) \ 219 Concurrency/Keywords.$(OBJEXT) $(am__objects_2) \ 220 $(am__objects_3) GenPoly/GenPoly.$(OBJEXT) \ 231 221 GenPoly/Lvalue.$(OBJEXT) InitTweak/GenInit.$(OBJEXT) \ 232 222 InitTweak/InitTweak.$(OBJEXT) Parser/LinkageSpec.$(OBJEXT) \ 233 $(am__objects_ 5) $(am__objects_6) SymTab/Demangle.$(OBJEXT) \234 $(am__objects_ 7) Tuples/TupleAssignment.$(OBJEXT) \223 $(am__objects_4) $(am__objects_5) SymTab/Demangle.$(OBJEXT) \ 224 $(am__objects_6) Tuples/TupleAssignment.$(OBJEXT) \ 235 225 Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \ 236 226 Validate/HandleAttributes.$(OBJEXT) \ 237 227 Validate/FindSpecialDecls.$(OBJEXT) 238 am_libdemangle_a_OBJECTS = $(am__objects_ 8)228 am_libdemangle_a_OBJECTS = $(am__objects_7) 239 229 libdemangle_a_OBJECTS = $(am_libdemangle_a_OBJECTS) 240 230 am__installdirs = "$(DESTDIR)$(cfa_cpplibdir)" 241 231 PROGRAMS = $(cfa_cpplib_PROGRAMS) 242 am__objects_ 9= main.$(OBJEXT) MakeLibCfa.$(OBJEXT) \243 CompilationState.$(OBJEXT) $(am__objects_1) $(am__objects_2)\232 am__objects_8 = main.$(OBJEXT) MakeLibCfa.$(OBJEXT) \ 233 CompilationState.$(OBJEXT) $(am__objects_1) \ 244 234 CodeGen/Generate.$(OBJEXT) CodeGen/FixNames.$(OBJEXT) \ 245 235 CodeTools/DeclStats.$(OBJEXT) \ 246 236 CodeTools/ResolvProtoDump.$(OBJEXT) \ 247 237 CodeTools/TrackLoc.$(OBJEXT) Concurrency/Keywords.$(OBJEXT) \ 248 Concurrency/Waitfor.$(OBJEXT) $(am__objects_ 3) \249 Common/DebugMalloc.$(OBJEXT) $(am__objects_ 4) \238 Concurrency/Waitfor.$(OBJEXT) $(am__objects_2) \ 239 Common/DebugMalloc.$(OBJEXT) $(am__objects_3) \ 250 240 ControlStruct/ExceptTranslate.$(OBJEXT) GenPoly/Box.$(OBJEXT) \ 251 241 GenPoly/GenPoly.$(OBJEXT) GenPoly/ScrubTyVars.$(OBJEXT) \ … … 261 251 Parser/InitializerNode.$(OBJEXT) Parser/TypeData.$(OBJEXT) \ 262 252 Parser/LinkageSpec.$(OBJEXT) Parser/parserutility.$(OBJEXT) \ 263 $(am__objects_ 5) ResolvExpr/AlternativePrinter.$(OBJEXT) \264 $(am__objects_ 6) $(am__objects_7) \253 $(am__objects_4) ResolvExpr/AlternativePrinter.$(OBJEXT) \ 254 $(am__objects_5) $(am__objects_6) \ 265 255 Tuples/TupleAssignment.$(OBJEXT) \ 266 256 Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \ … … 268 258 Validate/FindSpecialDecls.$(OBJEXT) \ 269 259 Virtual/ExpandCasts.$(OBJEXT) 270 am____driver_cfa_cpp_OBJECTS = $(am__objects_ 9)260 am____driver_cfa_cpp_OBJECTS = $(am__objects_8) 271 261 ___driver_cfa_cpp_OBJECTS = $(am____driver_cfa_cpp_OBJECTS) 272 262 am__DEPENDENCIES_1 = … … 378 368 ETAGS = etags 379 369 CTAGS = ctags 380 am__DIST_COMMON = $(srcdir)/ AST/module.mk $(srcdir)/CodeGen/module.mk \370 am__DIST_COMMON = $(srcdir)/CodeGen/module.mk \ 381 371 $(srcdir)/CodeTools/module.mk $(srcdir)/Common/module.mk \ 382 372 $(srcdir)/Concurrency/module.mk \ … … 538 528 AUTOMAKE_OPTIONS = foreign subdir-objects 539 529 ACLOCAL_AMFLAGS = -I automake 540 SRC = main.cc MakeLibCfa.cc CompilationState.cc $(SRC_AST) \ 541 $(SRC_CODEGEN) CodeGen/Generate.cc CodeGen/FixNames.cc \ 542 CodeTools/DeclStats.cc CodeTools/ResolvProtoDump.cc \ 543 CodeTools/TrackLoc.cc Concurrency/Keywords.cc \ 544 Concurrency/Waitfor.cc $(SRC_COMMON) Common/DebugMalloc.cc \ 545 $(SRC_CONTROLSTRUCT) ControlStruct/ExceptTranslate.cc \ 546 GenPoly/Box.cc GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc \ 547 GenPoly/Lvalue.cc GenPoly/Specialize.cc \ 548 GenPoly/FindFunction.cc GenPoly/InstantiateGeneric.cc \ 549 InitTweak/GenInit.cc InitTweak/FixInit.cc \ 550 InitTweak/FixGlobalInit.cc InitTweak/InitTweak.cc \ 551 Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \ 552 Parser/ParseNode.cc Parser/DeclarationNode.cc \ 553 Parser/ExpressionNode.cc Parser/StatementNode.cc \ 554 Parser/InitializerNode.cc Parser/TypeData.cc \ 555 Parser/LinkageSpec.cc Parser/parserutility.cc \ 556 $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc \ 557 $(SRC_SYMTAB) $(SRC_SYNTREE) Tuples/TupleAssignment.cc \ 558 Tuples/TupleExpansion.cc Tuples/Explode.cc \ 559 Validate/HandleAttributes.cc Validate/FindSpecialDecls.cc \ 560 Virtual/ExpandCasts.cc 561 SRCDEMANGLE = CompilationState.cc $(SRC_AST) $(SRC_CODEGEN) \ 530 SRC = main.cc MakeLibCfa.cc CompilationState.cc $(SRC_CODEGEN) \ 531 CodeGen/Generate.cc CodeGen/FixNames.cc CodeTools/DeclStats.cc \ 532 CodeTools/ResolvProtoDump.cc CodeTools/TrackLoc.cc \ 533 Concurrency/Keywords.cc Concurrency/Waitfor.cc $(SRC_COMMON) \ 534 Common/DebugMalloc.cc $(SRC_CONTROLSTRUCT) \ 535 ControlStruct/ExceptTranslate.cc GenPoly/Box.cc \ 536 GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc \ 537 GenPoly/Specialize.cc GenPoly/FindFunction.cc \ 538 GenPoly/InstantiateGeneric.cc InitTweak/GenInit.cc \ 539 InitTweak/FixInit.cc InitTweak/FixGlobalInit.cc \ 540 InitTweak/InitTweak.cc Parser/parser.yy Parser/lex.ll \ 541 Parser/TypedefTable.cc Parser/ParseNode.cc \ 542 Parser/DeclarationNode.cc Parser/ExpressionNode.cc \ 543 Parser/StatementNode.cc Parser/InitializerNode.cc \ 544 Parser/TypeData.cc Parser/LinkageSpec.cc \ 545 Parser/parserutility.cc $(SRC_RESOLVEXPR) \ 546 ResolvExpr/AlternativePrinter.cc $(SRC_SYMTAB) $(SRC_SYNTREE) \ 547 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 548 Tuples/Explode.cc Validate/HandleAttributes.cc \ 549 Validate/FindSpecialDecls.cc Virtual/ExpandCasts.cc 550 SRCDEMANGLE = CompilationState.cc $(SRC_CODEGEN) \ 562 551 Concurrency/Keywords.cc $(SRC_COMMON) $(SRC_CONTROLSTRUCT) \ 563 552 GenPoly/GenPoly.cc GenPoly/Lvalue.cc InitTweak/GenInit.cc \ … … 573 562 @WITH_LIBTCMALLOC_TRUE@LIBTCMALLOC = -ltcmalloc 574 563 @WITH_LIBTCMALLOC_TRUE@TCMALLOCFLAG = -DTCMALLOC 575 SRC_AST = \576 AST/Attribute.cpp \577 AST/Convert.cpp \578 AST/Decl.cpp \579 AST/DeclReplacer.cpp \580 AST/Expr.cpp \581 AST/GenericSubstitution.cpp \582 AST/Init.cpp \583 AST/LinkageSpec.cpp \584 AST/Node.cpp \585 AST/Pass.cpp \586 AST/Print.cpp \587 AST/Stmt.cpp \588 AST/Type.cpp \589 AST/TypeSubstitution.cpp590 591 564 SRC_CODEGEN = \ 592 565 CodeGen/CodeGenerator.cc \ … … 697 670 698 671 .SUFFIXES: 699 .SUFFIXES: .cc . cpp .ll .lo .o .obj .yy700 $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/ AST/module.mk $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__configure_deps)672 .SUFFIXES: .cc .ll .lo .o .obj .yy 673 $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__configure_deps) 701 674 @for dep in $?; do \ 702 675 case '$(am__configure_deps)' in \ … … 718 691 cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ 719 692 esac; 720 $(srcdir)/ AST/module.mk $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__empty):693 $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__empty): 721 694 722 695 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) … … 731 704 clean-noinstLIBRARIES: 732 705 -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) 733 AST/$(am__dirstamp):734 @$(MKDIR_P) AST735 @: > AST/$(am__dirstamp)736 AST/$(DEPDIR)/$(am__dirstamp):737 @$(MKDIR_P) AST/$(DEPDIR)738 @: > AST/$(DEPDIR)/$(am__dirstamp)739 AST/Attribute.$(OBJEXT): AST/$(am__dirstamp) \740 AST/$(DEPDIR)/$(am__dirstamp)741 AST/Convert.$(OBJEXT): AST/$(am__dirstamp) \742 AST/$(DEPDIR)/$(am__dirstamp)743 AST/Decl.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)744 AST/DeclReplacer.$(OBJEXT): AST/$(am__dirstamp) \745 AST/$(DEPDIR)/$(am__dirstamp)746 AST/Expr.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)747 AST/GenericSubstitution.$(OBJEXT): AST/$(am__dirstamp) \748 AST/$(DEPDIR)/$(am__dirstamp)749 AST/Init.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)750 AST/LinkageSpec.$(OBJEXT): AST/$(am__dirstamp) \751 AST/$(DEPDIR)/$(am__dirstamp)752 AST/Node.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)753 AST/Pass.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)754 AST/Print.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)755 AST/Stmt.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)756 AST/Type.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)757 AST/TypeSubstitution.$(OBJEXT): AST/$(am__dirstamp) \758 AST/$(DEPDIR)/$(am__dirstamp)759 706 CodeGen/$(am__dirstamp): 760 707 @$(MKDIR_P) CodeGen … … 1155 1102 mostlyclean-compile: 1156 1103 -rm -f *.$(OBJEXT) 1157 -rm -f AST/*.$(OBJEXT)1158 1104 -rm -f CodeGen/*.$(OBJEXT) 1159 1105 -rm -f CodeTools/*.$(OBJEXT) … … 1178 1124 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MakeLibCfa.Po@am__quote@ 1179 1125 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ 1180 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Attribute.Po@am__quote@1181 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Convert.Po@am__quote@1182 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Decl.Po@am__quote@1183 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/DeclReplacer.Po@am__quote@1184 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Expr.Po@am__quote@1185 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/GenericSubstitution.Po@am__quote@1186 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Init.Po@am__quote@1187 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/LinkageSpec.Po@am__quote@1188 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Node.Po@am__quote@1189 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Pass.Po@am__quote@1190 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Print.Po@am__quote@1191 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Stmt.Po@am__quote@1192 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Type.Po@am__quote@1193 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/TypeSubstitution.Po@am__quote@1194 1126 @AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/CodeGenerator.Po@am__quote@ 1195 1127 @AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/FixMain.Po@am__quote@ … … 1335 1267 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $< 1336 1268 1337 .cpp.o:1338 @am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\1339 @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\1340 @am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po1341 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@1342 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1343 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<1344 1345 .cpp.obj:1346 @am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\1347 @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\1348 @am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po1349 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@1350 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1351 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`1352 1353 .cpp.lo:1354 @am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\1355 @am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\1356 @am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo1357 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@1358 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1359 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<1360 1361 1269 .ll.cc: 1362 1270 $(AM_V_LEX)$(am__skiplex) $(SHELL) $(YLWRAP) $< $(LEX_OUTPUT_ROOT).c $@ -- $(LEXCOMPILE) … … 1491 1399 -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 1492 1400 -rm -f ../driver/$(am__dirstamp) 1493 -rm -f AST/$(DEPDIR)/$(am__dirstamp)1494 -rm -f AST/$(am__dirstamp)1495 1401 -rm -f CodeGen/$(DEPDIR)/$(am__dirstamp) 1496 1402 -rm -f CodeGen/$(am__dirstamp) … … 1538 1444 1539 1445 distclean: distclean-am 1540 -rm -rf ./$(DEPDIR) AST/$(DEPDIR)CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR)1446 -rm -rf ./$(DEPDIR) CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR) 1541 1447 -rm -f Makefile 1542 1448 distclean-am: clean-am distclean-compile distclean-generic \ … … 1584 1490 1585 1491 maintainer-clean: maintainer-clean-am 1586 -rm -rf ./$(DEPDIR) AST/$(DEPDIR)CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR)1492 -rm -rf ./$(DEPDIR) CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR) 1587 1493 -rm -f Makefile 1588 1494 maintainer-clean-am: distclean-am maintainer-clean-generic -
src/ResolvExpr/Unify.cc
rd908563 r933f32f 179 179 result = false; 180 180 } else { 181 result = env.bindVarToVar( 182 var1, var2, TypeDecl::Data{ entry1->second, entry2->second }, needAssertions, 181 result = env.bindVarToVar( 182 var1, var2, TypeDecl::Data{ entry1->second, entry2->second }, needAssertions, 183 183 haveAssertions, openVars, widenMode, indexer ); 184 184 } … … 648 648 649 649 ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func ) { 650 if ( func->returns.empty() ) return new ast::VoidType{}; 651 if ( func->returns.size() == 1 ) return func->returns[0]->get_type(); 652 653 std::vector<ast::ptr<ast::Type>> tys; 654 for ( const ast::DeclWithType * decl : func->returns ) { 655 tys.emplace_back( decl->get_type() ); 656 } 657 return new ast::TupleType{ std::move(tys) }; 650 assert(!"restore after AST added to build"); 651 // if ( func->returns.empty() ) return new ast::VoidType{}; 652 // if ( func->returns.size() == 1 ) return func->returns[0]->get_type(); 653 654 // std::vector<ast::ptr<ast::Type>> tys; 655 // for ( const ast::DeclWithType * decl : func->returns ) { 656 // tys.emplace_back( decl->get_type() ); 657 // } 658 // return new ast::TupleType{ std::move(tys) }; 658 659 } 659 660 } // namespace ResolvExpr -
src/SynTree/Declaration.h
rd908563 r933f32f 286 286 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } 287 287 288 virtual void print( std::ostream &os, Indenter indent = {} ) const override final;288 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 289 289 virtual void printShort( std::ostream &os, Indenter indent = {} ) const override; 290 290 protected: -
src/SynTree/Expression.h
rd908563 r933f32f 731 731 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 732 732 virtual void print( std::ostream & os, Indenter indent = {} ) const; 733 734 friend class ConverterNewToOld;735 private:736 TupleAssignExpr( StmtExpr * stmts );737 733 }; 738 734 -
src/SynTree/TupleExpr.cc
rd908563 r933f32f 105 105 } 106 106 107 TupleAssignExpr::TupleAssignExpr(108 StmtExpr * s )109 : Expression(), stmtExpr(s) {110 }111 112 113 107 TupleAssignExpr::~TupleAssignExpr() { 114 108 delete stmtExpr; -
src/Tuples/TupleExpansion.cc
rd908563 r933f32f 320 320 } 321 321 const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) { 322 // produce the TupleType which aggregates the types of the exprs 323 std::vector<ast::ptr<ast::Type>> types; 324 ast::CV::Qualifiers quals{ 325 ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue | 326 ast::CV::Atomic | ast::CV::Mutex }; 327 328 for ( const ast::Expr * expr : exprs ) { 329 assert( expr->result ); 330 // if the type of any expr is void, the type of the entire tuple is void 331 if ( expr->result->isVoid() ) return new ast::VoidType{}; 332 333 // qualifiers on the tuple type are the qualifiers that exist on all components 334 quals &= expr->result->qualifiers; 335 336 types.emplace_back( expr->result ); 337 } 338 339 if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; } 340 return new ast::TupleType{ std::move(types), quals }; 322 (void) exprs; 323 #warning Not implemented; needs Type.cpp in build 324 assertf(false, "Not implemented; needs Type.cpp in build"); 325 // // produce the TupleType which aggregates the types of the exprs 326 // std::vector<ast::ptr<ast::Type>> types; 327 // ast::CV::Qualifiers quals{ 328 // ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue | 329 // ast::CV::Atomic | ast::CV::Mutex }; 330 331 // for ( const ast::Expr * expr : exprs ) { 332 // assert( expr->result ); 333 // // if the type of any expr is void, the type of the entire tuple is void 334 // if ( expr->result->isVoid() ) return new ast::VoidType{}; 335 336 // // qualifiers on the tuple type are the qualifiers that exist on all components 337 // quals &= expr->result->qualifiers; 338 339 // types.emplace_back( expr->result ); 340 // } 341 342 // if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; } 343 // return new ast::TupleType{ std::move(types), quals }; 341 344 } 342 345 … … 344 347 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( type ) ) { 345 348 if ( inst->get_baseType() && inst->get_baseType()->get_kind() == TypeDecl::Ttype ) { 346 return inst;347 }348 }349 return nullptr;350 }351 352 const ast::TypeInstType * isTtype( const ast::Type * type ) {353 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {354 if ( inst->base && inst->base->kind == ast::TypeVar::Ttype ) {355 349 return inst; 356 350 } -
src/include/cassert
rd908563 r933f32f 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Aug 18 13:19:26 2016 11 // Last Modified By : Andrew Beach12 // Last Modified On : T hu May 23 15:30:00201713 // Update Count : 1 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 1 11:56:01 2017 13 // Update Count : 16 14 14 // 15 15 … … 19 19 20 20 #include_next <cassert> 21 22 #include <string>23 24 template < typename ... Params >25 std::string toString( const Params & ... params );26 21 27 22 #ifdef NDEBUG … … 43 38 #endif 44 39 45 enum StrictAllowNull {NonNull, AllowNull}; 46 47 template<typename T, StrictAllowNull nullable = NonNull, typename U> 40 template<typename T, typename U> 48 41 static inline T strict_dynamic_cast( const U & src ) { 49 if (nullable == AllowNull && src == nullptr) {50 return nullptr;51 }52 assert(src);53 42 T ret = dynamic_cast<T>(src); 54 43 assertf(ret, "%s", toString(src).c_str()); -
src/main.cc
rd908563 r933f32f 40 40 #include "Common/Stats.h" 41 41 #include "Common/PassVisitor.h" 42 // #include "AST/Pass.hpp" 42 43 #include "Common/SemanticError.h" // for SemanticError 43 44 #include "Common/UnimplementedError.h" // for UnimplementedError
Note:
See TracChangeset
for help on using the changeset viewer.