Changes in / [8d70648:d88f8b3b]
- Location:
- src
- Files:
-
- 4 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r8d70648 rd88f8b3b 75 75 std::list< T * > acceptL( const U & container ) { 76 76 std::list< T * > ret; 77 for ( 77 for (auto ptr : container ) { 78 78 ret.emplace_back( accept1( ptr ) ); 79 79 } … … 1445 1445 }; 1446 1446 cache.emplace( old, decl ); 1447 decl->withExprs = GET_ACCEPT_V(withExprs, Expr);1448 1447 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); 1449 1448 decl->scopeLevel = old->scopeLevel; -
src/AST/Decl.cpp
r8d70648 rd88f8b3b 17 17 18 18 #include <cassert> // for assert, strict_dynamic_cast 19 #include <iostream>20 19 #include <string> 21 20 #include <unordered_map> … … 71 70 } 72 71 73 std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) {74 return out << data.kind << ", " << data.isComplete;75 }76 77 72 // --- EnumDecl 78 73 -
src/AST/Decl.hpp
r8d70648 rd88f8b3b 16 16 #pragma once 17 17 18 #include <iosfwd>19 18 #include <string> // for string, to_string 20 19 #include <unordered_map> … … 122 121 ptr<FunctionType> type; 123 122 ptr<CompoundStmt> stmts; 124 std:: vector< ptr<Expr> > withExprs;123 std::list< ptr<Expr> > withExprs; 125 124 126 125 FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type, … … 173 172 174 173 Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {} 175 Data( const TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {}174 Data( TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {} 176 175 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {} 177 Data( const Data & d1, const Data& d2 )176 Data( const Data& d1, const Data& d2 ) 178 177 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 179 178 180 bool operator== ( const Data 179 bool operator== ( const Data& o ) const { 181 180 return kind == o.kind && isComplete == o.isComplete; 182 181 } 183 bool operator!= ( const Data 182 bool operator!= ( const Data& o ) const { return !(*this == o); } 184 183 }; 185 184 … … 201 200 MUTATE_FRIEND 202 201 }; 203 204 std::ostream & operator<< ( std::ostream &, const TypeDecl::Data & );205 202 206 203 /// C-style typedef `typedef Foo Bar` -
src/AST/Expr.cpp
r8d70648 rd88f8b3b 64 64 // references have been removed, in which case dereference returns an lvalue of the 65 65 // base type 66 ret->result = base; 67 add_lvalue( ret->result ); 66 ret->result.set_and_mutate( base )->set_lvalue( true ); 68 67 } 69 68 } … … 174 173 assert( var ); 175 174 assert( var->get_type() ); 176 result = var->get_type(); 177 add_lvalue( result ); 175 result.set_and_mutate( var->get_type() )->set_lvalue( true ); 178 176 } 179 177 … … 308 306 : Expr( loc ), init( i ) { 309 307 assert( t && i ); 310 result = t; 311 add_lvalue( result ); 308 result.set_and_mutate( t )->set_lvalue( true ); 312 309 } 313 310 … … 325 322 "index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); 326 323 // like MemberExpr, TupleIndexExpr is always an lvalue 327 result = type->types[ index ]; 328 add_lvalue( result ); 324 result.set_and_mutate( type->types[ index ] )->set_lvalue( true ); 329 325 } 330 326 -
src/AST/Node.hpp
r8d70648 rd88f8b3b 113 113 } 114 114 115 ptr_base( ptr_base && o ) : node(o.node) { o.node = nullptr; } 115 ptr_base( ptr_base && o ) : node(o.node) { 116 if( node ) _inc(node); 117 } 116 118 117 119 template< enum Node::ref_type o_ref_t > … … 137 139 138 140 ptr_base & operator=( ptr_base && o ) { 139 if ( node == o.node ) return *this; 140 if ( node ) _dec(node); 141 node = o.node; 142 o.node = nullptr; 141 assign(o.node); 143 142 return *this; 144 143 } -
src/AST/Pass.hpp
r8d70648 rd88f8b3b 179 179 180 180 template<typename pass_type> 181 friend void accept _all( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor );181 friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor ); 182 182 private: 183 183 -
src/AST/Pass.proto.hpp
r8d70648 rd88f8b3b 312 312 INDEXER_FUNC1( addTrait , const TraitDecl * ); 313 313 INDEXER_FUNC2( addWith , const std::vector< ptr<Expr> > &, const Node * ); 314 INDEXER_FUNC2( addWith , const std::list < ptr<Expr> > &, const Node * ); 314 315 315 316 // A few extra functions have more complicated behaviour, they are hand written -
src/AST/Print.hpp
r8d70648 rd88f8b3b 17 17 18 18 #include <iosfwd> 19 #include <utility> // for forward20 19 21 20 #include "AST/Node.hpp" … … 29 28 void print( std::ostream & os, const ast::Node * node, Indenter indent = {} ); 30 29 31 /// Wrap any standard format printer (matching above) with integer Indenter constructor 32 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 }); 30 inline void print( std::ostream & os, const ast::Node * node, unsigned int indent ) { 31 print( os, node, Indenter{ Indenter::tabsize, indent }); 35 32 } 36 33 -
src/AST/Type.cpp
r8d70648 rd88f8b3b 27 27 namespace ast { 28 28 29 const Type * Type::getComponent( unsigned i ) const{29 const Type * Type::getComponent( unsigned i ) { 30 30 assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i ); 31 31 return this; 32 32 } 33 33 34 const Type * Type::stripDeclarator() const{34 const Type * Type::stripDeclarator() { 35 35 const Type * t; 36 36 const Type * a; … … 39 39 } 40 40 41 const Type * Type::stripReferences() const{41 const Type * Type::stripReferences() { 42 42 const Type * t; 43 43 const ReferenceType * r; -
src/AST/Type.hpp
r8d70648 rd88f8b3b 25 25 #include "Decl.hpp" // for AggregateDecl subclasses 26 26 #include "Fwd.hpp" 27 #include "Node.hpp" // for Node, ptr , ptr_base27 #include "Node.hpp" // for Node, ptr 28 28 #include "TypeVar.hpp" 29 29 #include "Visitor.hpp" … … 58 58 virtual bool isVoid() const { return size() == 0; } 59 59 /// Get the i'th component of this type 60 virtual const Type * getComponent( unsigned i ) const;60 virtual const Type * getComponent( unsigned i ); 61 61 62 62 /// type without outer pointers and arrays 63 const Type * stripDeclarator() const;63 const Type * stripDeclarator(); 64 64 /// type without outer references 65 const Type * stripReferences() const;65 const Type * stripReferences(); 66 66 /// number of reference occuring consecutively on the outermost layer of this type 67 67 /// (i.e. do not count references nested within other types) … … 75 75 MUTATE_FRIEND 76 76 }; 77 78 /// Set the `is_lvalue` qualifier on this type, cloning only if necessary79 template< enum Node::ref_type ref_t >80 void add_lvalue( ptr_base< Type, ref_t > & p ) {81 if ( ! p->qualifiers.is_lvalue ) p.get_and_mutate()->qualifiers.is_lvalue = true;82 }83 84 /// Clear the qualifiers on this type, cloning only if necessary85 template< enum Node::ref_type ref_t >86 void clear_qualifiers( ptr_base< Type, ref_t > & p ) {87 if ( p->qualifiers != CV::Qualifiers{} ) p.get_and_mutate()->qualifiers = CV::Qualifiers{};88 }89 77 90 78 /// `void` … … 449 437 unsigned size() const override { return types.size(); } 450 438 451 const Type * getComponent( unsigned i ) constoverride {439 const Type * getComponent( unsigned i ) override { 452 440 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 453 441 i, size() ); -
src/AST/module.mk
r8d70648 rd88f8b3b 28 28 AST/Print.cpp \ 29 29 AST/Stmt.cpp \ 30 AST/SymbolTable.cpp \31 30 AST/Type.cpp \ 32 AST/TypeEnvironment.cpp \33 31 AST/TypeSubstitution.cpp 34 32 -
src/AST/porting.md
r8d70648 rd88f8b3b 104 104 * `LinkageSpec::isMangled(Spec)` etc. => `Spec.is_mangled` etc. 105 105 * `LinkageSpec::Intrinsic` etc. => `ast::Linkage::Intrinsic` etc. 106 * Boolean flags to `SymTab::Mangler::mangle` are now a `SymTab::Mangle::Mode` struct107 * uses `bitfield`108 * Because `Indexer` isn't a terribly evocative name:109 * `SymTab::Indexer` => `ast::SymbolTable`110 * `SymTab/Indexer.{h,cc}` => `AST/SymbolTable.{hpp,cpp}`111 * **TODO** `WithIndexer` => `WithSymbolTable`112 * `indexer` => `symTab`113 * `IdData::deleteStmt` => `IdData::deleter`114 * `lookupId()` now returns a vector rather than an out-param list115 * To avoid name collisions:116 * `SymTab::Mangler` => `Mangle`117 * `ResolvExpr::TypeEnvironment` => `ast::TypeEnvironment`118 * in `AST/TypeEnvironment.hpp`119 106 * Boolean constructor parameters get replaced with a dedicated flag enum: 120 107 * e.g. `bool isVarLen;` => `enum LengthFlag { FixedLen, VariableLen };` `LengthFlag isVarLen;` … … 274 261 * feature is `type@thing` e.g. `int@MAX` 275 262 276 `referenceToRvalueConversion`277 * now returns `const Expr *` rather than mutating argument278 279 `printAssertionSet`, `printOpenVarSet`280 * `ostream &` now first argument, for consistency281 282 `EqvClass`283 * `type` => `bound`284 285 `TypeEnvironment`286 * `makeSubstitution()` => `writeToSubstitution()`287 * `isEmpty()` => `empty()`288 * removed `clone()` in favour of explicit copies289 290 `occurs`291 * moved to be helper function in `TypeEnvironment.cpp` (its only use)292 293 263 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes 294 264 -
src/GenPoly/GenPoly.cc
r8d70648 rd88f8b3b 24 24 #include <vector> // for vector 25 25 26 #include "AST/Type.hpp"27 26 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::const_it... 28 27 #include "ResolvExpr/typeops.h" // for flatten … … 263 262 } else { 264 263 return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise 265 }266 }267 268 const ast::FunctionType * getFunctionType( const ast::Type * ty ) {269 if ( auto pty = dynamic_cast< const ast::PointerType * >( ty ) ) {270 return pty->base.as< ast::FunctionType >();271 } else {272 return dynamic_cast< const ast::FunctionType * >( ty );273 264 } 274 265 } -
src/GenPoly/GenPoly.h
r8d70648 rd88f8b3b 20 20 21 21 #include "ErasableScopedMap.h" // for ErasableScopedMap 22 #include "AST/Fwd.hpp"23 22 #include "SymTab/Mangler.h" // for Mangler 24 23 #include "SynTree/Declaration.h" // for TypeDecl::Data, AggregateDecl, Type... … … 73 72 /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise 74 73 FunctionType *getFunctionType( Type *ty ); 75 const ast::FunctionType * getFunctionType( const ast::Type * ty );76 74 77 75 /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise; -
src/InitTweak/InitTweak.cc
r8d70648 rd88f8b3b 756 756 } 757 757 758 bool isCopyFunction( const ast::FunctionDecl * decl ) {759 const ast::FunctionType * ftype = decl->type;760 if ( ftype->params.size() != 2 ) return false;761 762 const ast::Type * t1 = getPointerBase( ftype->params.front()->get_type() );763 if ( ! t1 ) return false;764 const ast::Type * t2 = ftype->params.back()->get_type();765 766 return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2, ast::SymbolTable{} );767 }768 769 758 FunctionDecl * isAssignment( Declaration * decl ) { 770 759 return isCopyFunction( decl, "?=?" ); -
src/InitTweak/InitTweak.h
r8d70648 rd88f8b3b 30 30 FunctionDecl * isCopyConstructor( Declaration * decl ); 31 31 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ); 32 bool isCopyFunction( const ast::FunctionDecl * decl );33 32 34 33 /// returns the base type of the first parameter to a constructor/destructor/assignment function -
src/Makefile.in
r8d70648 rd88f8b3b 170 170 AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \ 171 171 AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \ 172 AST/Stmt.$(OBJEXT) AST/SymbolTable.$(OBJEXT) \ 173 AST/Type.$(OBJEXT) AST/TypeEnvironment.$(OBJEXT) \ 172 AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \ 174 173 AST/TypeSubstitution.$(OBJEXT) 175 174 am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \ … … 587 586 AST/Print.cpp \ 588 587 AST/Stmt.cpp \ 589 AST/SymbolTable.cpp \590 588 AST/Type.cpp \ 591 AST/TypeEnvironment.cpp \592 589 AST/TypeSubstitution.cpp 593 590 … … 757 754 AST/Print.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp) 758 755 AST/Stmt.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp) 759 AST/SymbolTable.$(OBJEXT): AST/$(am__dirstamp) \760 AST/$(DEPDIR)/$(am__dirstamp)761 756 AST/Type.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp) 762 AST/TypeEnvironment.$(OBJEXT): AST/$(am__dirstamp) \763 AST/$(DEPDIR)/$(am__dirstamp)764 757 AST/TypeSubstitution.$(OBJEXT): AST/$(am__dirstamp) \ 765 758 AST/$(DEPDIR)/$(am__dirstamp) … … 1197 1190 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Print.Po@am__quote@ 1198 1191 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Stmt.Po@am__quote@ 1199 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/SymbolTable.Po@am__quote@1200 1192 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Type.Po@am__quote@ 1201 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/TypeEnvironment.Po@am__quote@1202 1193 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/TypeSubstitution.Po@am__quote@ 1203 1194 @AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/CodeGenerator.Po@am__quote@ -
src/ResolvExpr/AlternativeFinder.cc
r8d70648 rd88f8b3b 28 28 #include "Alternative.h" // for AltList, Alternative 29 29 #include "AlternativeFinder.h" 30 #include "AST/Expr.hpp"31 #include "AST/Type.hpp"32 30 #include "Common/SemanticError.h" // for SemanticError 33 31 #include "Common/utility.h" // for deleteAll, printAll, CodeLocation … … 224 222 cost.incReference(); 225 223 } 226 }227 228 const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost ) {229 if ( expr->result.as< ast::ReferenceType >() ) {230 // cast away reference from expr231 cost.incReference();232 return new ast::CastExpr{ expr->location, expr, expr->result->stripReferences() };233 }234 235 return expr;236 224 } 237 225 -
src/ResolvExpr/ResolveAssertions.cc
r8d70648 rd88f8b3b 30 30 #include "Common/Indenter.h" // for Indenter 31 31 #include "Common/utility.h" // for sort_mins 32 #include "GenPoly/GenPoly.h" // for getFunctionType33 32 #include "ResolvExpr/RenameVars.h" // for renameTyVars 34 33 #include "SymTab/Indexer.h" // for Indexer … … 155 154 Cost k = Cost::zero; 156 155 for ( const auto& assn : x.assns ) { 157 // compute conversion cost from satisfying decl to assertion158 156 k += computeConversionCost( 159 157 assn.match.adjType, assn.decl->get_type(), indexer, x.env ); 160 158 161 159 // mark vars+specialization cost on function-type assertions 162 FunctionType* func = GenPoly::getFunctionType( assn.match.cdata.id->get_type() ); 160 Type* assnType = assn.match.cdata.id->get_type(); 161 FunctionType* func; 162 if ( PointerType* ptr = dynamic_cast< PointerType* >( assnType ) ) { 163 func = dynamic_cast< FunctionType* >( ptr->base ); 164 } else { 165 func = dynamic_cast< FunctionType* >( assnType ); 166 } 163 167 if ( ! func ) continue; 164 168 -
src/ResolvExpr/Resolver.cc
r8d70648 rd88f8b3b 7 7 // Resolver.cc -- 8 8 // 9 // Author : Aaron B. Moss9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Wed May 29 11:00:00201913 // Update Count : 24 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 19 18:09:56 2019 13 // Update Count : 240 14 14 // 15 15 … … 21 21 #include "Alternative.h" // for Alternative, AltList 22 22 #include "AlternativeFinder.h" // for AlternativeFinder, resolveIn... 23 #include "CurrentObject.h" // for CurrentObject24 #include "RenameVars.h" // for RenameVars, global_renamer25 #include "Resolver.h"26 #include "ResolvMode.h" // for ResolvMode27 #include "typeops.h" // for extractResultType28 #include "Unify.h" // for unify29 #include "AST/Pass.hpp"30 #include "AST/SymbolTable.hpp"31 23 #include "Common/PassVisitor.h" // for PassVisitor 32 24 #include "Common/SemanticError.h" // for SemanticError 33 25 #include "Common/utility.h" // for ValueGuard, group_iterate 26 #include "CurrentObject.h" // for CurrentObject 34 27 #include "InitTweak/GenInit.h" 35 28 #include "InitTweak/InitTweak.h" // for isIntrinsicSingleArgCallStmt 29 #include "RenameVars.h" // for RenameVars, global_renamer 36 30 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 31 #include "Resolver.h" 32 #include "ResolvMode.h" // for ResolvMode 37 33 #include "SymTab/Autogen.h" // for SizeType 38 34 #include "SymTab/Indexer.h" // for Indexer … … 45 41 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 46 42 #include "Tuples/Tuples.h" 43 #include "typeops.h" // for extractResultType 44 #include "Unify.h" // for unify 47 45 #include "Validate/FindSpecialDecls.h" // for SizeType 48 46 … … 50 48 51 49 namespace ResolvExpr { 52 struct Resolver _old final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver_old>, public WithShortCircuiting, public WithStmtsToAdd {53 Resolver _old() {}54 Resolver _old( const SymTab::Indexer & other ) {50 struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting, public WithStmtsToAdd { 51 Resolver() {} 52 Resolver( const SymTab::Indexer & other ) { 55 53 indexer = other; 56 54 } … … 103 101 104 102 void resolve( std::list< Declaration * > translationUnit ) { 105 PassVisitor<Resolver _old> resolver;103 PassVisitor<Resolver> resolver; 106 104 acceptAll( translationUnit, resolver ); 107 105 } 108 106 109 107 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) { 110 PassVisitor<Resolver _old> resolver( indexer );108 PassVisitor<Resolver> resolver( indexer ); 111 109 maybeAccept( decl, resolver ); 112 110 } … … 404 402 } 405 403 406 void Resolver _old::previsit( ObjectDecl * objectDecl ) {407 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 408 // class-variable initContext is changed multiple time because the LHS is analysed twice. 409 // The second analysis changes initContext because of a function type can contain object 410 // declarations in the return and parameter types. So each value of initContext is 404 void Resolver::previsit( ObjectDecl * objectDecl ) { 405 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 406 // class-variable initContext is changed multiple time because the LHS is analysed twice. 407 // The second analysis changes initContext because of a function type can contain object 408 // declarations in the return and parameter types. So each value of initContext is 411 409 // retained, so the type on the first analysis is preserved and used for selecting the RHS. 412 410 GuardValue( currentObject ); … … 420 418 421 419 template< typename PtrType > 422 void Resolver _old::handlePtrType( PtrType * type ) {420 void Resolver::handlePtrType( PtrType * type ) { 423 421 if ( type->get_dimension() ) { 424 422 findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer ); … … 426 424 } 427 425 428 void Resolver _old::previsit( ArrayType * at ) {426 void Resolver::previsit( ArrayType * at ) { 429 427 handlePtrType( at ); 430 428 } 431 429 432 void Resolver _old::previsit( PointerType * pt ) {430 void Resolver::previsit( PointerType * pt ) { 433 431 handlePtrType( pt ); 434 432 } 435 433 436 void Resolver _old::previsit( FunctionDecl * functionDecl ) {434 void Resolver::previsit( FunctionDecl * functionDecl ) { 437 435 #if 0 438 436 std::cerr << "resolver visiting functiondecl "; … … 444 442 } 445 443 446 void Resolver _old::postvisit( FunctionDecl * functionDecl ) {447 // default value expressions have an environment which shouldn't be there and trips up 444 void Resolver::postvisit( FunctionDecl * functionDecl ) { 445 // default value expressions have an environment which shouldn't be there and trips up 448 446 // later passes. 449 447 // xxx - it might be necessary to somehow keep the information from this environment, but I … … 459 457 } 460 458 461 void Resolver _old::previsit( EnumDecl * ) {459 void Resolver::previsit( EnumDecl * ) { 462 460 // in case we decide to allow nested enums 463 461 GuardValue( inEnumDecl ); … … 465 463 } 466 464 467 void Resolver _old::previsit( StaticAssertDecl * assertDecl ) {465 void Resolver::previsit( StaticAssertDecl * assertDecl ) { 468 466 findIntegralExpression( assertDecl->condition, indexer ); 469 467 } 470 468 471 void Resolver _old::previsit( ExprStmt * exprStmt ) {469 void Resolver::previsit( ExprStmt * exprStmt ) { 472 470 visit_children = false; 473 471 assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" ); … … 475 473 } 476 474 477 void Resolver _old::previsit( AsmExpr * asmExpr ) {475 void Resolver::previsit( AsmExpr * asmExpr ) { 478 476 visit_children = false; 479 477 findVoidExpression( asmExpr->operand, indexer ); … … 483 481 } 484 482 485 void Resolver _old::previsit( AsmStmt * asmStmt ) {483 void Resolver::previsit( AsmStmt * asmStmt ) { 486 484 visit_children = false; 487 485 acceptAll( asmStmt->get_input(), *visitor ); … … 489 487 } 490 488 491 void Resolver _old::previsit( IfStmt * ifStmt ) {489 void Resolver::previsit( IfStmt * ifStmt ) { 492 490 findIntegralExpression( ifStmt->condition, indexer ); 493 491 } 494 492 495 void Resolver _old::previsit( WhileStmt * whileStmt ) {493 void Resolver::previsit( WhileStmt * whileStmt ) { 496 494 findIntegralExpression( whileStmt->condition, indexer ); 497 495 } 498 496 499 void Resolver _old::previsit( ForStmt * forStmt ) {497 void Resolver::previsit( ForStmt * forStmt ) { 500 498 if ( forStmt->condition ) { 501 499 findIntegralExpression( forStmt->condition, indexer ); … … 507 505 } 508 506 509 void Resolver _old::previsit( SwitchStmt * switchStmt ) {507 void Resolver::previsit( SwitchStmt * switchStmt ) { 510 508 GuardValue( currentObject ); 511 509 findIntegralExpression( switchStmt->condition, indexer ); … … 514 512 } 515 513 516 void Resolver _old::previsit( CaseStmt * caseStmt ) {514 void Resolver::previsit( CaseStmt * caseStmt ) { 517 515 if ( caseStmt->condition ) { 518 516 std::list< InitAlternative > initAlts = currentObject.getOptions(); … … 533 531 } 534 532 535 void Resolver _old::previsit( BranchStmt * branchStmt ) {533 void Resolver::previsit( BranchStmt * branchStmt ) { 536 534 visit_children = false; 537 535 // must resolve the argument for a computed goto … … 544 542 } 545 543 546 void Resolver _old::previsit( ReturnStmt * returnStmt ) {544 void Resolver::previsit( ReturnStmt * returnStmt ) { 547 545 visit_children = false; 548 546 if ( returnStmt->expr ) { … … 551 549 } 552 550 553 void Resolver _old::previsit( ThrowStmt * throwStmt ) {551 void Resolver::previsit( ThrowStmt * throwStmt ) { 554 552 visit_children = false; 555 553 // TODO: Replace *exception type with &exception type. … … 563 561 } 564 562 565 void Resolver _old::previsit( CatchStmt * catchStmt ) {563 void Resolver::previsit( CatchStmt * catchStmt ) { 566 564 if ( catchStmt->cond ) { 567 565 findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer ); … … 578 576 } 579 577 580 void Resolver _old::previsit( WaitForStmt * stmt ) {578 void Resolver::previsit( WaitForStmt * stmt ) { 581 579 visit_children = false; 582 580 … … 784 782 } 785 783 786 void Resolver _old::previsit( SingleInit * singleInit ) {784 void Resolver::previsit( SingleInit * singleInit ) { 787 785 visit_children = false; 788 786 // resolve initialization using the possibilities as determined by the currentObject cursor … … 836 834 } 837 835 838 void Resolver _old::previsit( ListInit * listInit ) {836 void Resolver::previsit( ListInit * listInit ) { 839 837 visit_children = false; 840 838 // move cursor into brace-enclosed initializer-list … … 871 869 872 870 // ConstructorInit - fall back on C-style initializer 873 void Resolver _old::fallbackInit( ConstructorInit * ctorInit ) {871 void Resolver::fallbackInit( ConstructorInit * ctorInit ) { 874 872 // could not find valid constructor, or found an intrinsic constructor 875 873 // fall back on C-style initializer … … 884 882 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) { 885 883 assert( ctorInit ); 886 PassVisitor<Resolver _old> resolver( indexer );884 PassVisitor<Resolver> resolver( indexer ); 887 885 ctorInit->accept( resolver ); 888 886 } … … 890 888 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) { 891 889 assert( stmtExpr ); 892 PassVisitor<Resolver _old> resolver( indexer );890 PassVisitor<Resolver> resolver( indexer ); 893 891 stmtExpr->accept( resolver ); 894 892 stmtExpr->computeResult(); … … 896 894 } 897 895 898 void Resolver _old::previsit( ConstructorInit * ctorInit ) {896 void Resolver::previsit( ConstructorInit * ctorInit ) { 899 897 visit_children = false; 900 898 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit … … 930 928 // } 931 929 } 932 933 ///////////////////////////////////////////////////////////////////////////934 //935 // *** NEW RESOLVER ***936 //937 ///////////////////////////////////////////////////////////////////////////938 939 class Resolver_new final940 : public ast::WithIndexer, public ast::WithGuards, public ast::WithVisitorRef<Resolver_new>,941 public ast::WithShortCircuiting, public ast::WithStmtsToAdd<> {942 943 public:944 Resolver_new() = default;945 Resolver_new( const ast::SymbolTable & syms ) { /*symtab = syms;*/ }946 947 void previsit( ast::FunctionDecl * functionDecl );948 ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl );949 void previsit( ast::ObjectDecl * objectDecl );950 void previsit( ast::EnumDecl * enumDecl );951 void previsit( ast::StaticAssertDecl * assertDecl );952 953 void previsit( ast::ArrayType * at );954 void previsit( ast::PointerType * pt );955 956 void previsit( ast::ExprStmt * exprStmt );957 void previsit( ast::AsmExpr * asmExpr );958 void previsit( ast::AsmStmt * asmStmt );959 void previsit( ast::IfStmt * ifStmt );960 void previsit( ast::WhileStmt * whileStmt );961 void previsit( ast::ForStmt * forStmt );962 void previsit( ast::SwitchStmt * switchStmt );963 void previsit( ast::CaseStmt * caseStmt );964 void previsit( ast::BranchStmt * branchStmt );965 void previsit( ast::ReturnStmt * returnStmt );966 void previsit( ast::ThrowStmt * throwStmt );967 void previsit( ast::CatchStmt * catchStmt );968 void previsit( ast::WaitForStmt * stmt );969 970 void previsit( ast::SingleInit * singleInit );971 void previsit( ast::ListInit * listInit );972 void previsit( ast::ConstructorInit * ctorInit );973 };974 975 void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit ) {976 ast::Pass<Resolver_new> resolver;977 accept_all( translationUnit, resolver );978 }979 980 void previsit( ast::FunctionDecl * functionDecl ) {981 #warning unimplemented; Resolver port in progress982 (void)functionDecl;983 assert(false);984 }985 986 ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl ) {987 #warning unimplemented; Resolver port in progress988 (void)functionDecl;989 assert(false);990 return nullptr;991 }992 993 void previsit( ast::ObjectDecl * objectDecl ) {994 #warning unimplemented; Resolver port in progress995 (void)objectDecl;996 assert(false);997 }998 999 void previsit( ast::EnumDecl * enumDecl ) {1000 #warning unimplemented; Resolver port in progress1001 (void)enumDecl;1002 assert(false);1003 }1004 1005 void previsit( ast::StaticAssertDecl * assertDecl ) {1006 #warning unimplemented; Resolver port in progress1007 (void)assertDecl;1008 assert(false);1009 }1010 1011 void previsit( ast::ArrayType * at ) {1012 #warning unimplemented; Resolver port in progress1013 (void)at;1014 assert(false);1015 }1016 1017 void previsit( ast::PointerType * pt ) {1018 #warning unimplemented; Resolver port in progress1019 (void)pt;1020 assert(false);1021 }1022 1023 void previsit( ast::ExprStmt * exprStmt ) {1024 #warning unimplemented; Resolver port in progress1025 (void)exprStmt;1026 assert(false);1027 }1028 1029 void previsit( ast::AsmExpr * asmExpr ) {1030 #warning unimplemented; Resolver port in progress1031 (void)asmExpr;1032 assert(false);1033 }1034 1035 void previsit( ast::AsmStmt * asmStmt ) {1036 #warning unimplemented; Resolver port in progress1037 (void)asmStmt;1038 assert(false);1039 }1040 1041 void previsit( ast::IfStmt * ifStmt ) {1042 #warning unimplemented; Resolver port in progress1043 (void)ifStmt;1044 assert(false);1045 }1046 1047 void previsit( ast::WhileStmt * whileStmt ) {1048 #warning unimplemented; Resolver port in progress1049 (void)whileStmt;1050 assert(false);1051 }1052 1053 void previsit( ast::ForStmt * forStmt ) {1054 #warning unimplemented; Resolver port in progress1055 (void)forStmt;1056 assert(false);1057 }1058 1059 void previsit( ast::SwitchStmt * switchStmt ) {1060 #warning unimplemented; Resolver port in progress1061 (void)switchStmt;1062 assert(false);1063 }1064 1065 void previsit( ast::CaseStmt * caseStmt ) {1066 #warning unimplemented; Resolver port in progress1067 (void)caseStmt;1068 assert(false);1069 }1070 1071 void previsit( ast::BranchStmt * branchStmt ) {1072 #warning unimplemented; Resolver port in progress1073 (void)branchStmt;1074 assert(false);1075 }1076 1077 void previsit( ast::ReturnStmt * returnStmt ) {1078 #warning unimplemented; Resolver port in progress1079 (void)returnStmt;1080 assert(false);1081 }1082 1083 void previsit( ast::ThrowStmt * throwStmt ) {1084 #warning unimplemented; Resolver port in progress1085 (void)throwStmt;1086 assert(false);1087 }1088 1089 void previsit( ast::CatchStmt * catchStmt ) {1090 #warning unimplemented; Resolver port in progress1091 (void)catchStmt;1092 assert(false);1093 }1094 1095 void previsit( ast::WaitForStmt * stmt ) {1096 #warning unimplemented; Resolver port in progress1097 (void)stmt;1098 assert(false);1099 }1100 1101 void previsit( ast::SingleInit * singleInit ) {1102 #warning unimplemented; Resolver port in progress1103 (void)singleInit;1104 assert(false);1105 }1106 1107 void previsit( ast::ListInit * listInit ) {1108 #warning unimplemented; Resolver port in progress1109 (void)listInit;1110 assert(false);1111 }1112 1113 void previsit( ast::ConstructorInit * ctorInit ) {1114 #warning unimplemented; Resolver port in progress1115 (void)ctorInit;1116 assert(false);1117 }1118 1119 930 } // namespace ResolvExpr 1120 931 -
src/ResolvExpr/Resolver.h
r8d70648 rd88f8b3b 16 16 #pragma once 17 17 18 #include <list> // for list 19 #include <AST/Node.hpp> // for ptr 18 #include <list> // for list 20 19 21 20 class ConstructorInit; … … 24 23 class StmtExpr; 25 24 namespace SymTab { 26 class Indexer; 27 } // namespace SymTab 28 29 namespace ast { 30 class Decl; 31 } // namespace ast 25 class Indexer; 26 } // namespace SymTab 32 27 33 28 namespace ResolvExpr { … … 45 40 /// Resolves with-stmts and with-clauses on functions 46 41 void resolveWithExprs( std::list< Declaration * > & translationUnit ); 47 48 /// Checks types and binds syntactic constructs to typed representations49 void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit );50 42 } // namespace ResolvExpr 51 43 -
src/ResolvExpr/Unify.cc
r8d70648 rd88f8b3b 14 14 // 15 15 16 #include <cassert> 17 #include <iterator> 18 #include <map> 19 #include <memory> 20 #include <set> 21 #include <string> 22 #include <utility> 16 #include <cassert> // for assertf, assert 17 #include <iterator> // for back_insert_iterator, back_inserter 18 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_i... 19 #include <memory> // for unique_ptr 20 #include <set> // for set 21 #include <string> // for string, operator==, operator!=, bas... 22 #include <utility> // for pair, move 23 23 #include <vector> 24 24 25 25 #include "AST/Node.hpp" 26 26 #include "AST/Type.hpp" 27 #include "AST/TypeEnvironment.hpp" 28 #include "Common/PassVisitor.h" // for PassVisitor 29 #include "FindOpenVars.h" // for findOpenVars 30 #include "Parser/LinkageSpec.h" // for C 31 #include "SynTree/Constant.h" // for Constant 32 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data, Declarati... 33 #include "SynTree/Expression.h" // for TypeExpr, Expression, ConstantExpr 34 #include "SynTree/Mutator.h" // for Mutator 35 #include "SynTree/Type.h" // for Type, TypeInstType, FunctionType 36 #include "SynTree/Visitor.h" // for Visitor 37 #include "Tuples/Tuples.h" // for isTtype 38 #include "TypeEnvironment.h" // for EqvClass, AssertionSet, OpenVarSet 27 #include "Common/PassVisitor.h" // for PassVisitor 28 #include "FindOpenVars.h" // for findOpenVars 29 #include "Parser/LinkageSpec.h" // for C 30 #include "SynTree/Constant.h" // for Constant 31 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data, Declarati... 32 #include "SynTree/Expression.h" // for TypeExpr, Expression, ConstantExpr 33 #include "SynTree/Mutator.h" // for Mutator 34 #include "SynTree/Type.h" // for Type, TypeInstType, FunctionType 35 #include "SynTree/Visitor.h" // for Visitor 36 #include "Tuples/Tuples.h" // for isTtype 37 #include "TypeEnvironment.h" // for EqvClass, AssertionSet, OpenVarSet 39 38 #include "Unify.h" 40 #include "typeops.h" 39 #include "typeops.h" // for flatten, occurs, commonType 41 40 42 41 namespace SymTab { … … 107 106 delete newSecond; 108 107 return result; 109 }110 111 bool typesCompatible(112 const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,113 const ast::TypeEnvironment & env ) {114 #warning unimplemented115 assert((first, second, symtab, env, false));116 return false;117 108 } 118 109 … … 139 130 delete newSecond; 140 131 return result; 141 }142 143 bool typesCompatibleIgnoreQualifiers(144 const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,145 const ast::TypeEnvironment & env ) {146 #warning unimplemented147 assert((first, second, symtab, env, false));148 return false;149 132 } 150 133 … … 280 263 } 281 264 282 bool unifyInexact(283 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,284 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & openVars,285 WidenMode widenMode, const ast::SymbolTable & symtab, const ast::Type *& common ) {286 #warning unimplemented287 assert((type1, type2, env, need, have, openVars, widenMode, symtab, common, false));288 return false;289 }290 291 265 Unify::Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) 292 266 : result( false ), type2( type2 ), env( env ), needAssertions( needAssertions ), haveAssertions( haveAssertions ), openVars( openVars ), widenMode( widenMode ), indexer( indexer ) { -
src/ResolvExpr/Unify.h
r8d70648 rd88f8b3b 18 18 #include <list> // for list 19 19 20 #include "AST/TypeEnvironment.hpp" // for TypeEnvironment, AssertionSet, OpenVarSet21 20 #include "Common/utility.h" // for deleteAll 22 21 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data 23 22 #include "TypeEnvironment.h" // for AssertionSet, OpenVarSet 24 #include "WidenMode.h" 23 #include "WidenMode.h" // for WidenMode 25 24 26 25 class Type; 27 26 class TypeInstType; 28 27 namespace SymTab { 29 class Indexer; 30 } 31 32 namespace ast { 33 class SymbolTable; 34 class Type; 35 } 28 class Indexer; 29 } // namespace SymTab 36 30 37 31 namespace ResolvExpr { … … 68 62 } 69 63 70 bool unifyInexact(71 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,72 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & openVars,73 WidenMode widenMode, const ast::SymbolTable & symtab, const ast::Type *& common );74 75 64 } // namespace ResolvExpr 76 65 -
src/ResolvExpr/typeops.h
r8d70648 rd88f8b3b 18 18 #include <vector> 19 19 20 #include "AST/Fwd.hpp"21 20 #include "AST/Node.hpp" 22 #include "AST/SymbolTable.hpp"23 21 #include "AST/Type.hpp" 24 #include "AST/TypeEnvironment.hpp"25 22 #include "SynTree/SynTree.h" 26 23 #include "SynTree/Type.h" … … 102 99 } 103 100 104 bool typesCompatible(105 const ast::Type *, const ast::Type *, const ast::SymbolTable &,106 const ast::TypeEnvironment & env = {} );107 108 bool typesCompatibleIgnoreQualifiers(109 const ast::Type *, const ast::Type *, const ast::SymbolTable &,110 const ast::TypeEnvironment & env = {} );111 112 101 /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value. 113 102 Type * extractResultType( FunctionType * functionType ); … … 126 115 // in Occurs.cc 127 116 bool occurs( Type *type, std::string varName, const TypeEnvironment &env ); 128 // new AST version in TypeEnvironment.cpp (only place it was used in old AST)129 117 130 118 template<typename Iter> … … 139 127 // in AlternativeFinder.cc 140 128 void referenceToRvalueConversion( Expression *& expr, Cost & cost ); 141 const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );142 129 143 130 // flatten tuple type into list of types -
src/SymTab/Mangler.cc
r8d70648 rd88f8b3b 390 390 } // namespace SymTab 391 391 392 namespace Mangle {393 std::string mangle( const ast::Node * decl, Mangle::Mode mode ) {394 #warning unimplemented395 assert( decl && mode.val && false );396 return "";397 }398 } // namespace Mangle399 400 392 // Local Variables: // 401 393 // tab-width: 4 // -
src/SymTab/Mangler.h
r8d70648 rd88f8b3b 21 21 #include <utility> // for pair 22 22 23 #include "AST/Bitfield.hpp"24 #include "AST/Fwd.hpp"25 23 #include "SynTree/SynTree.h" // for Types 26 24 #include "SynTree/Visitor.h" // for Visitor, maybeAccept … … 77 75 } // SymTab 78 76 79 namespace Mangle {80 /// Bitflags for mangle modes81 enum {82 NoOverrideable = 1 << 0,83 Type = 1 << 1,84 NoGenericParams = 1 << 285 };86 87 /// Bitflag type for mangler modes88 struct mangle_flags {89 union {90 unsigned int val;91 struct {92 bool no_overrideable : 1;93 bool type : 1;94 bool no_generic_params : 1;95 };96 };97 98 constexpr mangle_flags( unsigned int val ) : val(val) {}99 };100 101 using Mode = bitfield<mangle_flags>;102 103 /// Mangle declaration name104 std::string mangle( const ast::Node * decl, Mode mode = {} );105 106 namespace Encoding {107 using namespace SymTab::Mangler::Encoding;108 };109 }110 111 77 extern "C" { 112 78 char * cforall_demangle(const char *, int);
Note:
See TracChangeset
for help on using the changeset viewer.