- Timestamp:
- Jun 5, 2019, 8:36:48 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 866545b
- Parents:
- 67130fe (diff), 3cd5fdd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/AST
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Bitfield.hpp
r67130fe rc6a1e8a 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Thu May 910:00:00 201913 // Update Count : 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 5 10:00:00 2019 13 // Update Count : 2 14 14 // 15 15 16 16 #pragma once 17 17 18 #include <strings.h> // for ffs 18 #include <strings.h> // for ffs 19 #include <type_traits> // for is_unsigned 19 20 20 21 /// Make a type a bitfield. … … 24 25 template<typename T> 25 26 struct bitfield : public T { 26 static_assert(sizeof(T) == sizeof(unsigned int), "Type has incorrect size");27 27 using T::val; 28 28 using val_t = decltype(val); 29 static_assert(sizeof(T) == sizeof(unsigned int), "Type has incorrect size"); 30 static_assert(std::is_unsigned<val_t>::value, "Bitfield val field is not unsigned."); 29 31 30 32 constexpr bitfield() : T( 0 ) {} -
src/AST/Convert.cpp
r67130fe rc6a1e8a 749 749 break; 750 750 case ast::ConstantExpr::String: 751 rslt = new ConstantExpr{Constant::from_string( node->rep )}; 751 rslt = new ConstantExpr{Constant{ 752 get<Type>().accept1( node->result ), 753 node->rep, 754 (long long unsigned int)0 755 }}; 752 756 break; 753 757 } … … 2150 2154 GET_ACCEPT_1(result, Type), 2151 2155 old->constant.get_value(), 2152 (unsigned long long) old->intValue() 2156 (unsigned long long) old->intValue(), 2157 ast::ConstantExpr::Kind::Integer 2153 2158 ); 2154 2159 } else if (isFloatlikeConstantType(old->result)) { … … 2160 2165 ); 2161 2166 } else if (isStringlikeConstantType(old->result)) { 2162 rslt = ast::ConstantExpr::from_string( 2163 old->location, 2164 old->constant.get_value() 2167 rslt = new ast::ConstantExpr( 2168 old->location, 2169 GET_ACCEPT_1(result, Type), 2170 old->constant.get_value(), 2171 0, 2172 ast::ConstantExpr::Kind::String 2165 2173 ); 2166 2174 } -
src/AST/Decl.hpp
r67130fe rc6a1e8a 103 103 104 104 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, 105 Init * init = nullptr, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,106 Expr * bitWd = nullptr, std::vector< ptr<Attribute> > && attrs = {},107 Function::Specs fs = {} )105 const Init * init = nullptr, Storage::Classes storage = {}, 106 Linkage::Spec linkage = Linkage::C, const Expr * bitWd = nullptr, 107 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} ) 108 108 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ), 109 109 init( init ), bitfieldWidth( bitWd ) {} -
src/AST/Node.cpp
r67130fe rc6a1e8a 34 34 template< typename node_t, enum ast::Node::ref_type ref_t > 35 35 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); } 36 37 template< typename node_t, enum ast::Node::ref_type ref_t > 38 void ast::ptr_base<node_t, ref_t>::_check() const { if(node) assert(node->was_ever_strong == false || node->strong_count > 0); } 36 39 37 40 template< typename node_t, enum ast::Node::ref_type ref_t > -
src/AST/Node.hpp
r67130fe rc6a1e8a 46 46 }; 47 47 48 bool unique() const { return strong_count == 1; } 49 48 50 private: 49 51 /// Make a copy of this node; should be overridden in subclass with more precise return type … … 56 58 mutable size_t strong_count = 0; 57 59 mutable size_t weak_count = 0; 60 mutable bool was_ever_strong = false; 58 61 59 62 void increment(ref_type ref) const { 60 63 switch (ref) { 61 case ref_type::strong: strong_count++; break;64 case ref_type::strong: strong_count++; was_ever_strong = true; break; 62 65 case ref_type::weak : weak_count ++; break; 63 66 } … … 176 179 } 177 180 178 const node_t * get() const { return node; }179 const node_t * operator->() const { return node; }180 const node_t & operator* () const { return *node; }181 explicit operator bool() const { return node; }182 operator const node_t * () const { return node; }181 const node_t * get() const { _check(); return node; } 182 const node_t * operator->() const { _check(); return node; } 183 const node_t & operator* () const { _check(); return *node; } 184 explicit operator bool() const { _check(); return node; } 185 operator const node_t * () const { _check(); return node; } 183 186 184 187 /// wrapper for convenient access to dynamic_cast 185 188 template<typename o_node_t> 186 const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }189 const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); } 187 190 188 191 /// wrapper for convenient access to strict_dynamic_cast … … 208 211 void _inc( const node_t * other ); 209 212 void _dec( const node_t * other ); 213 void _check() const; 210 214 211 215 protected: -
src/AST/Pass.hpp
r67130fe rc6a1e8a 33 33 #include "AST/Visitor.hpp" 34 34 35 #include " SymTab/Indexer.h"35 #include "AST/SymbolTable.hpp" 36 36 37 37 // Private prelude header, needed for some of the magic tricks this class pulls off … … 61 61 // postvisit/postmutate teminates. 62 62 // | WithVisitorRef - provides an pointer to the templated visitor wrapper 63 // | With Indexer - provides indexer functionality (i.e. up-to-date symbol table)63 // | WithSymbolTable - provides symbol table functionality 64 64 //------------------------------------------------------------------------------------------------- 65 65 template< typename pass_t > … … 206 206 207 207 private: 208 /// Internal RAII guard for indexerfeatures209 struct guard_ indexer{210 guard_ indexer( Pass<pass_t> & pass ): pass( pass ) { __pass::indexer::enter(pass, 0); }211 ~guard_ indexer() { __pass::indexer::leave(pass, 0); }208 /// Internal RAII guard for symbol table features 209 struct guard_symtab { 210 guard_symtab( Pass<pass_t> & pass ): pass( pass ) { __pass::symtab::enter(pass, 0); } 211 ~guard_symtab() { __pass::symtab::leave(pass, 0); } 212 212 Pass<pass_t> & pass; 213 213 }; … … 294 294 }; 295 295 296 /// Use when the templated visitor should update the indexer297 struct With Indexer{298 Sym Tab::Indexer indexer;296 /// Use when the templated visitor should update the symbol table 297 struct WithSymbolTable { 298 SymbolTable symtab; 299 299 }; 300 300 } -
src/AST/Pass.impl.hpp
r67130fe rc6a1e8a 398 398 VISIT( 399 399 { 400 guard_ indexerguard { *this };400 guard_symtab guard { *this }; 401 401 maybe_accept( node, &ObjectDecl::type ); 402 402 } … … 406 406 ) 407 407 408 __pass:: indexer::addId( pass, 0, node );408 __pass::symtab::addId( pass, 0, node ); 409 409 410 410 VISIT_END( DeclWithType, node ); … … 417 417 VISIT_START( node ); 418 418 419 __pass:: indexer::addId( pass, 0, node );419 __pass::symtab::addId( pass, 0, node ); 420 420 421 421 VISIT(maybe_accept( node, &FunctionDecl::withExprs );) 422 422 { 423 423 // with clause introduces a level of scope (for the with expression members). 424 // with clause exprs are added to the indexerbefore parameters so that parameters424 // with clause exprs are added to the symbol table before parameters so that parameters 425 425 // shadow with exprs and not the other way around. 426 guard_ indexerguard { *this };427 __pass:: indexer::addWith( pass, 0, node->withExprs, node );426 guard_symtab guard { *this }; 427 __pass::symtab::addWith( pass, 0, node->withExprs, node ); 428 428 { 429 guard_ indexerguard { *this };429 guard_symtab guard { *this }; 430 430 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 431 431 static ast::ObjectDecl func( … … 436 436 ) 437 437 ); 438 __pass:: indexer::addId( pass, 0, &func );438 __pass::symtab::addId( pass, 0, &func ); 439 439 VISIT( 440 440 maybe_accept( node, &FunctionDecl::type ); … … 460 460 // make up a forward declaration and add it before processing the members 461 461 // needs to be on the heap because addStruct saves the pointer 462 __pass:: indexer::addStructFwd( pass, 0, node );463 464 VISIT({ 465 guard_ indexerguard { * this };462 __pass::symtab::addStructFwd( pass, 0, node ); 463 464 VISIT({ 465 guard_symtab guard { * this }; 466 466 maybe_accept( node, &StructDecl::params ); 467 467 maybe_accept( node, &StructDecl::members ); … … 469 469 470 470 // this addition replaces the forward declaration 471 __pass:: indexer::addStruct( pass, 0, node );471 __pass::symtab::addStruct( pass, 0, node ); 472 472 473 473 VISIT_END( Decl, node ); … … 481 481 482 482 // make up a forward declaration and add it before processing the members 483 __pass:: indexer::addUnionFwd( pass, 0, node );484 485 VISIT({ 486 guard_ indexerguard { * this };483 __pass::symtab::addUnionFwd( pass, 0, node ); 484 485 VISIT({ 486 guard_symtab guard { * this }; 487 487 maybe_accept( node, &UnionDecl::params ); 488 488 maybe_accept( node, &UnionDecl::members ); 489 489 }) 490 490 491 __pass:: indexer::addUnion( pass, 0, node );491 __pass::symtab::addUnion( pass, 0, node ); 492 492 493 493 VISIT_END( Decl, node ); … … 500 500 VISIT_START( node ); 501 501 502 __pass:: indexer::addEnum( pass, 0, node );502 __pass::symtab::addEnum( pass, 0, node ); 503 503 504 504 VISIT( … … 518 518 519 519 VISIT({ 520 guard_ indexerguard { *this };520 guard_symtab guard { *this }; 521 521 maybe_accept( node, &TraitDecl::params ); 522 522 maybe_accept( node, &TraitDecl::members ); 523 523 }) 524 524 525 __pass:: indexer::addTrait( pass, 0, node );525 __pass::symtab::addTrait( pass, 0, node ); 526 526 527 527 VISIT_END( Decl, node ); … … 535 535 536 536 VISIT({ 537 guard_ indexerguard { *this };537 guard_symtab guard { *this }; 538 538 maybe_accept( node, &TypeDecl::params ); 539 539 maybe_accept( node, &TypeDecl::base ); … … 543 543 // note that assertions come after the type is added to the symtab, since they are not part of the type proper 544 544 // and may depend on the type itself 545 __pass:: indexer::addType( pass, 0, node );545 __pass::symtab::addType( pass, 0, node ); 546 546 547 547 VISIT( … … 549 549 550 550 { 551 guard_ indexerguard { *this };551 guard_symtab guard { *this }; 552 552 maybe_accept( node, &TypeDecl::init ); 553 553 } … … 564 564 565 565 VISIT({ 566 guard_ indexerguard { *this };566 guard_symtab guard { *this }; 567 567 maybe_accept( node, &TypedefDecl::params ); 568 568 maybe_accept( node, &TypedefDecl::base ); 569 569 }) 570 570 571 __pass:: indexer::addType( pass, 0, node );571 __pass::symtab::addType( pass, 0, node ); 572 572 573 573 VISIT( maybe_accept( node, &TypedefDecl::assertions ); ) … … 611 611 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 612 612 auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() { 613 if ( ! inFunction ) __pass:: indexer::enter(pass, 0);613 if ( ! inFunction ) __pass::symtab::enter(pass, 0); 614 614 }, [this, inFunction = this->inFunction]() { 615 if ( ! inFunction ) __pass:: indexer::leave(pass, 0);615 if ( ! inFunction ) __pass::symtab::leave(pass, 0); 616 616 }); 617 617 ValueGuard< bool > guard2( inFunction ); … … 669 669 VISIT({ 670 670 // if statements introduce a level of scope (for the initialization) 671 guard_ indexerguard { *this };671 guard_symtab guard { *this }; 672 672 maybe_accept( node, &IfStmt::inits ); 673 673 maybe_accept( node, &IfStmt::cond ); … … 687 687 VISIT({ 688 688 // while statements introduce a level of scope (for the initialization) 689 guard_ indexerguard { *this };689 guard_symtab guard { *this }; 690 690 maybe_accept( node, &WhileStmt::inits ); 691 691 maybe_accept( node, &WhileStmt::cond ); … … 704 704 VISIT({ 705 705 // for statements introduce a level of scope (for the initialization) 706 guard_ indexerguard { *this };706 guard_symtab guard { *this }; 707 707 maybe_accept( node, &ForStmt::inits ); 708 708 maybe_accept( node, &ForStmt::cond ); … … 800 800 VISIT({ 801 801 // catch statements introduce a level of scope (for the caught exception) 802 guard_ indexerguard { *this };802 guard_symtab guard { *this }; 803 803 maybe_accept( node, &CatchStmt::decl ); 804 804 maybe_accept( node, &CatchStmt::cond ); … … 901 901 { 902 902 // catch statements introduce a level of scope (for the caught exception) 903 guard_ indexerguard { *this };904 __pass:: indexer::addWith( pass, 0, node->exprs, node );903 guard_symtab guard { *this }; 904 __pass::symtab::addWith( pass, 0, node->exprs, node ); 905 905 maybe_accept( node, &WithStmt::stmt ); 906 906 } … … 953 953 VISIT( 954 954 { 955 guard_ indexerguard { *this };955 guard_symtab guard { *this }; 956 956 maybe_accept( node, &ApplicationExpr::result ); 957 957 } … … 971 971 VISIT( 972 972 { 973 guard_ indexerguard { *this };973 guard_symtab guard { *this }; 974 974 maybe_accept( node, &UntypedExpr::result ); 975 975 } … … 988 988 989 989 VISIT({ 990 guard_ indexerguard { *this };990 guard_symtab guard { *this }; 991 991 maybe_accept( node, &NameExpr::result ); 992 992 }) … … 1002 1002 1003 1003 VISIT({ 1004 guard_ indexerguard { *this };1004 guard_symtab guard { *this }; 1005 1005 maybe_accept( node, &CastExpr::result ); 1006 1006 } … … 1018 1018 1019 1019 VISIT({ 1020 guard_ indexerguard { *this };1020 guard_symtab guard { *this }; 1021 1021 maybe_accept( node, &KeywordCastExpr::result ); 1022 1022 } … … 1034 1034 1035 1035 VISIT({ 1036 guard_ indexerguard { *this };1036 guard_symtab guard { *this }; 1037 1037 maybe_accept( node, &VirtualCastExpr::result ); 1038 1038 } … … 1050 1050 1051 1051 VISIT({ 1052 guard_ indexerguard { *this };1052 guard_symtab guard { *this }; 1053 1053 maybe_accept( node, &AddressExpr::result ); 1054 1054 } … … 1066 1066 1067 1067 VISIT({ 1068 guard_ indexerguard { *this };1068 guard_symtab guard { *this }; 1069 1069 maybe_accept( node, &LabelAddressExpr::result ); 1070 1070 }) … … 1080 1080 1081 1081 VISIT({ 1082 guard_ indexerguard { *this };1082 guard_symtab guard { *this }; 1083 1083 maybe_accept( node, &UntypedMemberExpr::result ); 1084 1084 } … … 1097 1097 1098 1098 VISIT({ 1099 guard_ indexerguard { *this };1099 guard_symtab guard { *this }; 1100 1100 maybe_accept( node, &MemberExpr::result ); 1101 1101 } … … 1113 1113 1114 1114 VISIT({ 1115 guard_ indexerguard { *this };1115 guard_symtab guard { *this }; 1116 1116 maybe_accept( node, &VariableExpr::result ); 1117 1117 }) … … 1127 1127 1128 1128 VISIT({ 1129 guard_ indexerguard { *this };1129 guard_symtab guard { *this }; 1130 1130 maybe_accept( node, &ConstantExpr::result ); 1131 1131 }) … … 1141 1141 1142 1142 VISIT({ 1143 guard_ indexerguard { *this };1143 guard_symtab guard { *this }; 1144 1144 maybe_accept( node, &SizeofExpr::result ); 1145 1145 } … … 1161 1161 1162 1162 VISIT({ 1163 guard_ indexerguard { *this };1163 guard_symtab guard { *this }; 1164 1164 maybe_accept( node, &AlignofExpr::result ); 1165 1165 } … … 1181 1181 1182 1182 VISIT({ 1183 guard_ indexerguard { *this };1183 guard_symtab guard { *this }; 1184 1184 maybe_accept( node, &UntypedOffsetofExpr::result ); 1185 1185 } … … 1197 1197 1198 1198 VISIT({ 1199 guard_ indexerguard { *this };1199 guard_symtab guard { *this }; 1200 1200 maybe_accept( node, &OffsetofExpr::result ); 1201 1201 } … … 1213 1213 1214 1214 VISIT({ 1215 guard_ indexerguard { *this };1215 guard_symtab guard { *this }; 1216 1216 maybe_accept( node, &OffsetPackExpr::result ); 1217 1217 } … … 1229 1229 1230 1230 VISIT({ 1231 guard_ indexerguard { *this };1231 guard_symtab guard { *this }; 1232 1232 maybe_accept( node, &LogicalExpr::result ); 1233 1233 } … … 1246 1246 1247 1247 VISIT({ 1248 guard_ indexerguard { *this };1248 guard_symtab guard { *this }; 1249 1249 maybe_accept( node, &ConditionalExpr::result ); 1250 1250 } … … 1264 1264 1265 1265 VISIT({ 1266 guard_ indexerguard { *this };1266 guard_symtab guard { *this }; 1267 1267 maybe_accept( node, &CommaExpr::result ); 1268 1268 } … … 1281 1281 1282 1282 VISIT({ 1283 guard_ indexerguard { *this };1283 guard_symtab guard { *this }; 1284 1284 maybe_accept( node, &TypeExpr::result ); 1285 1285 } … … 1297 1297 1298 1298 VISIT({ 1299 guard_ indexerguard { *this };1299 guard_symtab guard { *this }; 1300 1300 maybe_accept( node, &AsmExpr::result ); 1301 1301 } … … 1315 1315 1316 1316 VISIT({ 1317 guard_ indexerguard { *this };1317 guard_symtab guard { *this }; 1318 1318 maybe_accept( node, &ImplicitCopyCtorExpr::result ); 1319 1319 } … … 1331 1331 1332 1332 VISIT({ 1333 guard_ indexerguard { *this };1333 guard_symtab guard { *this }; 1334 1334 maybe_accept( node, &ConstructorExpr::result ); 1335 1335 } … … 1347 1347 1348 1348 VISIT({ 1349 guard_ indexerguard { *this };1349 guard_symtab guard { *this }; 1350 1350 maybe_accept( node, &CompoundLiteralExpr::result ); 1351 1351 } … … 1363 1363 1364 1364 VISIT({ 1365 guard_ indexerguard { *this };1365 guard_symtab guard { *this }; 1366 1366 maybe_accept( node, &RangeExpr::result ); 1367 1367 } … … 1380 1380 1381 1381 VISIT({ 1382 guard_ indexerguard { *this };1382 guard_symtab guard { *this }; 1383 1383 maybe_accept( node, &UntypedTupleExpr::result ); 1384 1384 } … … 1396 1396 1397 1397 VISIT({ 1398 guard_ indexerguard { *this };1398 guard_symtab guard { *this }; 1399 1399 maybe_accept( node, &TupleExpr::result ); 1400 1400 } … … 1412 1412 1413 1413 VISIT({ 1414 guard_ indexerguard { *this };1414 guard_symtab guard { *this }; 1415 1415 maybe_accept( node, &TupleIndexExpr::result ); 1416 1416 } … … 1428 1428 1429 1429 VISIT({ 1430 guard_ indexerguard { *this };1430 guard_symtab guard { *this }; 1431 1431 maybe_accept( node, &TupleAssignExpr::result ); 1432 1432 } … … 1454 1454 1455 1455 { 1456 guard_ indexerguard { *this };1456 guard_symtab guard { *this }; 1457 1457 maybe_accept( node, &StmtExpr::result ); 1458 1458 } … … 1472 1472 1473 1473 VISIT({ 1474 guard_ indexerguard { *this };1474 guard_symtab guard { *this }; 1475 1475 maybe_accept( node, &UniqueExpr::result ); 1476 1476 } … … 1488 1488 1489 1489 VISIT({ 1490 guard_ indexerguard { *this };1490 guard_symtab guard { *this }; 1491 1491 maybe_accept( node, &UntypedInitExpr::result ); 1492 1492 } … … 1505 1505 1506 1506 VISIT({ 1507 guard_ indexerguard { *this };1507 guard_symtab guard { *this }; 1508 1508 maybe_accept( node, &InitExpr::result ); 1509 1509 } … … 1522 1522 1523 1523 VISIT({ 1524 guard_ indexerguard { *this };1524 guard_symtab guard { *this }; 1525 1525 maybe_accept( node, &DeletedExpr::result ); 1526 1526 } … … 1539 1539 1540 1540 VISIT({ 1541 guard_ indexerguard { *this };1541 guard_symtab guard { *this }; 1542 1542 maybe_accept( node, &DefaultArgExpr::result ); 1543 1543 } … … 1555 1555 1556 1556 VISIT({ 1557 guard_ indexerguard { *this };1557 guard_symtab guard { *this }; 1558 1558 maybe_accept( node, &GenericExpr::result ); 1559 1559 } … … 1566 1566 const Type * type = nullptr; 1567 1567 if( assoc.type ) { 1568 guard_ indexerguard { *this };1568 guard_symtab guard { *this }; 1569 1569 type = assoc.type->accept( *this ); 1570 1570 if( type != assoc.type ) mutated = true; … … 1682 1682 VISIT_START( node ); 1683 1683 1684 __pass:: indexer::addStruct( pass, 0, node->name );1685 1686 VISIT({ 1687 guard_ indexerguard { *this };1684 __pass::symtab::addStruct( pass, 0, node->name ); 1685 1686 VISIT({ 1687 guard_symtab guard { *this }; 1688 1688 maybe_accept( node, &StructInstType::forall ); 1689 1689 maybe_accept( node, &StructInstType::params ); … … 1699 1699 VISIT_START( node ); 1700 1700 1701 __pass:: indexer::addStruct( pass, 0, node->name );1701 __pass::symtab::addStruct( pass, 0, node->name ); 1702 1702 1703 1703 { 1704 guard_ indexerguard { *this };1704 guard_symtab guard { *this }; 1705 1705 maybe_accept( node, &UnionInstType::forall ); 1706 1706 maybe_accept( node, &UnionInstType::params ); … … 1893 1893 std::unordered_map< std::string, ast::ptr< ast::Type > > new_map; 1894 1894 for ( const auto & p : node->typeEnv ) { 1895 guard_ indexerguard { *this };1895 guard_symtab guard { *this }; 1896 1896 auto new_node = p.second->accept( *this ); 1897 1897 if (new_node != p.second) mutated = false; … … 1909 1909 std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map; 1910 1910 for ( const auto & p : node->varEnv ) { 1911 guard_ indexerguard { *this };1911 guard_symtab guard { *this }; 1912 1912 auto new_node = p.second->accept( *this ); 1913 1913 if (new_node != p.second) mutated = false; -
src/AST/Pass.proto.hpp
r67130fe rc6a1e8a 265 265 }; 266 266 267 // Finally certain pass desire an up to date indexerautomatically268 // detect the presence of a member name indexerand call all the members appropriately269 namespace indexer{267 // Finally certain pass desire an up to date symbol table automatically 268 // detect the presence of a member name `symtab` and call all the members appropriately 269 namespace symtab { 270 270 // Some simple scoping rules 271 271 template<typename pass_t> 272 static inline auto enter( pass_t & pass, int ) -> decltype( pass. indexer.enterScope(), void() ) {273 pass. indexer.enterScope();272 static inline auto enter( pass_t & pass, int ) -> decltype( pass.symtab.enterScope(), void() ) { 273 pass.symtab.enterScope(); 274 274 } 275 275 … … 278 278 279 279 template<typename pass_t> 280 static inline auto leave( pass_t & pass, int ) -> decltype( pass. indexer.leaveScope(), void() ) {281 pass. indexer.leaveScope();280 static inline auto leave( pass_t & pass, int ) -> decltype( pass.symtab.leaveScope(), void() ) { 281 pass.symtab.leaveScope(); 282 282 } 283 283 … … 285 285 static inline auto leave( pass_t &, long ) {} 286 286 287 // The indexerhas 2 kind of functions mostly, 1 argument and 2 arguments287 // The symbol table has 2 kind of functions mostly, 1 argument and 2 arguments 288 288 // Create macro to condense these common patterns 289 #define INDEXER_FUNC1( func, type ) \289 #define SYMTAB_FUNC1( func, type ) \ 290 290 template<typename pass_t> \ 291 static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass. indexer.func( arg ), void() ) {\292 pass. indexer.func( arg ); \291 static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass.symtab.func( arg ), void() ) {\ 292 pass.symtab.func( arg ); \ 293 293 } \ 294 294 \ … … 296 296 static inline void func( pass_t &, long, type ) {} 297 297 298 #define INDEXER_FUNC2( func, type1, type2 ) \298 #define SYMTAB_FUNC2( func, type1, type2 ) \ 299 299 template<typename pass_t> \ 300 static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass. indexer.func( arg1, arg2 ), void () ) {\301 pass. indexer.func( arg1, arg2 ); \300 static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass.symtab.func( arg1, arg2 ), void () ) {\ 301 pass.symtab.func( arg1, arg2 ); \ 302 302 } \ 303 303 \ … … 305 305 static inline void func( pass_t &, long, type1, type2 ) {} 306 306 307 INDEXER_FUNC1( addId , const DeclWithType * );308 INDEXER_FUNC1( addType , const NamedTypeDecl * );309 INDEXER_FUNC1( addStruct , const StructDecl * );310 INDEXER_FUNC1( addEnum , const EnumDecl * );311 INDEXER_FUNC1( addUnion , const UnionDecl * );312 INDEXER_FUNC1( addTrait , const TraitDecl * );313 INDEXER_FUNC2( addWith , const std::vector< ptr<Expr> > &, const Node * );307 SYMTAB_FUNC1( addId , const DeclWithType * ); 308 SYMTAB_FUNC1( addType , const NamedTypeDecl * ); 309 SYMTAB_FUNC1( addStruct , const StructDecl * ); 310 SYMTAB_FUNC1( addEnum , const EnumDecl * ); 311 SYMTAB_FUNC1( addUnion , const UnionDecl * ); 312 SYMTAB_FUNC1( addTrait , const TraitDecl * ); 313 SYMTAB_FUNC2( addWith , const std::vector< ptr<Expr> > &, const Node * ); 314 314 315 315 // A few extra functions have more complicated behaviour, they are hand written 316 316 template<typename pass_t> 317 static inline auto addStructFwd( pass_t & pass, int, const ast::StructDecl * decl ) -> decltype( pass. indexer.addStruct( decl ), void() ) {317 static inline auto addStructFwd( pass_t & pass, int, const ast::StructDecl * decl ) -> decltype( pass.symtab.addStruct( decl ), void() ) { 318 318 ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name ); 319 319 fwd->params = decl->params; 320 pass. indexer.addStruct( fwd );320 pass.symtab.addStruct( fwd ); 321 321 } 322 322 … … 325 325 326 326 template<typename pass_t> 327 static inline auto addUnionFwd( pass_t & pass, int, const ast::UnionDecl * decl ) -> decltype( pass. indexer.addUnion( decl ), void() ) {327 static inline auto addUnionFwd( pass_t & pass, int, const ast::UnionDecl * decl ) -> decltype( pass.symtab.addUnion( decl ), void() ) { 328 328 UnionDecl * fwd = new UnionDecl( decl->location, decl->name ); 329 329 fwd->params = decl->params; 330 pass. indexer.addUnion( fwd );330 pass.symtab.addUnion( fwd ); 331 331 } 332 332 … … 335 335 336 336 template<typename pass_t> 337 static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass. indexer.addStruct( str ), void() ) {338 if ( ! pass. indexer.lookupStruct( str ) ) {339 pass. indexer.addStruct( str );337 static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.symtab.addStruct( str ), void() ) { 338 if ( ! pass.symtab.lookupStruct( str ) ) { 339 pass.symtab.addStruct( str ); 340 340 } 341 341 } … … 345 345 346 346 template<typename pass_t> 347 static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass. indexer.addUnion( str ), void() ) {348 if ( ! pass. indexer.lookupUnion( str ) ) {349 pass. indexer.addUnion( str );347 static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.symtab.addUnion( str ), void() ) { 348 if ( ! pass.symtab.lookupUnion( str ) ) { 349 pass.symtab.addUnion( str ); 350 350 } 351 351 } … … 354 354 static inline void addUnion( pass_t &, long, const std::string & ) {} 355 355 356 #undef INDEXER_FUNC1357 #undef INDEXER_FUNC2356 #undef SYMTAB_FUNC1 357 #undef SYMTAB_FUNC2 358 358 }; 359 359 }; -
src/AST/Print.hpp
r67130fe rc6a1e8a 29 29 void print( std::ostream & os, const ast::Node * node, Indenter indent = {} ); 30 30 31 /// Wrap any standard format printer (matching above) with integer Indenter constructor32 template<typename T>33 inline void print( std::ostream & os, T && x, unsigned int indent ) {34 print( os, std::forward<T>(x), Indenter{ Indenter::tabsize, indent });35 }36 37 31 /// Print a declaration in its short form 38 32 void printShort( std::ostream & os, const ast::Decl * node, Indenter indent = {} ); 39 33 40 34 inline void printShort( std::ostream & os, const ast::Decl * node, unsigned int indent ) { 41 printShort( os, node, Indenter{ Indenter::tabsize,indent } );35 printShort( os, node, Indenter{ indent } ); 42 36 } 43 37 -
src/AST/SymbolTable.hpp
r67130fe rc6a1e8a 85 85 86 86 public: 87 explicitSymbolTable();87 SymbolTable(); 88 88 ~SymbolTable(); 89 89 … … 123 123 void addType( const NamedTypeDecl * decl ); 124 124 /// Adds a struct declaration to the symbol table by name 125 void addStruct( const std::string & id );125 void addStruct( const std::string & id ); 126 126 /// Adds a struct declaration to the symbol table 127 127 void addStruct( const StructDecl * decl ); 128 128 /// Adds an enum declaration to the symbol table 129 void addEnum( const EnumDecl * decl );129 void addEnum( const EnumDecl * decl ); 130 130 /// Adds a union declaration to the symbol table by name 131 void addUnion( const std::string & id );131 void addUnion( const std::string & id ); 132 132 /// Adds a union declaration to the symbol table 133 133 void addUnion( const UnionDecl * decl ); -
src/AST/porting.md
r67130fe rc6a1e8a 109 109 * `SymTab::Indexer` => `ast::SymbolTable` 110 110 * `SymTab/Indexer.{h,cc}` => `AST/SymbolTable.{hpp,cpp}` 111 * **TODO**`WithIndexer` => `WithSymbolTable`111 * `WithIndexer` => `WithSymbolTable` 112 112 * `indexer` => `symTab` 113 113 * `IdData::deleteStmt` => `IdData::deleter` 114 114 * `lookupId()` now returns a vector rather than an out-param list 115 116 115 * To avoid name collisions: 116 * `SymTab::Mangler` => `Mangle` 117 117 * `ResolvExpr::TypeEnvironment` => `ast::TypeEnvironment` 118 118 * in `AST/TypeEnvironment.hpp` … … 295 295 * changed `WidenMode widenMode` => `WidenMode widen` 296 296 297 `Alternative` => `Candidate` 298 * `openVars` => `open` 299 297 300 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes 298 301
Note:
See TracChangeset
for help on using the changeset viewer.