Changes in / [1fcc2f3:d056d0d]
- Files:
-
- 1 added
- 6 deleted
- 47 edited
-
Jenkinsfile (added)
-
Jenkinsfile_disabled (deleted)
-
src/AST/Attribute.hpp (modified) (1 diff)
-
src/AST/CVQualifiers.hpp (modified) (2 diffs)
-
src/AST/Convert.cpp (modified) (2 diffs)
-
src/AST/Copy.hpp (deleted)
-
src/AST/Decl.cpp (modified) (1 diff)
-
src/AST/Decl.hpp (modified) (6 diffs)
-
src/AST/Eval.hpp (deleted)
-
src/AST/Expr.cpp (modified) (16 diffs)
-
src/AST/Expr.hpp (modified) (12 diffs)
-
src/AST/ForallSubstitutionTable.cpp (deleted)
-
src/AST/ForallSubstitutionTable.hpp (deleted)
-
src/AST/ForallSubstitutor.hpp (deleted)
-
src/AST/Init.hpp (modified) (1 diff)
-
src/AST/Node.cpp (modified) (2 diffs)
-
src/AST/Node.hpp (modified) (9 diffs)
-
src/AST/Pass.hpp (modified) (6 diffs)
-
src/AST/Pass.impl.hpp (modified) (13 diffs)
-
src/AST/Pass.proto.hpp (modified) (4 diffs)
-
src/AST/Stmt.hpp (modified) (2 diffs)
-
src/AST/Type.cpp (modified) (8 diffs)
-
src/AST/Type.hpp (modified) (14 diffs)
-
src/AST/TypeEnvironment.hpp (modified) (6 diffs)
-
src/AST/TypeSubstitution.cpp (modified) (6 diffs)
-
src/AST/TypeSubstitution.hpp (modified) (4 diffs)
-
src/AST/module.mk (modified) (1 diff)
-
src/Common/ScopedMap.h (modified) (1 diff)
-
src/Makefile.in (modified) (4 diffs)
-
src/ResolvExpr/AdjustExprType.cc (modified) (1 diff)
-
src/ResolvExpr/Candidate.hpp (modified) (2 diffs)
-
src/ResolvExpr/CandidateFinder.cpp (modified) (85 diffs)
-
src/ResolvExpr/CandidateFinder.hpp (modified) (4 diffs)
-
src/ResolvExpr/CastCost.cc (modified) (7 diffs)
-
src/ResolvExpr/CommonType.cc (modified) (1 diff)
-
src/ResolvExpr/ConversionCost.cc (modified) (16 diffs)
-
src/ResolvExpr/ConversionCost.h (modified) (5 diffs)
-
src/ResolvExpr/CurrentObject.cc (modified) (15 diffs)
-
src/ResolvExpr/PolyCost.cc (modified) (1 diff)
-
src/ResolvExpr/RenameVars.cc (modified) (11 diffs)
-
src/ResolvExpr/ResolveTypeof.cc (modified) (5 diffs)
-
src/ResolvExpr/Resolver.cc (modified) (6 diffs)
-
src/ResolvExpr/SatisfyAssertions.cpp (modified) (5 diffs)
-
src/ResolvExpr/SatisfyAssertions.hpp (modified) (1 diff)
-
src/ResolvExpr/SpecCost.cc (modified) (3 diffs)
-
src/ResolvExpr/Unify.cc (modified) (9 diffs)
-
src/ResolvExpr/typeops.h (modified) (3 diffs)
-
src/SymTab/Autogen.h (modified) (5 diffs)
-
src/SynTree/Statement.h (modified) (1 diff)
-
src/Tuples/Explode.cc (modified) (1 diff)
-
src/Tuples/Explode.h (modified) (2 diffs)
-
src/Tuples/TupleAssignment.cc (modified) (6 diffs)
-
src/Tuples/TupleExpansion.cc (modified) (2 diffs)
-
src/main.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Attribute.hpp
r1fcc2f3 rd056d0d 51 51 template<typename node_t> 52 52 friend node_t * mutate(const node_t * node); 53 template<typename node_t>54 friend node_t * shallowCopy(const node_t * node);55 53 }; 56 54 -
src/AST/CVQualifiers.hpp
r1fcc2f3 rd056d0d 27 27 Restrict = 1 << 1, 28 28 Volatile = 1 << 2, 29 Mutex = 1 << 3, 30 Atomic = 1 << 4, 31 NumQualifiers = 5 29 Lvalue = 1 << 3, 30 Mutex = 1 << 4, 31 Atomic = 1 << 5, 32 NumQualifiers = 6 32 33 }; 33 34 34 35 /// Mask for equivalence-preserving qualfiers 35 enum { EquivQualifiers = ~ Restrict};36 enum { EquivQualifiers = ~(Restrict | Lvalue) }; 36 37 37 38 /// Underlying data for qualifiers … … 43 44 bool is_restrict : 1; 44 45 bool is_volatile : 1; 46 bool is_lvalue : 1; 45 47 bool is_mutex : 1; 46 48 bool is_atomic : 1; -
src/AST/Convert.cpp
r1fcc2f3 rd056d0d 608 608 609 609 tgt->result = get<Type>().accept1(src->result); 610 // Unconditionally use a clone of the result type.611 // We know this will leak some objects: much of the immediate conversion result.612 // In some cases, using the conversion result directly gives unintended object sharing.613 // A parameter (ObjectDecl, a child of a FunctionType) is shared by the weak-ref cache.614 // But tgt->result must be fully owned privately by tgt.615 // Applying these conservative copies here means616 // - weak references point at the declaration's copy, not these expr.result copies (good)617 // - we copy more objects than really needed (bad, tolerated)618 if (tgt->result) {619 tgt->result = tgt->result->clone();620 }621 610 return visitBaseExpr_skipResultType(src, tgt); 622 611 } … … 2124 2113 old->location, 2125 2114 GET_ACCEPT_1(member, DeclWithType), 2126 GET_ACCEPT_1(aggregate, Expr), 2127 ast::MemberExpr::NoOpConstructionChosen 2115 GET_ACCEPT_1(aggregate, Expr) 2128 2116 ) 2129 2117 ); -
src/AST/Decl.cpp
r1fcc2f3 rd056d0d 52 52 53 53 const Type * FunctionDecl::get_type() const { return type.get(); } 54 void FunctionDecl::set_type( const Type * t ) { 55 type = strict_dynamic_cast< const FunctionType * >( t ); 56 } 54 void FunctionDecl::set_type(Type * t) { type = strict_dynamic_cast< FunctionType* >( t ); } 57 55 58 56 // --- TypeDecl -
src/AST/Decl.hpp
r1fcc2f3 rd056d0d 32 32 33 33 // Must be included in *all* AST classes; should be #undef'd at the end of the file 34 #define MUTATE_FRIEND \ 35 template<typename node_t> friend node_t * mutate(const node_t * node); \ 36 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 34 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 37 35 38 36 namespace ast { … … 89 87 virtual const Type * get_type() const = 0; 90 88 /// Set type of this declaration. May be verified by subclass 91 virtual void set_type( const Type *) = 0;89 virtual void set_type(Type *) = 0; 92 90 93 91 const DeclWithType * accept( Visitor & v ) const override = 0; … … 112 110 113 111 const Type* get_type() const override { return type; } 114 void set_type( constType * ty ) override { type = ty; }112 void set_type( Type * ty ) override { type = ty; } 115 113 116 114 const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); } … … 134 132 135 133 const Type * get_type() const override; 136 void set_type( const Type * t) override;134 void set_type(Type * t) override; 137 135 138 136 bool has_body() const { return stmts; } … … 151 149 std::vector<ptr<DeclWithType>> assertions; 152 150 153 NamedTypeDecl( 154 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 155 const Type * b, Linkage::Spec spec = Linkage::Cforall ) 151 NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 152 Type* b, Linkage::Spec spec = Linkage::Cforall ) 156 153 : Decl( loc, name, storage, spec ), base( b ), params(), assertions() {} 157 154 … … 188 185 }; 189 186 190 TypeDecl( 191 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 192 const Type * b, TypeVar::Kind k, bool s, const Type * i = nullptr ) 187 TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b, 188 TypeVar::Kind k, bool s, Type* i = nullptr ) 193 189 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ), 194 190 init( i ) {} -
src/AST/Expr.cpp
r1fcc2f3 rd056d0d 10 10 // Created On : Wed May 15 17:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Created On : Fri Oct 4 15:34:00 201913 // Update Count : 412 // Created On : Thr Jun 13 13:38:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 20 20 #include <vector> 21 21 22 #include "Copy.hpp" // for shallowCopy23 #include "Eval.hpp" // for call24 22 #include "GenericSubstitution.hpp" 25 #include "LinkageSpec.hpp"26 23 #include "Stmt.hpp" 27 24 #include "Type.hpp" … … 30 27 #include "Common/SemanticError.h" 31 28 #include "GenPoly/Lvalue.h" // for referencesPermissable 32 #include "InitTweak/InitTweak.h" // for get Function, getPointerBase29 #include "InitTweak/InitTweak.h" // for getPointerBase 33 30 #include "ResolvExpr/typeops.h" // for extractResultType 34 31 #include "Tuples/Tuples.h" // for makeTupleType 35 32 36 33 namespace ast { 37 38 namespace {39 std::set<std::string> const lvalueFunctionNames = {"*?", "?[?]"};40 }41 42 // --- Expr43 bool Expr::get_lvalue() const {44 return false;45 }46 34 47 35 // --- ApplicationExpr … … 58 46 } 59 47 60 bool ApplicationExpr::get_lvalue() const {61 if ( const DeclWithType * func = InitTweak::getFunction( this ) ) {62 return func->linkage == Linkage::Intrinsic && lvalueFunctionNames.count( func->name );63 }64 return false;65 }66 67 48 // --- UntypedExpr 68 49 … … 70 51 assert( arg ); 71 52 72 UntypedExpr * ret = call( loc, "*?", arg ); 53 UntypedExpr * ret = new UntypedExpr{ 54 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 55 }; 73 56 if ( const Type * ty = arg->result ) { 74 57 const Type * base = InitTweak::getPointerBase( ty ); … … 82 65 // base type 83 66 ret->result = base; 67 add_qualifiers( ret->result, CV::Lvalue ); 84 68 } 85 69 } 86 70 return ret; 87 }88 89 bool UntypedExpr::get_lvalue() const {90 std::string fname = InitTweak::getFunctionName( this );91 return lvalueFunctionNames.count( fname );92 71 } 93 72 … … 95 74 assert( lhs && rhs ); 96 75 97 UntypedExpr * ret = call( loc, "?=?", lhs, rhs ); 76 UntypedExpr * ret = new UntypedExpr{ 77 loc, new NameExpr{loc, "?=?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ lhs }, ptr<Expr>{ rhs } } 78 }; 98 79 if ( lhs->result && rhs->result ) { 99 80 // if both expressions are typed, assumes that this assignment is a C bitwise assignment, … … 127 108 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) { 128 109 if ( arg->result ) { 129 if ( arg-> get_lvalue() ) {110 if ( arg->result->is_lvalue() ) { 130 111 // lvalue, retains all levels of reference, and gains a pointer inside the references 131 112 Type * res = addrType( arg->result ); 113 res->set_lvalue( false ); // result of & is never an lvalue 132 114 result = res; 133 115 } else { … … 136 118 dynamic_cast< const ReferenceType * >( arg->result.get() ) ) { 137 119 Type * res = addrType( refType->base ); 120 res->set_lvalue( false ); // result of & is never an lvalue 138 121 result = res; 139 122 } else { … … 155 138 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) 156 139 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {} 157 158 bool CastExpr::get_lvalue() const {159 // This is actually wrong by C, but it works with our current set-up.160 return arg->get_lvalue();161 }162 140 163 141 // --- KeywordCastExpr … … 174 152 } 175 153 176 // --- UntypedMemberExpr177 178 bool UntypedMemberExpr::get_lvalue() const {179 return aggregate->get_lvalue();180 }181 182 154 // --- MemberExpr 183 155 … … 188 160 assert( aggregate->result ); 189 161 190 // Deep copy on result type avoids mutation on transitively multiply referenced object. 191 // 192 // Example, adapted from parts of builtins and bootloader: 193 // 194 // forall(dtype T) 195 // struct __Destructor { 196 // T * object; 197 // void (*dtor)(T *); 198 // }; 199 // 200 // forall(dtype S) 201 // void foo(__Destructor(S) &d) { 202 // if (d.dtor) { // here 203 // } 204 // } 205 // 206 // Let e be the "d.dtor" guard espression, which is MemberExpr after resolve. Let d be the 207 // declaration of member __Destructor.dtor (an ObjectDecl), as accessed via the top-level 208 // declaration of __Destructor. Consider the types e.result and d.type. In the old AST, one 209 // is a clone of the other. Ordinary new-AST use would set them up as a multiply-referenced 210 // object. 211 // 212 // e.result: PointerType 213 // .base: FunctionType 214 // .params.front(): ObjectDecl, the anonymous parameter of type T* 215 // .type: PointerType 216 // .base: TypeInstType 217 // let x = that 218 // let y = similar, except start from d.type 219 // 220 // Consider two code lines down, genericSubstitution(...).apply(result). 221 // 222 // Applying this chosen-candidate's type substitution means modifying x, substituting 223 // S for T. This mutation should affect x and not y. 224 225 result = deepCopy(mem->get_type()); 226 162 // take ownership of member type 163 result = mem->get_type(); 227 164 // substitute aggregate generic parameters into member type 228 165 genericSubstitution( aggregate->result ).apply( result ); 229 // ensure appropriate restrictions from aggregate type 230 add_qualifiers( result, aggregate->result->qualifiers ); 231 } 232 233 MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg, 234 MemberExpr::NoOpConstruction overloadSelector ) 235 : Expr( loc ), member( mem ), aggregate( agg ) { 236 assert( member ); 237 assert( aggregate ); 238 assert( aggregate->result ); 239 (void) overloadSelector; 240 } 241 242 bool MemberExpr::get_lvalue() const { 243 // This is actually wrong by C, but it works with our current set-up. 244 return true; 166 // ensure lvalue and appropriate restrictions from aggregate type 167 add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue ); 245 168 } 246 169 … … 254 177 assert( var ); 255 178 assert( var->get_type() ); 256 result = shallowCopy( var->get_type() ); 257 } 258 259 bool VariableExpr::get_lvalue() const { 260 // It isn't always an lvalue, but it is never an rvalue. 261 return true; 179 result = var->get_type(); 180 add_qualifiers( result, CV::Lvalue ); 262 181 } 263 182 … … 345 264 const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) 346 265 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} 347 348 // --- CommaExpr349 bool CommaExpr::get_lvalue() const {350 // This is wrong by C, but the current implementation uses it.351 // (ex: Specialize, Lvalue and Box)352 return arg2->get_lvalue();353 }354 266 355 267 // --- ConstructorExpr … … 371 283 assert( t && i ); 372 284 result = t; 373 } 374 375 bool CompoundLiteralExpr::get_lvalue() const { 376 return true; 285 add_qualifiers( result, CV::Lvalue ); 377 286 } 378 287 … … 391 300 // like MemberExpr, TupleIndexExpr is always an lvalue 392 301 result = type->types[ index ]; 393 } 394 395 bool TupleIndexExpr::get_lvalue() const { 396 return tuple->get_lvalue(); 302 add_qualifiers( result, CV::Lvalue ); 397 303 } 398 304 -
src/AST/Expr.hpp
r1fcc2f3 rd056d0d 9 9 // Author : Aaron B. Moss 10 10 // Created On : Fri May 10 10:30:00 2019 11 // Last Modified By : A ndrew Beach12 // Created On : Thr Sep 26 12:51:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Created On : Fri May 10 10:30:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 30 30 31 31 // Must be included in *all* AST classes; should be #undef'd at the end of the file 32 #define MUTATE_FRIEND \ 33 template<typename node_t> friend node_t * mutate(const node_t * node); \ 34 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 35 32 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 36 33 37 34 class ConverterOldToNew; … … 187 184 188 185 Expr * set_extension( bool ex ) { extension = ex; return this; } 189 virtual bool get_lvalue() const;190 186 191 187 virtual const Expr * accept( Visitor & v ) const override = 0; … … 204 200 ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} ); 205 201 206 bool get_lvalue() const final;207 208 202 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 209 203 private: … … 220 214 UntypedExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} ) 221 215 : Expr( loc ), func( f ), args( std::move(as) ) {} 222 223 bool get_lvalue() const final;224 216 225 217 /// Creates a new dereference expression … … 298 290 CastExpr( const Expr * a ) : CastExpr( a->location, a, GeneratedCast ) {} 299 291 300 bool get_lvalue() const final;301 302 292 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 303 293 private: … … 347 337 : Expr( loc ), member( mem ), aggregate( agg ) { assert( aggregate ); } 348 338 349 bool get_lvalue() const final;350 351 339 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 352 340 private: … … 363 351 MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg ); 364 352 365 bool get_lvalue() const final;366 367 353 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 368 354 private: 369 355 MemberExpr * clone() const override { return new MemberExpr{ *this }; } 370 356 MUTATE_FRIEND 371 372 // Custructor overload meant only for AST conversion373 enum NoOpConstruction { NoOpConstructionChosen };374 MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg,375 NoOpConstruction overloadSelector );376 friend class ::ConverterOldToNew;377 friend class ::ConverterNewToOld;378 357 }; 379 358 … … 385 364 VariableExpr( const CodeLocation & loc ); 386 365 VariableExpr( const CodeLocation & loc, const DeclWithType * v ); 387 388 bool get_lvalue() const final;389 366 390 367 /// generates a function pointer for a given function … … 554 531 555 532 CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 ) 556 : Expr( loc ), arg1( a1 ), arg2( a2 ) { 557 this->result = a2->result; 558 } 559 560 bool get_lvalue() const final; 533 : Expr( loc ), arg1( a1 ), arg2( a2 ) {} 561 534 562 535 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } … … 631 604 CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ); 632 605 633 bool get_lvalue() const final;634 635 606 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 636 607 private: … … 688 659 689 660 TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ); 690 691 bool get_lvalue() const final;692 661 693 662 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Init.hpp
r1fcc2f3 rd056d0d 25 25 26 26 // Must be included in *all* AST classes; should be #undef'd at the end of the file 27 #define MUTATE_FRIEND \ 28 template<typename node_t> friend node_t * mutate(const node_t * node); \ 29 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 27 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 30 28 31 29 namespace ast { -
src/AST/Node.cpp
r1fcc2f3 rd056d0d 17 17 #include "Fwd.hpp" 18 18 19 #include <csignal> // MEMORY DEBUG -- for raise20 19 #include <iostream> 21 20 … … 30 29 #include "Print.hpp" 31 30 32 /// MEMORY DEBUG -- allows breaking on ref-count changes of dynamically chosen object. 33 /// Process to use in GDB: 34 /// break ast::Node::_trap() 35 /// run 36 /// set variable MEM_TRAP_OBJ = <target> 37 /// disable <first breakpoint> 38 /// continue 39 void * MEM_TRAP_OBJ = nullptr; 40 41 void _trap( const void * node ) { 42 if ( node == MEM_TRAP_OBJ ) std::raise(SIGTRAP); 43 } 44 45 template< typename node_t, enum ast::Node::ref_type ref_t > 46 void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) { 47 node->increment(ref_t); 48 _trap( node ); 49 } 50 51 template< typename node_t, enum ast::Node::ref_type ref_t > 52 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node, bool do_delete ) { 53 _trap( node ); 54 node->decrement(ref_t, do_delete ); 55 } 56 57 template< typename node_t, enum ast::Node::ref_type ref_t > 58 void ast::ptr_base<node_t, ref_t>::_check() const { 59 // if(node) assert(node->was_ever_strong == false || node->strong_count > 0); 60 } 31 template< typename node_t, enum ast::Node::ref_type ref_t > 32 void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) { node->increment(ref_t); } 33 34 template< typename node_t, enum ast::Node::ref_type ref_t > 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); } 61 39 62 40 template< typename node_t, enum ast::Node::ref_type ref_t > -
src/AST/Node.hpp
r1fcc2f3 rd056d0d 38 38 Node& operator= (const Node&) = delete; 39 39 Node& operator= (Node&&) = delete; 40 virtual ~Node() {}40 virtual ~Node() = default; 41 41 42 42 virtual const Node * accept( Visitor & v ) const = 0; … … 57 57 template<typename node_t> 58 58 friend node_t * mutate(const node_t * node); 59 template<typename node_t>60 friend node_t * shallowCopy(const node_t * node);61 59 62 60 mutable size_t strong_count = 0; … … 71 69 } 72 70 73 void decrement(ast::Node::ref_type ref , bool do_delete = true) const {71 void decrement(ast::Node::ref_type ref) const { 74 72 switch (ref) { 75 73 case ref_type::strong: strong_count--; break; … … 77 75 } 78 76 79 if( do_delete &&!strong_count && !weak_count) {77 if(!strong_count && !weak_count) { 80 78 delete this; 81 79 } … … 96 94 assertf( 97 95 node->weak_count == 0, 98 "Error: mutating node with weak references to it will invalid atesome references"96 "Error: mutating node with weak references to it will invalided some references" 99 97 ); 100 98 return node->clone(); … … 106 104 // skip mutate if equivalent 107 105 if ( node->*field == val ) return node; 108 106 109 107 // mutate and return 110 108 node_t * ret = mutate( node ); … … 125 123 (ret->*field)[i] = std::forward< field_t >( val ); 126 124 return ret; 127 }128 129 /// Mutate an entire indexed collection by cloning to accepted value130 template<typename node_t, typename parent_t, typename coll_t>131 const node_t * mutate_each( const node_t * node, coll_t parent_t::* field, Visitor & v ) {132 for ( unsigned i = 0; i < (node->*field).size(); ++i ) {133 node = mutate_field_index( node, field, i, (node->*field)[i]->accept( v ) );134 }135 return node;136 125 } 137 126 … … 230 219 operator const node_t * () const { _check(); return node; } 231 220 232 const node_t * release() {233 const node_t * ret = node;234 if ( node ) {235 _dec(node, false);236 node = nullptr;237 }238 return ret;239 }240 241 221 /// wrapper for convenient access to dynamic_cast 242 222 template<typename o_node_t> … … 264 244 265 245 void _inc( const node_t * other ); 266 void _dec( const node_t * other , bool do_delete = true);246 void _dec( const node_t * other ); 267 247 void _check() const; 268 248 -
src/AST/Pass.hpp
r1fcc2f3 rd056d0d 35 35 #include "AST/SymbolTable.hpp" 36 36 37 #include "AST/ForallSubstitutionTable.hpp"38 39 37 // Private prelude header, needed for some of the magic tricks this class pulls off 40 38 #include "AST/Pass.proto.hpp" … … 48 46 // 49 47 // Several additional features are available through inheritance 50 // | WithTypeSubstitution - provides polymorphic const TypeSubstitution * env for the 51 // current expression 52 // | WithStmtsToAdd - provides the ability to insert statements before or after the current 53 // statement by adding new statements into stmtsToAddBefore or 54 // stmtsToAddAfter respectively. 55 // | WithDeclsToAdd - provides the ability to insert declarations before or after the 56 // current declarations by adding new DeclStmt into declsToAddBefore or 57 // declsToAddAfter respectively. 58 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children 59 // to false in pre{visit,visit} to skip visiting children 60 // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, 61 // call GuardValue with the variable to save, the variable will 62 // automatically be restored to its previous value after the 63 // corresponding postvisit/postmutate teminates. 64 // | WithVisitorRef - provides an pointer to the templated visitor wrapper 65 // | WithSymbolTable - provides symbol table functionality 66 // | WithForallSubstitutor - maintains links between TypeInstType and TypeDecl under mutation 48 // | WithTypeSubstitution - provides polymorphic const TypeSubstitution * env for the 49 // current expression 50 // | WithStmtsToAdd - provides the ability to insert statements before or after the current 51 // statement by adding new statements into stmtsToAddBefore or 52 // stmtsToAddAfter respectively. 53 // | WithDeclsToAdd - provides the ability to insert declarations before or after the current 54 // declarations by adding new DeclStmt into declsToAddBefore or 55 // declsToAddAfter respectively. 56 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children 57 // to false in pre{visit,visit} to skip visiting children 58 // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, 59 // call GuardValue with the variable to save, the variable will 60 // automatically be restored to its previous value after the corresponding 61 // postvisit/postmutate teminates. 62 // | WithVisitorRef - provides an pointer to the templated visitor wrapper 63 // | WithSymbolTable - provides symbol table functionality 67 64 //------------------------------------------------------------------------------------------------- 68 65 template< typename pass_t > … … 204 201 container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container ); 205 202 206 /// Mutate forall-list, accounting for presence of type substitution map207 template<typename node_t>208 void mutate_forall( const node_t *& );209 210 203 public: 211 204 /// Logic to call the accept and mutate the parent if needed, delegates call to accept … … 216 209 /// Internal RAII guard for symbol table features 217 210 struct guard_symtab { 218 guard_symtab( Pass<pass_t> & pass ): pass( pass ) { __pass::symtab::enter(pass .pass, 0); }219 ~guard_symtab() { __pass::symtab::leave(pass .pass, 0); }211 guard_symtab( Pass<pass_t> & pass ): pass( pass ) { __pass::symtab::enter(pass, 0); } 212 ~guard_symtab() { __pass::symtab::leave(pass, 0); } 220 213 Pass<pass_t> & pass; 221 214 }; … … 223 216 /// Internal RAII guard for scope features 224 217 struct guard_scope { 225 guard_scope( Pass<pass_t> & pass ): pass( pass ) { __pass::scope::enter(pass .pass, 0); }226 ~guard_scope() { __pass::scope::leave(pass .pass, 0); }218 guard_scope( Pass<pass_t> & pass ): pass( pass ) { __pass::scope::enter(pass, 0); } 219 ~guard_scope() { __pass::scope::leave(pass, 0); } 227 220 Pass<pass_t> & pass; 228 };229 230 /// Internal RAII guard for forall substitutions231 struct guard_forall_subs {232 guard_forall_subs( Pass<pass_t> & pass, const ParameterizedType * type )233 : pass( pass ), type( type ) { __pass::forall::enter(pass.pass, 0, type ); }234 ~guard_forall_subs() { __pass::forall::leave(pass.pass, 0, type ); }235 Pass<pass_t> & pass;236 const ParameterizedType * type;237 221 }; 238 222 … … 329 313 SymbolTable symtab; 330 314 }; 331 332 /// Use when the templated visitor needs to keep TypeInstType instances properly linked to TypeDecl333 struct WithForallSubstitutor {334 ForallSubstitutionTable subs;335 };336 337 315 } 338 316 -
src/AST/Pass.impl.hpp
r1fcc2f3 rd056d0d 127 127 , decltype( node->accept(*this) ) 128 128 >::type 129 129 130 { 130 131 __pedantic_pass_assert( __visit_children() ); 131 __pedantic_pass_assert( node);132 __pedantic_pass_assert( expr ); 132 133 133 134 static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR"); … … 322 323 } 323 324 324 325 template< typename pass_t >326 template< typename node_t >327 void ast::Pass< pass_t >::mutate_forall( const node_t *& node ) {328 if ( auto subs = __pass::forall::subs( pass, 0 ) ) {329 // tracking TypeDecl substitution, full clone330 if ( node->forall.empty() ) return;331 332 node_t * mut = mutate( node );333 mut->forall = subs->clone( node->forall, *this );334 node = mut;335 } else {336 // not tracking TypeDecl substitution, just mutate337 maybe_accept( node, &node_t::forall );338 }339 }340 325 } 341 326 … … 444 429 guard_symtab guard { *this }; 445 430 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 446 static ast:: ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{447 CodeLocation{}, "__func__",448 new ast::ArrayType {449 new ast::BasicType { ast::BasicType::Char, ast::CV::Const },431 static ast::ObjectDecl func( 432 node->location, "__func__", 433 new ast::ArrayType( 434 new ast::BasicType( ast::BasicType::Char, ast::CV::Qualifiers( ast::CV::Const ) ), 450 435 nullptr, VariableLen, DynamicDim 451 }452 } };453 __pass::symtab::addId( pass, 0, func );436 ) 437 ); 438 __pass::symtab::addId( pass, 0, &func ); 454 439 VISIT( 455 440 maybe_accept( node, &FunctionDecl::type ); … … 625 610 VISIT({ 626 611 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 627 auto guard1 = makeFuncGuard( [this, inFunction Cpy= this->inFunction]() {628 if ( ! inFunction Cpy) __pass::symtab::enter(pass, 0);629 }, [this, inFunction Cpy= this->inFunction]() {630 if ( ! inFunction Cpy) __pass::symtab::leave(pass, 0);612 auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() { 613 if ( ! inFunction ) __pass::symtab::enter(pass, 0); 614 }, [this, inFunction = this->inFunction]() { 615 if ( ! inFunction ) __pass::symtab::leave(pass, 0); 631 616 }); 632 617 ValueGuard< bool > guard2( inFunction ); … … 953 938 // For now this isn't visited, it is unclear if this causes problem 954 939 // if all tests are known to pass, remove this code 955 VISIT(956 maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );957 )940 // VISIT( 941 // maybe_accept( node, &ImplicitCtorDtorStmt::callStmt ); 942 // ) 958 943 959 944 VISIT_END( Stmt, node ); … … 1682 1667 VISIT_START( node ); 1683 1668 1684 VISIT({ 1685 guard_forall_subs forall_guard { *this, node }; 1686 mutate_forall( node ); 1669 VISIT( 1670 maybe_accept( node, &FunctionType::forall ); 1687 1671 maybe_accept( node, &FunctionType::returns ); 1688 1672 maybe_accept( node, &FunctionType::params ); 1689 })1673 ) 1690 1674 1691 1675 VISIT_END( Type, node ); … … 1702 1686 VISIT({ 1703 1687 guard_symtab guard { *this }; 1704 guard_forall_subs forall_guard { *this, node }; 1705 mutate_forall( node ); 1688 maybe_accept( node, &StructInstType::forall ); 1706 1689 maybe_accept( node, &StructInstType::params ); 1707 1690 }) … … 1716 1699 VISIT_START( node ); 1717 1700 1718 __pass::symtab::add Union( pass, 0, node->name );1719 1720 VISIT({1701 __pass::symtab::addStruct( pass, 0, node->name ); 1702 1703 { 1721 1704 guard_symtab guard { *this }; 1722 guard_forall_subs forall_guard { *this, node }; 1723 mutate_forall( node ); 1705 maybe_accept( node, &UnionInstType::forall ); 1724 1706 maybe_accept( node, &UnionInstType::params ); 1725 } )1707 } 1726 1708 1727 1709 VISIT_END( Type, node ); … … 1734 1716 VISIT_START( node ); 1735 1717 1736 VISIT({ 1737 guard_forall_subs forall_guard { *this, node }; 1738 mutate_forall( node ); 1718 VISIT( 1719 maybe_accept( node, &EnumInstType::forall ); 1739 1720 maybe_accept( node, &EnumInstType::params ); 1740 })1721 ) 1741 1722 1742 1723 VISIT_END( Type, node ); … … 1749 1730 VISIT_START( node ); 1750 1731 1751 VISIT({ 1752 guard_forall_subs forall_guard { *this, node }; 1753 mutate_forall( node ); 1732 VISIT( 1733 maybe_accept( node, &TraitInstType::forall ); 1754 1734 maybe_accept( node, &TraitInstType::params ); 1755 })1735 ) 1756 1736 1757 1737 VISIT_END( Type, node ); … … 1765 1745 1766 1746 VISIT( 1767 { 1768 guard_forall_subs forall_guard { *this, node }; 1769 mutate_forall( node ); 1770 maybe_accept( node, &TypeInstType::params ); 1771 } 1772 // ensure that base re-bound if doing substitution 1773 __pass::forall::replace( pass, 0, node ); 1747 maybe_accept( node, &TypeInstType::forall ); 1748 maybe_accept( node, &TypeInstType::params ); 1774 1749 ) 1775 1750 … … 1920 1895 guard_symtab guard { *this }; 1921 1896 auto new_node = p.second->accept( *this ); 1922 if (new_node != p.second) mutated = true;1897 if (new_node != p.second) mutated = false; 1923 1898 new_map.insert({ p.first, new_node }); 1924 1899 } … … 1936 1911 guard_symtab guard { *this }; 1937 1912 auto new_node = p.second->accept( *this ); 1938 if (new_node != p.second) mutated = true;1913 if (new_node != p.second) mutated = false; 1939 1914 new_map.insert({ p.first, new_node }); 1940 1915 } -
src/AST/Pass.proto.hpp
r1fcc2f3 rd056d0d 263 263 template<typename pass_t> 264 264 static inline void leave( pass_t &, long ) {} 265 } // namespace scope266 267 // Certain passes desire an up to date symbol table automatically265 }; 266 267 // Finally certain pass desire an up to date symbol table automatically 268 268 // detect the presence of a member name `symtab` and call all the members appropriately 269 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.symtab , void() ) {272 static inline auto enter( pass_t & pass, int ) -> decltype( pass.symtab.enterScope(), void() ) { 273 273 pass.symtab.enterScope(); 274 274 } … … 278 278 279 279 template<typename pass_t> 280 static inline auto leave( pass_t & pass, int ) -> decltype( pass.symtab , void() ) {280 static inline auto leave( pass_t & pass, int ) -> decltype( pass.symtab.leaveScope(), void() ) { 281 281 pass.symtab.leaveScope(); 282 282 } … … 311 311 SYMTAB_FUNC1( addUnion , const UnionDecl * ); 312 312 SYMTAB_FUNC1( addTrait , const TraitDecl * ); 313 SYMTAB_FUNC2( addWith , const std::vector< ptr<Expr> > &, const Decl* );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 … … 356 356 #undef SYMTAB_FUNC1 357 357 #undef SYMTAB_FUNC2 358 } // namespace symtab 359 360 // Some passes need to mutate TypeDecl and properly update their pointing TypeInstType. 361 // Detect the presence of a member name `subs` and call all members appropriately 362 namespace forall { 363 // Some simple scoping rules 364 template<typename pass_t> 365 static inline auto enter( pass_t & pass, int, const ast::ParameterizedType * type ) 366 -> decltype( pass.subs, void() ) { 367 if ( ! type->forall.empty() ) pass.subs.beginScope(); 368 } 369 370 template<typename pass_t> 371 static inline auto enter( pass_t &, long, const ast::ParameterizedType * ) {} 372 373 template<typename pass_t> 374 static inline auto leave( pass_t & pass, int, const ast::ParameterizedType * type ) 375 -> decltype( pass.subs, void() ) { 376 if ( ! type->forall.empty() ) { pass.subs.endScope(); } 377 } 378 379 template<typename pass_t> 380 static inline auto leave( pass_t &, long, const ast::ParameterizedType * ) {} 381 382 // Get the substitution table, if present 383 template<typename pass_t> 384 static inline auto subs( pass_t & pass, int ) -> decltype( &pass.subs ) { 385 return &pass.subs; 386 } 387 388 template<typename pass_t> 389 static inline ast::ForallSubstitutionTable * subs( pass_t &, long ) { return nullptr; } 390 391 // Replaces a TypeInstType's base TypeDecl according to the table 392 template<typename pass_t> 393 static inline auto replace( pass_t & pass, int, const ast::TypeInstType *& inst ) 394 -> decltype( pass.subs, void() ) { 395 inst = ast::mutate_field( 396 inst, &ast::TypeInstType::base, pass.subs.replace( inst->base ) ); 397 } 398 399 template<typename pass_t> 400 static inline auto replace( pass_t &, long, const ast::TypeInstType *& ) {} 401 402 } // namespace forall 403 } // namespace __pass 404 } // namespace ast 358 }; 359 }; 360 }; -
src/AST/Stmt.hpp
r1fcc2f3 rd056d0d 27 27 28 28 // Must be included in *all* AST classes; should be #undef'd at the end of the file 29 #define MUTATE_FRIEND \ 30 template<typename node_t> friend node_t * mutate(const node_t * node); \ 31 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 29 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 32 30 33 31 namespace ast { … … 399 397 class ImplicitCtorDtorStmt final : public Stmt { 400 398 public: 401 ptr<Stmt> callStmt;399 readonly<Stmt> callStmt; 402 400 403 401 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt, -
src/AST/Type.cpp
r1fcc2f3 rd056d0d 21 21 22 22 #include "Decl.hpp" 23 #include "ForallSubstitutor.hpp" // for substituteForall24 23 #include "Init.hpp" 25 #include "Common/utility.h" // for copy, move26 24 #include "InitTweak/InitTweak.h" // for getPointerBase 27 25 #include "Tuples/Tuples.h" // for isTtype … … 93 91 ); 94 92 95 // --- ParameterizedType96 97 void ParameterizedType::initWithSub(98 const ParameterizedType & o, Pass< ForallSubstitutor > & sub99 ) {100 forall = sub.pass( o.forall );101 }102 103 93 // --- FunctionType 104 105 FunctionType::FunctionType( const FunctionType & o )106 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), returns(), params(),107 isVarArgs( o.isVarArgs ) {108 Pass< ForallSubstitutor > sub;109 initWithSub( o, sub ); // initialize substitution map110 returns = sub.pass( o.returns ); // apply to return and parameter types111 params = sub.pass( o.params );112 }113 94 114 95 namespace { … … 126 107 127 108 // --- ReferenceToType 128 129 void ReferenceToType::initWithSub( const ReferenceToType & o, Pass< ForallSubstitutor > & sub ) {130 ParameterizedType::initWithSub( o, sub ); // initialize substitution131 params = sub.pass( o.params ); // apply to parameters132 }133 134 ReferenceToType::ReferenceToType( const ReferenceToType & o )135 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), params(), name( o.name ),136 hoistType( o.hoistType ) {137 Pass< ForallSubstitutor > sub;138 initWithSub( o, sub );139 }140 141 109 std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const { 142 110 assertf( aggr(), "Must have aggregate to perform lookup" ); … … 151 119 // --- StructInstType 152 120 153 StructInstType::StructInstType( 154 const StructDecl * b, CV::Qualifiers q,std::vector<ptr<Attribute>>&& as )155 : ReferenceToType( b->name, q, move(as) ), base( b ) {}121 StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q, 122 std::vector<ptr<Attribute>>&& as ) 123 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {} 156 124 157 125 bool StructInstType::isComplete() const { return base ? base->body : false; } … … 159 127 // --- UnionInstType 160 128 161 UnionInstType::UnionInstType( 162 const UnionDecl * b, CV::Qualifiers q,std::vector<ptr<Attribute>>&& as )163 : ReferenceToType( b->name, q, move(as) ), base( b ) {}129 UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q, 130 std::vector<ptr<Attribute>>&& as ) 131 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {} 164 132 165 133 bool UnionInstType::isComplete() const { return base ? base->body : false; } … … 167 135 // --- EnumInstType 168 136 169 EnumInstType::EnumInstType( 170 const EnumDecl * b, CV::Qualifiers q,std::vector<ptr<Attribute>>&& as )171 : ReferenceToType( b->name, q, move(as) ), base( b ) {}137 EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q, 138 std::vector<ptr<Attribute>>&& as ) 139 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {} 172 140 173 141 bool EnumInstType::isComplete() const { return base ? base->body : false; } … … 175 143 // --- TraitInstType 176 144 177 TraitInstType::TraitInstType( 178 const TraitDecl * b, CV::Qualifiers q,std::vector<ptr<Attribute>>&& as )179 : ReferenceToType( b->name, q, move(as) ), base( b ) {}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 ) {} 180 148 181 149 // --- TypeInstType 182 183 TypeInstType::TypeInstType( const TypeInstType & o )184 : ReferenceToType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {185 Pass< ForallSubstitutor > sub;186 initWithSub( o, sub ); // initialize substitution187 base = sub.pass( o.base ); // apply to base type188 }189 150 190 151 void TypeInstType::set_base( const TypeDecl * b ) { … … 198 159 199 160 TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q ) 200 : Type( q ), types( move(ts) ), members() {161 : Type( q ), types( std::move(ts) ), members() { 201 162 // This constructor is awkward. `TupleType` needs to contain objects so that members can be 202 163 // named, but members without initializer nodes end up getting constructors, which breaks -
src/AST/Type.hpp
r1fcc2f3 rd056d0d 30 30 31 31 // Must be included in *all* AST classes; should be #undef'd at the end of the file 32 #define MUTATE_FRIEND \ 33 template<typename node_t> friend node_t * mutate(const node_t * node); \ 34 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 32 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 35 33 36 34 namespace ast { 37 38 template< typename T > class Pass;39 40 struct ForallSubstitutor;41 35 42 36 class Type : public Node { … … 51 45 bool is_volatile() const { return qualifiers.is_volatile; } 52 46 bool is_restrict() const { return qualifiers.is_restrict; } 47 bool is_lvalue() const { return qualifiers.is_lvalue; } 53 48 bool is_mutex() const { return qualifiers.is_mutex; } 54 49 bool is_atomic() const { return qualifiers.is_atomic; } … … 57 52 Type * set_volatile( bool v ) { qualifiers.is_volatile = v; return this; } 58 53 Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; } 54 Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; } 59 55 Type * set_mutex( bool v ) { qualifiers.is_mutex = v; return this; } 60 56 Type * set_atomic( bool v ) { qualifiers.is_atomic = v; return this; } … … 168 164 static const char *typeNames[]; 169 165 170 BasicType( Kind k, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 166 BasicType( Kind k, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 171 167 : Type(q, std::move(as)), kind(k) {} 172 168 … … 270 266 /// Base type for potentially forall-qualified types 271 267 class ParameterizedType : public Type { 272 protected:273 /// initializes forall with substitutor274 void initWithSub( const ParameterizedType & o, Pass< ForallSubstitutor > & sub );275 268 public: 276 269 using ForallList = std::vector<ptr<TypeDecl>>; … … 284 277 ParameterizedType( CV::Qualifiers q, std::vector<ptr<Attribute>> && as = {} ) 285 278 : Type(q, std::move(as)), forall() {} 286 287 // enforce use of ForallSubstitutor to copy parameterized type288 ParameterizedType( const ParameterizedType & ) = delete;289 290 ParameterizedType( ParameterizedType && ) = default;291 292 // no need to change destructor, and operator= deleted in Node293 279 294 280 private: … … 316 302 : ParameterizedType(q), returns(), params(), isVarArgs(va) {} 317 303 318 FunctionType( const FunctionType & o );319 320 304 /// true if either the parameters or return values contain a tttype 321 305 bool isTtype() const; … … 331 315 /// base class for types that refer to types declared elsewhere (aggregates and typedefs) 332 316 class ReferenceToType : public ParameterizedType { 333 protected:334 /// Initializes forall and parameters based on substitutor335 void initWithSub( const ReferenceToType & o, Pass< ForallSubstitutor > & sub );336 317 public: 337 318 std::vector<ptr<Expr>> params; … … 339 320 bool hoistType = false; 340 321 341 ReferenceToType( 342 const std::string& n, CV::Qualifiers q = {},std::vector<ptr<Attribute>> && as = {} )322 ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 323 std::vector<ptr<Attribute>> && as = {} ) 343 324 : ParameterizedType(q, std::move(as)), params(), name(n) {} 344 345 ReferenceToType( const ReferenceToType & o );346 325 347 326 /// Gets aggregate declaration this type refers to … … 360 339 readonly<StructDecl> base; 361 340 362 StructInstType( 363 const std::string& n, CV::Qualifiers q = {},std::vector<ptr<Attribute>> && as = {} )341 StructInstType( const std::string& n, CV::Qualifiers q = {}, 342 std::vector<ptr<Attribute>> && as = {} ) 364 343 : ReferenceToType( n, q, std::move(as) ), base() {} 365 366 StructInstType( 367 const StructDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 344 StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 345 std::vector<ptr<Attribute>> && as = {} ); 368 346 369 347 bool isComplete() const override; … … 382 360 readonly<UnionDecl> base; 383 361 384 UnionInstType( 385 const std::string& n, CV::Qualifiers q = {},std::vector<ptr<Attribute>> && as = {} )362 UnionInstType( const std::string& n, CV::Qualifiers q = {}, 363 std::vector<ptr<Attribute>> && as = {} ) 386 364 : ReferenceToType( n, q, std::move(as) ), base() {} 387 388 UnionInstType( 389 const UnionDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 365 UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 366 std::vector<ptr<Attribute>> && as = {} ); 390 367 391 368 bool isComplete() const override; … … 404 381 readonly<EnumDecl> base; 405 382 406 EnumInstType( 407 const std::string& n, CV::Qualifiers q = {},std::vector<ptr<Attribute>> && as = {} )383 EnumInstType( const std::string& n, CV::Qualifiers q = {}, 384 std::vector<ptr<Attribute>> && as = {} ) 408 385 : ReferenceToType( n, q, std::move(as) ), base() {} 409 410 EnumInstType( 411 const EnumDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 386 EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 387 std::vector<ptr<Attribute>> && as = {} ); 412 388 413 389 bool isComplete() const override; … … 426 402 readonly<TraitDecl> base; 427 403 428 TraitInstType( 429 const std::string& n, CV::Qualifiers q = {},std::vector<ptr<Attribute>> && as = {} )404 TraitInstType( const std::string& n, CV::Qualifiers q = {}, 405 std::vector<ptr<Attribute>> && as = {} ) 430 406 : ReferenceToType( n, q, std::move(as) ), base() {} 431 432 TraitInstType( 433 const TraitDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 407 TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 408 std::vector<ptr<Attribute>> && as = {} ); 434 409 435 410 // not meaningful for TraitInstType … … 450 425 TypeVar::Kind kind; 451 426 452 TypeInstType( 453 const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 427 TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 454 428 std::vector<ptr<Attribute>> && as = {} ) 455 429 : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} 456 457 TypeInstType( 458 const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 430 TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 459 431 std::vector<ptr<Attribute>> && as = {} ) 460 432 : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {} 461 462 TypeInstType( const TypeInstType & o );463 433 464 434 /// sets `base`, updating `kind` correctly -
src/AST/TypeEnvironment.hpp
r1fcc2f3 rd056d0d 38 38 /// Adding this comparison operator significantly improves assertion satisfaction run time for 39 39 /// some cases. The current satisfaction algorithm's speed partially depends on the order of 40 /// assertions. Assertions which have fewer possible matches should appear before assertions 41 /// which have more possible matches. This seems to imply that this could be further improved 42 /// by providing an indexer as an additional argument and ordering based on the number of 40 /// assertions. Assertions which have fewer possible matches should appear before assertions 41 /// which have more possible matches. This seems to imply that this could be further improved 42 /// by providing an indexer as an additional argument and ordering based on the number of 43 43 /// matches of the same kind (object, function) for the names of the declarations. 44 44 /// 45 /// I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this 45 /// I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this 46 46 /// comparator. 47 47 /// 48 /// Note: since this compares pointers for position, minor changes in the source file that 49 /// affect memory layout can alter compilation time in unpredictable ways. For example, the 50 /// placement of a line directive can reorder type pointers with respect to each other so that 51 /// assertions are seen in different orders, causing a potentially different number of 52 /// unification calls when resolving assertions. I've seen a TU go from 36 seconds to 27 53 /// seconds by reordering line directives alone, so it would be nice to fix this comparison so 54 /// that assertions compare more consistently. I've tried to modify this to compare on mangle 55 /// name instead of type as the second comparator, but this causes some assertions to never be 48 /// Note: since this compares pointers for position, minor changes in the source file that 49 /// affect memory layout can alter compilation time in unpredictable ways. For example, the 50 /// placement of a line directive can reorder type pointers with respect to each other so that 51 /// assertions are seen in different orders, causing a potentially different number of 52 /// unification calls when resolving assertions. I've seen a TU go from 36 seconds to 27 53 /// seconds by reordering line directives alone, so it would be nice to fix this comparison so 54 /// that assertions compare more consistently. I've tried to modify this to compare on mangle 55 /// name instead of type as the second comparator, but this causes some assertions to never be 56 56 /// recorded. More investigation is needed. 57 57 struct AssertCompare { … … 87 87 void print( std::ostream &, const OpenVarSet &, Indenter indent = {} ); 88 88 89 /// Represents an equivalence class of bound type variables, optionally with the concrete type 89 /// Represents an equivalence class of bound type variables, optionally with the concrete type 90 90 /// they bind to. 91 91 struct EqvClass { … … 96 96 97 97 EqvClass() : vars(), bound(), allowWidening( true ), data() {} 98 98 99 99 /// Copy-with-bound constructor 100 EqvClass( const EqvClass & o, const Type * b ) 100 EqvClass( const EqvClass & o, const Type * b ) 101 101 : vars( o.vars ), bound( b ), allowWidening( o.allowWidening ), data( o.data ) {} 102 102 … … 143 143 void writeToSubstitution( TypeSubstitution & sub ) const; 144 144 145 template< typename node_t >146 auto apply( node_t && type ) const {145 template< typename node_t, enum Node::ref_type ref_t > 146 int apply( ptr_base< node_t, ref_t > & type ) const { 147 147 TypeSubstitution sub; 148 148 writeToSubstitution( sub ); 149 return sub.apply( std::forward<node_t>(type));150 } 151 152 template< typename node_t >153 auto applyFree( node_t && type ) const {149 return sub.apply( type ); 150 } 151 152 template< typename node_t, enum Node::ref_type ref_t > 153 int applyFree( ptr_base< node_t, ref_t > & type ) const { 154 154 TypeSubstitution sub; 155 155 writeToSubstitution( sub ); 156 return sub.applyFree( std::forward<node_t>(type));156 return sub.applyFree( type ); 157 157 } 158 158 … … 173 173 void addActual( const TypeEnvironment & actualEnv, OpenVarSet & openVars ); 174 174 175 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add the class if 175 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add the class if 176 176 /// needed. Returns false on failure. 177 bool bindVar( 178 const TypeInstType * typeInst, const Type * bindTo, const TypeDecl::Data & data, 179 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars, 177 bool bindVar( 178 const TypeInstType * typeInst, const Type * bindTo, const TypeDecl::Data & data, 179 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars, 180 180 ResolvExpr::WidenMode widen, const SymbolTable & symtab ); 181 182 /// Binds the type classes represented by `var1` and `var2` together; will add one or both 181 182 /// Binds the type classes represented by `var1` and `var2` together; will add one or both 183 183 /// classes if needed. Returns false on failure. 184 bool bindVarToVar( 185 const TypeInstType * var1, const TypeInstType * var2, TypeDecl::Data && data, 186 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars, 184 bool bindVarToVar( 185 const TypeInstType * var1, const TypeInstType * var2, TypeDecl::Data && data, 186 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars, 187 187 ResolvExpr::WidenMode widen, const SymbolTable & symtab ); 188 188 … … 199 199 200 200 /// Unifies the type bound of `to` with the type bound of `from`, returning false if fails 201 bool mergeBound( 201 bool mergeBound( 202 202 EqvClass & to, const EqvClass & from, OpenVarSet & openVars, const SymbolTable & symtab ); 203 203 204 204 /// Merges two type classes from local environment, returning false if fails 205 bool mergeClasses( 206 ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars, 205 bool mergeClasses( 206 ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars, 207 207 const SymbolTable & symtab ); 208 208 -
src/AST/TypeSubstitution.cpp
r1fcc2f3 rd056d0d 92 92 namespace { 93 93 struct EnvTrimmer { 94 const TypeSubstitution *env;94 ptr<TypeSubstitution> env; 95 95 TypeSubstitution * newEnv; 96 96 EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){} … … 108 108 if ( env ) { 109 109 TypeSubstitution * newEnv = new TypeSubstitution(); 110 #if TIME_TO_CONVERT_PASSES 110 111 Pass<EnvTrimmer> trimmer( env, newEnv ); 111 112 expr->accept( trimmer ); 113 #else 114 (void)expr; 115 (void)env; 116 #endif 112 117 return newEnv; 113 118 } … … 116 121 117 122 void TypeSubstitution::normalize() { 118 Pass<Substituter> sub( *this, true ); 123 #if TIME_TO_CONVERT_PASSES 124 PassVisitor<Substituter> sub( *this, true ); 119 125 do { 120 126 sub.pass.subCount = 0; 121 127 sub.pass.freeOnly = true; 122 128 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 123 i->second = i->second->accept ( sub );129 i->second = i->second->acceptMutator( sub ); 124 130 } 125 131 } while ( sub.pass.subCount ); 126 } 127 128 const Type * TypeSubstitution::Substituter::postvisit( const TypeInstType *inst ) { 132 #endif 133 } 134 135 #if TIME_TO_CONVERT_PASSES 136 137 Type * TypeSubstitution::Substituter::postmutate( TypeInstType *inst ) { 129 138 BoundVarsType::const_iterator bound = boundVars.find( inst->name ); 130 139 if ( bound != boundVars.end() ) return inst; … … 137 146 // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here. 138 147 // TODO: investigate preventing type variables from being bound to themselves in the first place. 139 if ( constTypeInstType * replacement = i->second.as<TypeInstType>() ) {148 if ( TypeInstType * replacement = i->second.as<TypeInstType>() ) { 140 149 if ( inst->name == replacement->name ) { 141 150 return inst; … … 144 153 // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl; 145 154 subCount++; 146 ptr<Type> newType = i->second; // force clone if needed 147 add_qualifiers( newType, inst->qualifiers ); 148 // Note: need to recursively apply substitution to the new type because normalize does not 149 // substitute bound vars, but bound vars must be substituted when not in freeOnly mode. 150 newType = newType->accept( *visitor ); 151 return newType.release(); 152 } // if 153 } 154 155 const Expr * TypeSubstitution::Substituter::postvisit( const NameExpr * nameExpr ) { 155 Type * newtype = i->second->clone(); 156 newtype->get_qualifiers() |= inst->get_qualifiers(); 157 delete inst; 158 // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode. 159 return newtype->acceptMutator( *visitor ); 160 } // if 161 } 162 163 Expression * TypeSubstitution::Substituter::postmutate( NameExpr * nameExpr ) { 156 164 VarEnvType::const_iterator i = sub.varEnv.find( nameExpr->name ); 157 165 if ( i == sub.varEnv.end() ) { … … 159 167 } else { 160 168 subCount++; 161 return i->second; 162 } // if 163 } 164 165 void TypeSubstitution::Substituter::previsit( const ParameterizedType * ptype ) { 169 delete nameExpr; 170 return i->second->clone(); 171 } // if 172 } 173 174 void TypeSubstitution::Substituter::premutate( Type * type ) { 166 175 GuardValue( boundVars ); 167 176 // bind type variables from forall-qualifiers 168 177 if ( freeOnly ) { 169 for ( const TypeDecl * tyvar : ptype->forall) {170 boundVars.insert( tyvar->name );178 for ( Type::ForallList::const_iterator tyvar = type->forall.begin(); tyvar != type->forall.end(); ++tyvar ) { 179 boundVars.insert( (*tyvar)->name ); 171 180 } // for 172 181 } // if 173 182 } 174 183 175 void TypeSubstitution::Substituter::handleAggregateType( const ReferenceToType * type ) { 184 template< typename TypeClass > 185 void TypeSubstitution::Substituter::handleAggregateType( TypeClass * type ) { 176 186 GuardValue( boundVars ); 177 187 // bind type variables from forall-qualifiers 178 188 if ( freeOnly ) { 179 for ( const TypeDecl * tyvar : type->forall) {180 boundVars.insert( tyvar->name );189 for ( Type::ForallList::const_iterator tyvar = type->forall.begin(); tyvar != type->forall.end(); ++tyvar ) { 190 boundVars.insert( (*tyvar)->name ); 181 191 } // for 182 192 // bind type variables from generic type instantiations 183 if ( auto decl = type->aggr() ) { 184 if ( ! type->params.empty() ) { 185 for ( const TypeDecl * tyvar : decl->params ) { 186 boundVars.insert( tyvar->name ); 187 } // for 188 } // if 189 } 190 } // if 191 } 192 193 void TypeSubstitution::Substituter::previsit( const StructInstType * aggregateUseType ) { 193 std::list< TypeDecl* > *baseParameters = type->get_baseParameters(); 194 if ( baseParameters && ! type->parameters.empty() ) { 195 for ( std::list< TypeDecl* >::const_iterator tyvar = baseParameters->begin(); tyvar != baseParameters->end(); ++tyvar ) { 196 boundVars.insert( (*tyvar)->name ); 197 } // for 198 } // if 199 } // if 200 } 201 202 void TypeSubstitution::Substituter::premutate( StructInstType * aggregateUseType ) { 194 203 handleAggregateType( aggregateUseType ); 195 204 } 196 205 197 void TypeSubstitution::Substituter::pre visit( constUnionInstType *aggregateUseType ) {206 void TypeSubstitution::Substituter::premutate( UnionInstType *aggregateUseType ) { 198 207 handleAggregateType( aggregateUseType ); 199 208 } 209 210 #endif 200 211 201 212 } // namespace ast -
src/AST/TypeSubstitution.hpp
r1fcc2f3 rd056d0d 44 44 TypeSubstitution &operator=( const TypeSubstitution &other ); 45 45 46 template< typename SynTreeClass > 47 struct ApplyResult { 48 const SynTreeClass * node; 49 int count; 50 }; 51 52 template< typename SynTreeClass > ApplyResult<SynTreeClass> apply( const SynTreeClass * input ) const; 53 template< typename SynTreeClass > ApplyResult<SynTreeClass> applyFree( const SynTreeClass * input ) const; 46 template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const; 47 template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const; 54 48 55 49 template< typename node_t, enum Node::ref_type ref_t > 56 50 int apply( ptr_base< node_t, ref_t > & input ) const { 57 51 const node_t * p = input.get(); 58 autoret = apply(p);59 input = ret.node;60 return ret .count;52 int ret = apply(p); 53 input = p; 54 return ret; 61 55 } 62 56 … … 64 58 int applyFree( ptr_base< node_t, ref_t > & input ) const { 65 59 const node_t * p = input.get(); 66 autoret = applyFree(p);67 input = ret.node;68 return ret .count;60 int ret = applyFree(p); 61 input = p; 62 return ret; 69 63 } 70 64 … … 161 155 Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {} 162 156 163 const Type * postvisit( const TypeInstType * aggregateUseType ); 164 const Expr * postvisit( const NameExpr * nameExpr ); 157 #if TIME_TO_CONVERT_PASSES 158 159 Type * postmutate( TypeInstType * aggregateUseType ); 160 Expression * postmutate( NameExpr * nameExpr ); 165 161 166 162 /// Records type variable bindings from forall-statements 167 void pre visit( const ParameterizedType * type );163 void premutate( Type * type ); 168 164 /// Records type variable bindings from forall-statements and instantiations of generic types 169 void handleAggregateType( const ReferenceToType * type ); 170 171 void previsit( const StructInstType * aggregateUseType ); 172 void previsit( const UnionInstType * aggregateUseType ); 165 template< typename TypeClass > void handleAggregateType( TypeClass * type ); 166 167 void premutate( StructInstType * aggregateUseType ); 168 void premutate( UnionInstType * aggregateUseType ); 169 170 #endif 173 171 174 172 const TypeSubstitution & sub; … … 181 179 182 180 template< typename SynTreeClass > 183 TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::apply( const SynTreeClass *input ) const {181 int TypeSubstitution::apply( const SynTreeClass *& input ) const { 184 182 assert( input ); 185 183 Pass<Substituter> sub( *this, false ); 186 184 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 187 return { input, sub.pass.subCount }; 185 /// std::cerr << "substitution result is: "; 186 /// newType->print( std::cerr ); 187 /// std::cerr << std::endl; 188 return sub.pass.subCount; 188 189 } 189 190 190 191 template< typename SynTreeClass > 191 TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::applyFree( const SynTreeClass *input ) const {192 int TypeSubstitution::applyFree( const SynTreeClass *& input ) const { 192 193 assert( input ); 193 194 Pass<Substituter> sub( *this, true ); 194 195 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 195 return { input, sub.pass.subCount }; 196 /// std::cerr << "substitution result is: "; 197 /// newType->print( std::cerr ); 198 /// std::cerr << std::endl; 199 return sub.pass.subCount; 196 200 } 197 201 -
src/AST/module.mk
r1fcc2f3 rd056d0d 22 22 AST/DeclReplacer.cpp \ 23 23 AST/Expr.cpp \ 24 AST/ForallSubstitutionTable.cpp \25 24 AST/GenericSubstitution.cpp \ 26 25 AST/Init.cpp \ -
src/Common/ScopedMap.h
r1fcc2f3 rd056d0d 249 249 250 250 /// Gets the note at the given scope 251 Note& getNote() { return scopes.back().note; }252 const Note& getNote() const { return scopes.back().note; }253 251 Note& getNote( size_type i ) { return scopes[i].note; } 254 252 const Note& getNote( size_type i ) const { return scopes[i].note; } -
src/Makefile.in
r1fcc2f3 rd056d0d 169 169 AST/Convert.$(OBJEXT) AST/Decl.$(OBJEXT) \ 170 170 AST/DeclReplacer.$(OBJEXT) AST/Expr.$(OBJEXT) \ 171 AST/ForallSubstitutionTable.$(OBJEXT) \172 171 AST/GenericSubstitution.$(OBJEXT) AST/Init.$(OBJEXT) \ 173 172 AST/LinkageSpec.$(OBJEXT) AST/Node.$(OBJEXT) \ … … 591 590 AST/DeclReplacer.cpp \ 592 591 AST/Expr.cpp \ 593 AST/ForallSubstitutionTable.cpp \594 592 AST/GenericSubstitution.cpp \ 595 593 AST/Init.cpp \ … … 767 765 AST/$(DEPDIR)/$(am__dirstamp) 768 766 AST/Expr.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp) 769 AST/ForallSubstitutionTable.$(OBJEXT): AST/$(am__dirstamp) \770 AST/$(DEPDIR)/$(am__dirstamp)771 767 AST/GenericSubstitution.$(OBJEXT): AST/$(am__dirstamp) \ 772 768 AST/$(DEPDIR)/$(am__dirstamp) … … 1222 1218 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/DeclReplacer.Po@am__quote@ 1223 1219 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Expr.Po@am__quote@ 1224 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/ForallSubstitutionTable.Po@am__quote@1225 1220 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/GenericSubstitution.Po@am__quote@ 1226 1221 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Init.Po@am__quote@ -
src/ResolvExpr/AdjustExprType.cc
r1fcc2f3 rd056d0d 100 100 101 101 namespace { 102 class AdjustExprType_new final : public ast::WithShortCircuiting { 102 struct AdjustExprType_new final : public ast::WithShortCircuiting { 103 const ast::TypeEnvironment & tenv; 103 104 const ast::SymbolTable & symtab; 104 public:105 const ast::TypeEnvironment & tenv;106 105 107 106 AdjustExprType_new( const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 108 : symtab( syms ), tenv( e) {}107 : tenv( e ), symtab( syms ) {} 109 108 110 void pre visit( const ast::VoidType * ) { visit_children = false; }111 void pre visit( const ast::BasicType * ) { visit_children = false; }112 void pre visit( const ast::PointerType * ) { visit_children = false; }113 void pre visit( const ast::ArrayType * ) { visit_children = false; }114 void pre visit( const ast::FunctionType * ) { visit_children = false; }115 void pre visit( const ast::StructInstType * ) { visit_children = false; }116 void pre visit( const ast::UnionInstType * ) { visit_children = false; }117 void pre visit( const ast::EnumInstType * ) { visit_children = false; }118 void pre visit( const ast::TraitInstType * ) { visit_children = false; }119 void pre visit( const ast::TypeInstType * ) { visit_children = false; }120 void pre visit( const ast::TupleType * ) { visit_children = false; }121 void pre visit( const ast::VarArgsType * ) { visit_children = false; }122 void pre visit( const ast::ZeroType * ) { visit_children = false; }123 void pre visit( const ast::OneType * ) { visit_children = false; }109 void premutate( const ast::VoidType * ) { visit_children = false; } 110 void premutate( const ast::BasicType * ) { visit_children = false; } 111 void premutate( const ast::PointerType * ) { visit_children = false; } 112 void premutate( const ast::ArrayType * ) { visit_children = false; } 113 void premutate( const ast::FunctionType * ) { visit_children = false; } 114 void premutate( const ast::StructInstType * ) { visit_children = false; } 115 void premutate( const ast::UnionInstType * ) { visit_children = false; } 116 void premutate( const ast::EnumInstType * ) { visit_children = false; } 117 void premutate( const ast::TraitInstType * ) { visit_children = false; } 118 void premutate( const ast::TypeInstType * ) { visit_children = false; } 119 void premutate( const ast::TupleType * ) { visit_children = false; } 120 void premutate( const ast::VarArgsType * ) { visit_children = false; } 121 void premutate( const ast::ZeroType * ) { visit_children = false; } 122 void premutate( const ast::OneType * ) { visit_children = false; } 124 123 125 const ast::Type * post visit( const ast::ArrayType * at ) {124 const ast::Type * postmutate( const ast::ArrayType * at ) { 126 125 return new ast::PointerType{ at->base, at->qualifiers }; 127 126 } 128 127 129 const ast::Type * post visit( const ast::FunctionType * ft ) {128 const ast::Type * postmutate( const ast::FunctionType * ft ) { 130 129 return new ast::PointerType{ ft }; 131 130 } 132 131 133 const ast::Type * post visit( const ast::TypeInstType * inst ) {132 const ast::Type * postmutate( const ast::TypeInstType * inst ) { 134 133 // replace known function-type-variables with pointer-to-function 135 134 if ( const ast::EqvClass * eqvClass = tenv.lookup( inst->name ) ) { -
src/ResolvExpr/Candidate.hpp
r1fcc2f3 rd056d0d 51 51 52 52 Candidate( const ast::Expr * x, const ast::TypeEnvironment & e ) 53 : expr( x ), cost( Cost::zero ), cvtCost( Cost::zero ), env( e ), open(), need() { 54 assert(x->result); 55 } 53 : expr( x ), cost( Cost::zero ), cvtCost( Cost::zero ), env( e ), open(), need() {} 56 54 57 55 Candidate( const Candidate & o, const ast::Expr * x, const Cost & addedCost = Cost::zero ) 58 56 : expr( x ), cost( o.cost + addedCost ), cvtCost( Cost::zero ), env( o.env ), open( o.open ), 59 need( o.need ) { 60 assert(x->result); 61 } 57 need( o.need ) {} 62 58 63 59 Candidate( 64 const ast::Expr * x, const ast::TypeEnvironment & e, const ast::OpenVarSet & o, 60 const ast::Expr * x, const ast::TypeEnvironment & e, const ast::OpenVarSet & o, 65 61 const ast::AssertionSet & n, const Cost & c, const Cost & cvt = Cost::zero ) 66 : expr( x ), cost( c ), cvtCost( cvt ), env( e ), open( o ), need( n.begin(), n.end() ) { 67 assert(x->result); 68 } 62 : expr( x ), cost( c ), cvtCost( cvt ), env( e ), open( o ), need( n.begin(), n.end() ) {} 69 63 70 64 Candidate( … … 72 66 ast::AssertionSet && n, const Cost & c, const Cost & cvt = Cost::zero ) 73 67 : expr( x ), cost( c ), cvtCost( cvt ), env( std::move( e ) ), open( std::move( o ) ), 74 need( n.begin(), n.end() ) { 75 assert(x->result); 76 } 68 need( n.begin(), n.end() ) {} 77 69 }; 78 70 -
src/ResolvExpr/CandidateFinder.cpp
r1fcc2f3 rd056d0d 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed Jun 5 14:30:00 2019 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Tue Oct 1 14:55:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Wed Jun 5 14:30:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 54 54 return new ast::CastExpr{ expr, expr->result->stripReferences() }; 55 55 } 56 56 57 57 return expr; 58 58 } … … 61 61 UniqueId globalResnSlot = 0; 62 62 63 Cost computeConversionCost( 64 const ast::Type * argType, const ast::Type * paramType, bool argIsLvalue,65 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env63 Cost computeConversionCost( 64 const ast::Type * argType, const ast::Type * paramType, const ast::SymbolTable & symtab, 65 const ast::TypeEnvironment & env 66 66 ) { 67 67 PRINT( … … 74 74 std::cerr << std::endl; 75 75 ) 76 Cost convCost = conversionCost( argType, paramType, argIsLvalue,symtab, env );76 Cost convCost = conversionCost( argType, paramType, symtab, env ); 77 77 PRINT( 78 78 std::cerr << std::endl << "cost is " << convCost << std::endl; … … 107 107 108 108 /// Computes conversion cost for a given expression to a given type 109 const ast::Expr * computeExpressionConversionCost( 110 const ast::Expr * arg, const ast::Type * paramType, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, Cost & outCost 109 const ast::Expr * computeExpressionConversionCost( 110 const ast::Expr * arg, const ast::Type * paramType, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, Cost & outCost 111 111 ) { 112 Cost convCost = computeConversionCost( 113 arg->result, paramType, arg->get_lvalue(), symtab, env ); 112 Cost convCost = computeConversionCost( arg->result, paramType, symtab, env ); 114 113 outCost += convCost; 115 114 116 // If there is a non-zero conversion cost, ignoring poly cost, then the expression requires 117 // conversion. Ignore poly cost for now, since this requires resolution of the cast to 115 // If there is a non-zero conversion cost, ignoring poly cost, then the expression requires 116 // conversion. Ignore poly cost for now, since this requires resolution of the cast to 118 117 // infer parameters and this does not currently work for the reason stated below 119 118 Cost tmpCost = convCost; … … 124 123 return new ast::CastExpr{ arg, newType }; 125 124 126 // xxx - *should* be able to resolve this cast, but at the moment pointers are not 127 // castable to zero_t, but are implicitly convertible. This is clearly inconsistent, 125 // xxx - *should* be able to resolve this cast, but at the moment pointers are not 126 // castable to zero_t, but are implicitly convertible. This is clearly inconsistent, 128 127 // once this is fixed it should be possible to resolve the cast. 129 // xxx - this isn't working, it appears because type1 (parameter) is seen as widenable, 130 // but it shouldn't be because this makes the conversion from DT* to DT* since 128 // xxx - this isn't working, it appears because type1 (parameter) is seen as widenable, 129 // but it shouldn't be because this makes the conversion from DT* to DT* since 131 130 // commontype(zero_t, DT*) is DT*, rather than nothing 132 131 133 132 // CandidateFinder finder{ symtab, env }; 134 133 // finder.find( arg, ResolvMode::withAdjustment() ); 135 // assertf( finder.candidates.size() > 0, 134 // assertf( finder.candidates.size() > 0, 136 135 // "Somehow castable expression failed to find alternatives." ); 137 // assertf( finder.candidates.size() == 1, 136 // assertf( finder.candidates.size() == 1, 138 137 // "Somehow got multiple alternatives for known cast expression." ); 139 138 // return finder.candidates.front()->expr; … … 144 143 145 144 /// Computes conversion cost for a given candidate 146 Cost computeApplicationConversionCost( 147 CandidateRef cand, const ast::SymbolTable & symtab 145 Cost computeApplicationConversionCost( 146 CandidateRef cand, const ast::SymbolTable & symtab 148 147 ) { 149 148 auto appExpr = cand->expr.strict_as< ast::ApplicationExpr >(); … … 168 167 if ( function->isVarArgs ) { 169 168 convCost.incUnsafe(); 170 PRINT( std::cerr << "end of params with varargs function: inc unsafe: " 169 PRINT( std::cerr << "end of params with varargs function: inc unsafe: " 171 170 << convCost << std::endl; ; ) 172 171 // convert reference-typed expressions into value-typed expressions 173 cand->expr = ast::mutate_field_index( 174 appExpr, &ast::ApplicationExpr::args, i, 172 cand->expr = ast::mutate_field_index( 173 appExpr, &ast::ApplicationExpr::args, i, 175 174 referenceToRvalueConversion( args[i], convCost ) ); 176 175 continue; … … 181 180 // Default arguments should be free - don't include conversion cost. 182 181 // Unwrap them here because they are not relevant to the rest of the system 183 cand->expr = ast::mutate_field_index( 182 cand->expr = ast::mutate_field_index( 184 183 appExpr, &ast::ApplicationExpr::args, i, def->expr ); 185 184 ++param; … … 189 188 // mark conversion cost and also specialization cost of param type 190 189 const ast::Type * paramType = (*param)->get_type(); 191 cand->expr = ast::mutate_field_index( 192 appExpr, &ast::ApplicationExpr::args, i, 193 computeExpressionConversionCost( 190 cand->expr = ast::mutate_field_index( 191 appExpr, &ast::ApplicationExpr::args, i, 192 computeExpressionConversionCost( 194 193 args[i], paramType, symtab, cand->env, convCost ) ); 195 194 convCost.decSpec( specCost( paramType ) ); … … 199 198 if ( param != params.end() ) return Cost::infinity; 200 199 201 // specialization cost of return types can't be accounted for directly, it disables 200 // specialization cost of return types can't be accounted for directly, it disables 202 201 // otherwise-identical calls, like this example based on auto-newline in the I/O lib: 203 202 // … … 216 215 } 217 216 218 void makeUnifiableVars( 219 const ast::ParameterizedType * type, ast::OpenVarSet & unifiableVars, 220 ast::AssertionSet & need 217 void makeUnifiableVars( 218 const ast::ParameterizedType * type, ast::OpenVarSet & unifiableVars, 219 ast::AssertionSet & need 221 220 ) { 222 221 for ( const ast::TypeDecl * tyvar : type->forall ) { … … 255 254 256 255 ArgPack() 257 : parent( 0 ), expr(), cost( Cost::zero ), env(), need(), have(), open(), nextArg( 0 ), 256 : parent( 0 ), expr(), cost( Cost::zero ), env(), need(), have(), open(), nextArg( 0 ), 258 257 tupleStart( 0 ), nextExpl( 0 ), explAlt( 0 ) {} 259 258 259 ArgPack( 260 const ast::TypeEnvironment & env, const ast::AssertionSet & need, 261 const ast::AssertionSet & have, const ast::OpenVarSet & open ) 262 : parent( 0 ), expr(), cost( Cost::zero ), env( env ), need( need ), have( have ), 263 open( open ), nextArg( 0 ), tupleStart( 0 ), nextExpl( 0 ), explAlt( 0 ) {} 264 260 265 ArgPack( 261 const ast::TypeEnvironment & env, const ast::AssertionSet & need, 262 const ast::AssertionSet & have, const ast::OpenVarSet & open ) 263 : parent( 0 ), expr(), cost( Cost::zero ), env( env ), need( need ), have( have ), 264 open( open ), nextArg( 0 ), tupleStart( 0 ), nextExpl( 0 ), explAlt( 0 ) {} 265 266 ArgPack( 267 std::size_t parent, const ast::Expr * expr, ast::TypeEnvironment && env, 268 ast::AssertionSet && need, ast::AssertionSet && have, ast::OpenVarSet && open, 269 unsigned nextArg, unsigned tupleStart = 0, Cost cost = Cost::zero, 266 std::size_t parent, const ast::Expr * expr, ast::TypeEnvironment && env, 267 ast::AssertionSet && need, ast::AssertionSet && have, ast::OpenVarSet && open, 268 unsigned nextArg, unsigned tupleStart = 0, Cost cost = Cost::zero, 270 269 unsigned nextExpl = 0, unsigned explAlt = 0 ) 271 270 : parent(parent), expr( expr ), cost( cost ), env( move( env ) ), need( move( need ) ), 272 271 have( move( have ) ), open( move( open ) ), nextArg( nextArg ), tupleStart( tupleStart ), 273 272 nextExpl( nextExpl ), explAlt( explAlt ) {} 274 273 275 274 ArgPack( 276 const ArgPack & o, ast::TypeEnvironment && env, ast::AssertionSet && need, 275 const ArgPack & o, ast::TypeEnvironment && env, ast::AssertionSet && need, 277 276 ast::AssertionSet && have, ast::OpenVarSet && open, unsigned nextArg, Cost added ) 278 : parent( o.parent ), expr( o.expr ), cost( o.cost + added ), env( move( env ) ), 279 need( move( need ) ), have( move( have ) ), open( move( open ) ), nextArg( nextArg ), 277 : parent( o.parent ), expr( o.expr ), cost( o.cost + added ), env( move( env ) ), 278 need( move( need ) ), have( move( have ) ), open( move( open ) ), nextArg( nextArg ), 280 279 tupleStart( o.tupleStart ), nextExpl( 0 ), explAlt( 0 ) {} 281 280 282 281 /// true if this pack is in the middle of an exploded argument 283 282 bool hasExpl() const { return nextExpl > 0; } … … 287 286 return args[ nextArg-1 ][ explAlt ]; 288 287 } 289 288 290 289 /// Ends a tuple expression, consolidating the appropriate args 291 290 void endTuple( const std::vector< ArgPack > & packs ) { … … 308 307 309 308 /// Instantiates an argument to match a parameter, returns false if no matching results left 310 bool instantiateArgument( 311 const ast::Type * paramType, const ast::Init * init, const ExplodedArgs_new & args, 312 std::vector< ArgPack > & results, std::size_t & genStart, const ast::SymbolTable & symtab, 313 unsigned nTuples = 0 309 bool instantiateArgument( 310 const ast::Type * paramType, const ast::Init * init, const ExplodedArgs_new & args, 311 std::vector< ArgPack > & results, std::size_t & genStart, const ast::SymbolTable & symtab, 312 unsigned nTuples = 0 314 313 ) { 315 314 if ( auto tupleType = dynamic_cast< const ast::TupleType * >( paramType ) ) { … … 319 318 // xxx - dropping initializer changes behaviour from previous, but seems correct 320 319 // ^^^ need to handle the case where a tuple has a default argument 321 if ( ! instantiateArgument( 320 if ( ! instantiateArgument( 322 321 type, nullptr, args, results, genStart, symtab, nTuples ) ) return false; 323 322 nTuples = 0; … … 330 329 } else if ( const ast::TypeInstType * ttype = Tuples::isTtype( paramType ) ) { 331 330 // paramType is a ttype, consumes all remaining arguments 332 331 333 332 // completed tuples; will be spliced to end of results to finish 334 333 std::vector< ArgPack > finalResults{}; … … 343 342 for ( std::size_t i = genStart; i < genEnd; ++i ) { 344 343 unsigned nextArg = results[i].nextArg; 345 344 346 345 // use next element of exploded tuple if present 347 346 if ( results[i].hasExpl() ) { … … 353 352 results.emplace_back( 354 353 i, expl.exprs[ results[i].nextExpl ], copy( results[i].env ), 355 copy( results[i].need ), copy( results[i].have ), 354 copy( results[i].need ), copy( results[i].have ), 356 355 copy( results[i].open ), nextArg, nTuples, Cost::zero, nextExpl, 357 356 results[i].explAlt ); … … 371 370 // push empty tuple expression 372 371 newResult.parent = i; 373 newResult.expr = new ast::TupleExpr{ CodeLocation{}, {} }; 372 std::vector< ast::ptr< ast::Expr > > emptyList; 373 newResult.expr = 374 new ast::TupleExpr{ CodeLocation{}, move( emptyList ) }; 374 375 argType = newResult.expr->result; 375 376 } else { … … 399 400 400 401 // check unification for ttype before adding to final 401 if ( 402 unify( 402 if ( 403 unify( 403 404 ttype, argType, newResult.env, newResult.need, newResult.have, 404 newResult.open, symtab ) 405 newResult.open, symtab ) 405 406 ) { 406 407 finalResults.emplace_back( move( newResult ) ); … … 423 424 if ( expl.exprs.empty() ) { 424 425 results.emplace_back( 425 results[i], move( env ), copy( results[i].need ), 426 results[i], move( env ), copy( results[i].need ), 426 427 copy( results[i].have ), move( open ), nextArg + 1, expl.cost ); 427 428 428 429 continue; 429 430 } … … 431 432 // add new result 432 433 results.emplace_back( 433 i, expl.exprs.front(), move( env ), copy( results[i].need ), 434 copy( results[i].have ), move( open ), nextArg + 1, nTuples, 434 i, expl.exprs.front(), move( env ), copy( results[i].need ), 435 copy( results[i].have ), move( open ), nextArg + 1, nTuples, 435 436 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 436 437 } … … 478 479 479 480 results.emplace_back( 480 i, expr, move( env ), move( need ), move( have ), move( open ), nextArg, 481 i, expr, move( env ), move( need ), move( have ), move( open ), nextArg, 481 482 nTuples, Cost::zero, nextExpl, results[i].explAlt ); 482 483 } … … 494 495 if ( unify( paramType, cnst->result, env, need, have, open, symtab ) ) { 495 496 results.emplace_back( 496 i, new ast::DefaultArgExpr{ cnst->location, cnst }, move( env ), 497 i, new ast::DefaultArgExpr{ cnst->location, cnst }, move( env ), 497 498 move( need ), move( have ), move( open ), nextArg, nTuples ); 498 499 } … … 516 517 if ( expl.exprs.empty() ) { 517 518 results.emplace_back( 518 results[i], move( env ), move( need ), move( have ), move( open ), 519 results[i], move( env ), move( need ), move( have ), move( open ), 519 520 nextArg + 1, expl.cost ); 520 521 521 522 continue; 522 523 } … … 538 539 // add new result 539 540 results.emplace_back( 540 i, expr, move( env ), move( need ), move( have ), move( open ), 541 i, expr, move( env ), move( need ), move( have ), move( open ), 541 542 nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 542 543 } … … 547 548 genStart = genEnd; 548 549 549 return genEnd != results.size(); // were any new results added?550 return genEnd != results.size(); 550 551 } 551 552 552 553 /// Generate a cast expression from `arg` to `toType` 553 const ast::Expr * restructureCast( 554 const ast::Expr * restructureCast( 554 555 ast::ptr< ast::Expr > & arg, const ast::Type * toType, ast::GeneratedFlag isGenerated = ast::GeneratedCast 555 556 ) { 556 if ( 557 arg->result->size() > 1 558 && ! toType->isVoid() 559 && ! dynamic_cast< const ast::ReferenceType * >( toType ) 557 if ( 558 arg->result->size() > 1 559 && ! toType->isVoid() 560 && ! dynamic_cast< const ast::ReferenceType * >( toType ) 560 561 ) { 561 // Argument is a tuple and the target type is neither void nor a reference. Cast each 562 // member of the tuple to its corresponding target type, producing the tuple of those 563 // cast expressions. If there are more components of the tuple than components in the 564 // target type, then excess components do not come out in the result expression (but 562 // Argument is a tuple and the target type is neither void nor a reference. Cast each 563 // member of the tuple to its corresponding target type, producing the tuple of those 564 // cast expressions. If there are more components of the tuple than components in the 565 // target type, then excess components do not come out in the result expression (but 565 566 // UniqueExpr ensures that the side effects will still be produced) 566 567 if ( Tuples::maybeImpureIgnoreUnique( arg ) ) { 567 // expressions which may contain side effects require a single unique instance of 568 // expressions which may contain side effects require a single unique instance of 568 569 // the expression 569 570 arg = new ast::UniqueExpr{ arg->location, arg }; … … 573 574 // cast each component 574 575 ast::ptr< ast::Expr > idx = new ast::TupleIndexExpr{ arg->location, arg, i }; 575 components.emplace_back( 576 components.emplace_back( 576 577 restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 577 578 } … … 593 594 594 595 /// Actually visits expressions to find their candidate interpretations 595 class Finder final : public ast::WithShortCircuiting { 596 struct Finder final : public ast::WithShortCircuiting { 597 CandidateFinder & selfFinder; 596 598 const ast::SymbolTable & symtab; 597 public:598 CandidateFinder & selfFinder;599 599 CandidateList & candidates; 600 600 const ast::TypeEnvironment & tenv; … … 602 602 603 603 Finder( CandidateFinder & f ) 604 : s ymtab( f.localSyms ), selfFinder( f ), candidates( f.candidates ), tenv( f.env ),604 : selfFinder( f ), symtab( f.symtab ), candidates( f.candidates ), tenv( f.env ), 605 605 targetType( f.targetType ) {} 606 606 607 607 void previsit( const ast::Node * ) { visit_children = false; } 608 608 … … 639 639 640 640 /// Completes a function candidate with arguments located 641 void validateFunctionCandidate( 642 const CandidateRef & func, ArgPack & result, const std::vector< ArgPack > & results, 643 CandidateList & out 641 void validateFunctionCandidate( 642 const CandidateRef & func, ArgPack & result, const std::vector< ArgPack > & results, 643 CandidateList & out 644 644 ) { 645 ast::ApplicationExpr * appExpr = 645 ast::ApplicationExpr * appExpr = 646 646 new ast::ApplicationExpr{ func->expr->location, func->expr }; 647 647 // sum cost and accumulate arguments … … 657 657 appExpr->args = move( vargs ); 658 658 // build and validate new candidate 659 auto newCand = 659 auto newCand = 660 660 std::make_shared<Candidate>( appExpr, result.env, result.open, result.need, cost ); 661 661 PRINT( … … 669 669 /// Builds a list of candidates for a function, storing them in out 670 670 void makeFunctionCandidates( 671 const CandidateRef & func, const ast::FunctionType * funcType, 671 const CandidateRef & func, const ast::FunctionType * funcType, 672 672 const ExplodedArgs_new & args, CandidateList & out 673 673 ) { … … 676 676 ast::TypeEnvironment funcEnv{ func->env }; 677 677 makeUnifiableVars( funcType, funcOpen, funcNeed ); 678 // add all type variables as open variables now so that those not used in the 679 // parameterlist are still considered open678 // add all type variables as open variables now so that those not used in the parameter 679 // list are still considered open 680 680 funcEnv.add( funcType->forall ); 681 681 … … 683 683 // attempt to narrow based on expected target type 684 684 const ast::Type * returnType = funcType->returns.front()->get_type(); 685 if ( ! unify( 686 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, symtab ) 685 if ( ! unify( 686 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, symtab ) 687 687 ) { 688 688 // unification failed, do not pursue this candidate … … 698 698 for ( const ast::DeclWithType * param : funcType->params ) { 699 699 auto obj = strict_dynamic_cast< const ast::ObjectDecl * >( param ); 700 // Try adding the arguments corresponding to the current parameter to the existing 700 // Try adding the arguments corresponding to the current parameter to the existing 701 701 // matches 702 if ( ! instantiateArgument( 702 if ( ! instantiateArgument( 703 703 obj->type, obj->init, args, results, genStart, symtab ) ) return; 704 704 } … … 750 750 if ( expl.exprs.empty() ) { 751 751 results.emplace_back( 752 results[i], move( env ), copy( results[i].need ), 753 copy( results[i].have ), move( open ), nextArg + 1, 752 results[i], move( env ), copy( results[i].need ), 753 copy( results[i].have ), move( open ), nextArg + 1, 754 754 expl.cost ); 755 755 … … 760 760 results.emplace_back( 761 761 i, expl.exprs.front(), move( env ), copy( results[i].need ), 762 copy( results[i].have ), move( open ), nextArg + 1, 0, expl.cost, 762 copy( results[i].have ), move( open ), nextArg + 1, 0, expl.cost, 763 763 expl.exprs.size() == 1 ? 0 : 1, j ); 764 764 } … … 780 780 /// Adds implicit struct-conversions to the alternative list 781 781 void addAnonConversions( const CandidateRef & cand ) { 782 // adds anonymous member interpretations whenever an aggregate value type is seen. 783 // it's okay for the aggregate expression to have reference type -- cast it to the 782 // adds anonymous member interpretations whenever an aggregate value type is seen. 783 // it's okay for the aggregate expression to have reference type -- cast it to the 784 784 // base type to treat the aggregate as the referenced value 785 785 ast::ptr< ast::Expr > aggrExpr( cand->expr ); 786 786 ast::ptr< ast::Type > & aggrType = aggrExpr.get_and_mutate()->result; 787 787 cand->env.apply( aggrType ); 788 788 789 789 if ( aggrType.as< ast::ReferenceType >() ) { 790 790 aggrExpr = new ast::CastExpr{ aggrExpr, aggrType->stripReferences() }; … … 799 799 800 800 /// Adds aggregate member interpretations 801 void addAggMembers( 802 const ast::ReferenceToType * aggrInst, const ast::Expr * expr, 803 const Candidate & cand, const Cost & addedCost, const std::string & name 801 void addAggMembers( 802 const ast::ReferenceToType * aggrInst, const ast::Expr * expr, 803 const Candidate & cand, const Cost & addedCost, const std::string & name 804 804 ) { 805 805 for ( const ast::Decl * decl : aggrInst->lookup( name ) ) { 806 806 auto dwt = strict_dynamic_cast< const ast::DeclWithType * >( decl ); 807 CandidateRef newCand = std::make_shared<Candidate>( 807 CandidateRef newCand = std::make_shared<Candidate>( 808 808 cand, new ast::MemberExpr{ expr->location, dwt, expr }, addedCost ); 809 // add anonymous member interpretations whenever an aggregate value type is seen 809 // add anonymous member interpretations whenever an aggregate value type is seen 810 810 // as a member expression 811 811 addAnonConversions( newCand ); … … 815 815 816 816 /// Adds tuple member interpretations 817 void addTupleMembers( 818 const ast::TupleType * tupleType, const ast::Expr * expr, const Candidate & cand, 819 const Cost & addedCost, const ast::Expr * member 817 void addTupleMembers( 818 const ast::TupleType * tupleType, const ast::Expr * expr, const Candidate & cand, 819 const Cost & addedCost, const ast::Expr * member 820 820 ) { 821 821 if ( auto constantExpr = dynamic_cast< const ast::ConstantExpr * >( member ) ) { 822 // get the value of the constant expression as an int, must be between 0 and the 822 // get the value of the constant expression as an int, must be between 0 and the 823 823 // length of the tuple to have meaning 824 824 long long val = constantExpr->intValue(); 825 825 if ( val >= 0 && (unsigned long long)val < tupleType->size() ) { 826 826 addCandidate( 827 cand, new ast::TupleIndexExpr{ expr->location, expr, (unsigned)val }, 827 cand, new ast::TupleIndexExpr{ expr->location, expr, (unsigned)val }, 828 828 addedCost ); 829 829 } … … 837 837 if ( funcFinder.candidates.empty() ) return; 838 838 839 std::vector< CandidateFinder > argCandidates = 839 std::vector< CandidateFinder > argCandidates = 840 840 selfFinder.findSubExprs( untypedExpr->args ); 841 841 842 842 // take care of possible tuple assignments 843 843 // if not tuple assignment, handled as normal function call … … 877 877 if ( auto function = pointer->base.as< ast::FunctionType >() ) { 878 878 CandidateRef newFunc{ new Candidate{ *func } }; 879 newFunc->expr = 879 newFunc->expr = 880 880 referenceToRvalueConversion( newFunc->expr, newFunc->cost ); 881 881 makeFunctionCandidates( newFunc, function, argExpansions, found ); 882 882 } 883 } else if ( 884 auto inst = dynamic_cast< const ast::TypeInstType * >( funcResult ) 883 } else if ( 884 auto inst = dynamic_cast< const ast::TypeInstType * >( funcResult ) 885 885 ) { 886 886 if ( const ast::EqvClass * clz = func->env.lookup( inst->name ) ) { 887 887 if ( auto function = clz->bound.as< ast::FunctionType >() ) { 888 888 CandidateRef newFunc{ new Candidate{ *func } }; 889 newFunc->expr = 889 newFunc->expr = 890 890 referenceToRvalueConversion( newFunc->expr, newFunc->cost ); 891 891 makeFunctionCandidates( newFunc, function, argExpansions, found ); … … 901 901 std::vector< ExplodedArg > funcE; 902 902 funcE.reserve( funcFinder.candidates.size() ); 903 for ( const CandidateRef & func : funcFinder ) { 903 for ( const CandidateRef & func : funcFinder ) { 904 904 funcE.emplace_back( *func, symtab ); 905 905 } … … 913 913 if ( auto function = pointer->base.as< ast::FunctionType >() ) { 914 914 CandidateRef newOp{ new Candidate{ *op} }; 915 newOp->expr = 915 newOp->expr = 916 916 referenceToRvalueConversion( newOp->expr, newOp->cost ); 917 917 makeFunctionCandidates( newOp, function, argExpansions, found ); … … 922 922 } 923 923 924 // Implement SFINAE; resolution errors are only errors if there aren't any non-error 924 // Implement SFINAE; resolution errors are only errors if there aren't any non-error 925 925 // candidates 926 926 if ( found.empty() && ! errors.isEmpty() ) { throw errors; } … … 934 934 auto pointer = appExpr->func->result.strict_as< ast::PointerType >(); 935 935 auto function = pointer->base.strict_as< ast::FunctionType >(); 936 936 937 937 std::cerr << "Case +++++++++++++ " << appExpr->func << std::endl; 938 938 std::cerr << "parameters are:" << std::endl; … … 957 957 promoteCvtCost( winners ); 958 958 959 // function may return a struct/union value, in which case we need to add candidates 960 // for implicit conversions to each of the anonymous members, which must happen after 959 // function may return a struct/union value, in which case we need to add candidates 960 // for implicit conversions to each of the anonymous members, which must happen after 961 961 // `findMinCost`, since anon conversions are never the cheapest 962 962 for ( const CandidateRef & c : winners ) { … … 966 966 967 967 if ( candidates.empty() && targetType && ! targetType->isVoid() ) { 968 // If resolution is unsuccessful with a target type, try again without, since it 968 // If resolution is unsuccessful with a target type, try again without, since it 969 969 // will sometimes succeed when it wouldn't with a target type binding. 970 970 // For example: … … 983 983 /// true if expression is an lvalue 984 984 static bool isLvalue( const ast::Expr * x ) { 985 return x->result && ( x-> get_lvalue() || x->result.as< ast::ReferenceType >() );985 return x->result && ( x->result->is_lvalue() || x->result.as< ast::ReferenceType >() ); 986 986 } 987 987 … … 1016 1016 cand->env.extractOpenVars( open ); 1017 1017 1018 // It is possible that a cast can throw away some values in a multiply-valued 1019 // expression, e.g. cast-to-void, one value to zero. Figure out the prefix of the 1020 // subexpression results that are cast directly. The candidate is invalid if it 1018 // It is possible that a cast can throw away some values in a multiply-valued 1019 // expression, e.g. cast-to-void, one value to zero. Figure out the prefix of the 1020 // subexpression results that are cast directly. The candidate is invalid if it 1021 1021 // has fewer results than there are types to cast to. 1022 1022 int discardedValues = cand->expr->result->size() - toType->size(); … … 1025 1025 // unification run for side-effects 1026 1026 unify( toType, cand->expr->result, cand->env, need, have, open, symtab ); 1027 Cost thisCost = castCost( cand->expr->result, toType, cand->expr->get_lvalue(), 1028 symtab, cand->env ); 1027 Cost thisCost = castCost( cand->expr->result, toType, symtab, cand->env ); 1029 1028 PRINT( 1030 1029 std::cerr << "working on cast with result: " << toType << std::endl; … … 1038 1037 // count one safe conversion for each value that is thrown away 1039 1038 thisCost.incSafe( discardedValues ); 1040 CandidateRef newCand = std::make_shared<Candidate>( 1041 restructureCast( cand->expr, toType, castExpr->isGenerated ), 1042 copy( cand->env ), move( open ), move( need ), cand->cost, 1039 CandidateRef newCand = std::make_shared<Candidate>( 1040 restructureCast( cand->expr, toType, castExpr->isGenerated ), 1041 copy( cand->env ), move( open ), move( need ), cand->cost, 1043 1042 cand->cost + thisCost ); 1044 1043 inferParameters( newCand, matches ); … … 1058 1057 finder.find( castExpr->arg, ResolvMode::withoutPrune() ); 1059 1058 for ( CandidateRef & r : finder.candidates ) { 1060 addCandidate( 1061 *r, 1059 addCandidate( 1060 *r, 1062 1061 new ast::VirtualCastExpr{ castExpr->location, r->expr, castExpr->result } ); 1063 1062 } … … 1068 1067 aggFinder.find( memberExpr->aggregate, ResolvMode::withAdjustment() ); 1069 1068 for ( CandidateRef & agg : aggFinder.candidates ) { 1070 // it's okay for the aggregate expression to have reference type -- cast it to the 1069 // it's okay for the aggregate expression to have reference type -- cast it to the 1071 1070 // base type to treat the aggregate as the referenced value 1072 1071 Cost addedCost = Cost::zero; … … 1075 1074 // find member of the given type 1076 1075 if ( auto structInst = agg->expr->result.as< ast::StructInstType >() ) { 1077 addAggMembers( 1076 addAggMembers( 1078 1077 structInst, agg->expr, *agg, addedCost, getMemberName( memberExpr ) ); 1079 1078 } else if ( auto unionInst = agg->expr->result.as< ast::UnionInstType >() ) { 1080 addAggMembers( 1079 addAggMembers( 1081 1080 unionInst, agg->expr, *agg, addedCost, getMemberName( memberExpr ) ); 1082 1081 } else if ( auto tupleType = agg->expr->result.as< ast::TupleType >() ) { … … 1098 1097 1099 1098 CandidateRef newCand = std::make_shared<Candidate>( 1100 newExpr, copy( tenv ), ast::OpenVarSet{}, ast::AssertionSet{}, Cost::zero, 1099 newExpr, copy( tenv ), ast::OpenVarSet{}, ast::AssertionSet{}, Cost::zero, 1101 1100 cost ); 1102 1101 PRINT( … … 1108 1107 std::cerr << std::endl; 1109 1108 ) 1110 newCand->expr = ast::mutate_field( 1111 newCand->expr.get(), &ast::Expr::result, 1109 newCand->expr = ast::mutate_field( 1110 newCand->expr.get(), &ast::Expr::result, 1112 1111 renameTyVars( newCand->expr->result ) ); 1113 // add anonymous member interpretations whenever an aggregate value type is seen 1112 // add anonymous member interpretations whenever an aggregate value type is seen 1114 1113 // as a name expression 1115 1114 addAnonConversions( newCand ); … … 1121 1120 // not sufficient to just pass `variableExpr` here, type might have changed since 1122 1121 // creation 1123 addCandidate( 1122 addCandidate( 1124 1123 new ast::VariableExpr{ variableExpr->location, variableExpr->var }, tenv ); 1125 1124 } … … 1131 1130 void postvisit( const ast::SizeofExpr * sizeofExpr ) { 1132 1131 if ( sizeofExpr->type ) { 1133 addCandidate( 1134 new ast::SizeofExpr{ 1135 sizeofExpr->location, resolveTypeof( sizeofExpr->type, symtab ) }, 1132 addCandidate( 1133 new ast::SizeofExpr{ 1134 sizeofExpr->location, resolveTypeof( sizeofExpr->type, symtab ) }, 1136 1135 tenv ); 1137 1136 } else { … … 1142 1141 CandidateList winners = findMinCost( finder.candidates ); 1143 1142 if ( winners.size() != 1 ) { 1144 SemanticError( 1143 SemanticError( 1145 1144 sizeofExpr->expr.get(), "Ambiguous expression in sizeof operand: " ); 1146 1145 } … … 1155 1154 void postvisit( const ast::AlignofExpr * alignofExpr ) { 1156 1155 if ( alignofExpr->type ) { 1157 addCandidate( 1158 new ast::AlignofExpr{ 1159 alignofExpr->location, resolveTypeof( alignofExpr->type, symtab ) }, 1156 addCandidate( 1157 new ast::AlignofExpr{ 1158 alignofExpr->location, resolveTypeof( alignofExpr->type, symtab ) }, 1160 1159 tenv ); 1161 1160 } else { … … 1166 1165 CandidateList winners = findMinCost( finder.candidates ); 1167 1166 if ( winners.size() != 1 ) { 1168 SemanticError( 1167 SemanticError( 1169 1168 alignofExpr->expr.get(), "Ambiguous expression in alignof operand: " ); 1170 1169 } … … 1173 1172 choice->expr = referenceToRvalueConversion( choice->expr, choice->cost ); 1174 1173 choice->cost = Cost::zero; 1175 addCandidate( 1174 addCandidate( 1176 1175 *choice, new ast::AlignofExpr{ alignofExpr->location, choice->expr } ); 1177 1176 } … … 1186 1185 for ( const ast::Decl * member : aggInst->lookup( offsetofExpr->member ) ) { 1187 1186 auto dwt = strict_dynamic_cast< const ast::DeclWithType * >( member ); 1188 addCandidate( 1187 addCandidate( 1189 1188 new ast::OffsetofExpr{ offsetofExpr->location, aggInst, dwt }, tenv ); 1190 1189 } … … 1219 1218 1220 1219 addCandidate( 1221 new ast::LogicalExpr{ 1220 new ast::LogicalExpr{ 1222 1221 logicalExpr->location, r1->expr, r2->expr, logicalExpr->isAnd }, 1223 1222 move( env ), move( open ), move( need ), r1->cost + r2->cost ); … … 1257 1256 ast::AssertionSet have; 1258 1257 1259 // unify true and false results, then infer parameters to produce new 1258 // unify true and false results, then infer parameters to produce new 1260 1259 // candidates 1261 1260 ast::ptr< ast::Type > common; 1262 if ( 1263 unify( 1264 r2->expr->result, r3->expr->result, env, need, have, open, symtab, 1265 common ) 1261 if ( 1262 unify( 1263 r2->expr->result, r3->expr->result, env, need, have, open, symtab, 1264 common ) 1266 1265 ) { 1267 1266 // generate typed expression 1268 ast::ConditionalExpr * newExpr = new ast::ConditionalExpr{ 1267 ast::ConditionalExpr * newExpr = new ast::ConditionalExpr{ 1269 1268 conditionalExpr->location, r1->expr, r2->expr, r3->expr }; 1270 1269 newExpr->result = common ? common : r2->expr->result; 1271 1270 // convert both options to result type 1272 1271 Cost cost = r1->cost + r2->cost + r3->cost; 1273 newExpr->arg2 = computeExpressionConversionCost( 1272 newExpr->arg2 = computeExpressionConversionCost( 1274 1273 newExpr->arg2, newExpr->result, symtab, env, cost ); 1275 1274 newExpr->arg3 = computeExpressionConversionCost( … … 1288 1287 ast::TypeEnvironment env{ tenv }; 1289 1288 ast::ptr< ast::Expr > arg1 = resolveInVoidContext( commaExpr->arg1, symtab, env ); 1290 1289 1291 1290 CandidateFinder finder2{ symtab, env }; 1292 1291 finder2.find( commaExpr->arg2, ResolvMode::withAdjustment() ); … … 1331 1330 1332 1331 ast::ptr< ast::Type > common; 1333 if ( 1334 unify( 1335 r1->expr->result, r2->expr->result, env, need, have, open, symtab, 1336 common ) 1332 if ( 1333 unify( 1334 r1->expr->result, r2->expr->result, env, need, have, open, symtab, 1335 common ) 1337 1336 ) { 1338 1337 // generate new expression 1339 ast::RangeExpr * newExpr = 1338 ast::RangeExpr * newExpr = 1340 1339 new ast::RangeExpr{ rangeExpr->location, r1->expr, r2->expr }; 1341 1340 newExpr->result = common ? common : r1->expr->result; 1342 1341 // add candidate 1343 1342 CandidateRef newCand = std::make_shared<Candidate>( 1344 newExpr, move( env ), move( open ), move( need ), 1343 newExpr, move( env ), move( open ), move( need ), 1345 1344 r1->cost + r2->cost ); 1346 1345 inferParameters( newCand, candidates ); … … 1351 1350 1352 1351 void postvisit( const ast::UntypedTupleExpr * tupleExpr ) { 1353 std::vector< CandidateFinder > subCandidates = 1352 std::vector< CandidateFinder > subCandidates = 1354 1353 selfFinder.findSubExprs( tupleExpr->exprs ); 1355 1354 std::vector< CandidateList > possibilities; … … 1371 1370 1372 1371 addCandidate( 1373 new ast::TupleExpr{ tupleExpr->location, move( exprs ) }, 1372 new ast::TupleExpr{ tupleExpr->location, move( exprs ) }, 1374 1373 move( env ), move( open ), move( need ), sumCost( subs ) ); 1375 1374 } … … 1413 1412 toType = SymTab::validateType( initExpr->location, toType, symtab ); 1414 1413 toType = adjustExprType( toType, tenv, symtab ); 1415 // The call to find must occur inside this loop, otherwise polymorphic return 1416 // types are not bound to the initialization type, since return type variables are 1417 // only open for the duration of resolving the UntypedExpr. 1414 // The call to find must occur inside this loop, otherwise polymorphic return 1415 // types are not bound to the initialization type, since return type variables are 1416 // only open for the duration of resolving the UntypedExpr. 1418 1417 CandidateFinder finder{ symtab, tenv, toType }; 1419 1418 finder.find( initExpr->expr, ResolvMode::withAdjustment() ); … … 1427 1426 ) 1428 1427 1429 // It is possible that a cast can throw away some values in a multiply-valued 1430 // expression, e.g. cast-to-void, one value to zero. Figure out the prefix of 1431 // the subexpression results that are cast directly. The candidate is invalid 1428 // It is possible that a cast can throw away some values in a multiply-valued 1429 // expression, e.g. cast-to-void, one value to zero. Figure out the prefix of 1430 // the subexpression results that are cast directly. The candidate is invalid 1432 1431 // if it has fewer results than there are types to cast to. 1433 1432 int discardedValues = cand->expr->result->size() - toType->size(); … … 1436 1435 // unification run for side-effects 1437 1436 unify( toType, cand->expr->result, env, need, have, open, symtab ); 1438 Cost thisCost = castCost( cand->expr->result, toType, cand->expr->get_lvalue(), 1439 symtab, env ); 1440 1437 Cost thisCost = castCost( cand->expr->result, toType, symtab, env ); 1438 1441 1439 if ( thisCost != Cost::infinity ) { 1442 1440 // count one safe conversion for each value that is thrown away 1443 1441 thisCost.incSafe( discardedValues ); 1444 CandidateRef newCand = std::make_shared<Candidate>( 1445 new ast::InitExpr{ 1446 initExpr->location, restructureCast( cand->expr, toType ), 1447 initAlt.designation }, 1442 CandidateRef newCand = std::make_shared<Candidate>( 1443 new ast::InitExpr{ 1444 initExpr->location, restructureCast( cand->expr, toType ), 1445 initAlt.designation }, 1448 1446 copy( cand->env ), move( open ), move( need ), cand->cost, thisCost ); 1449 1447 inferParameters( newCand, matches ); … … 1471 1469 }; 1472 1470 1473 /// Prunes a list of candidates down to those that have the minimum conversion cost for a given 1471 /// Prunes a list of candidates down to those that have the minimum conversion cost for a given 1474 1472 /// return type. Skips ambiguous candidates. 1475 1473 CandidateList pruneCandidates( CandidateList & candidates ) { … … 1488 1486 { 1489 1487 ast::ptr< ast::Type > newType = candidate->expr->result; 1490 assertf(candidate->expr->result, "Result of expression %p for candidate is null", candidate->expr.get());1491 1488 candidate->env.apply( newType ); 1492 1489 mangleName = Mangle::mangle( newType ); … … 1497 1494 if ( candidate->cost < found->second.candidate->cost ) { 1498 1495 PRINT( 1499 std::cerr << "cost " << candidate->cost << " beats " 1496 std::cerr << "cost " << candidate->cost << " beats " 1500 1497 << found->second.candidate->cost << std::endl; 1501 1498 ) … … 1503 1500 found->second = PruneStruct{ candidate }; 1504 1501 } else if ( candidate->cost == found->second.candidate->cost ) { 1505 // if one of the candidates contains a deleted identifier, can pick the other, 1506 // since deleted expressions should not be ambiguous if there is another option 1502 // if one of the candidates contains a deleted identifier, can pick the other, 1503 // since deleted expressions should not be ambiguous if there is another option 1507 1504 // that is at least as good 1508 1505 if ( findDeletedExpr( candidate->expr ) ) { … … 1518 1515 } else { 1519 1516 PRINT( 1520 std::cerr << "cost " << candidate->cost << " loses to " 1517 std::cerr << "cost " << candidate->cost << " loses to " 1521 1518 << found->second.candidate->cost << std::endl; 1522 1519 ) … … 1533 1530 1534 1531 CandidateRef cand = target.second.candidate; 1535 1532 1536 1533 ast::ptr< ast::Type > newResult = cand->expr->result; 1537 1534 cand->env.applyFree( newResult ); 1538 1535 cand->expr = ast::mutate_field( 1539 1536 cand->expr.get(), &ast::Expr::result, move( newResult ) ); 1540 1537 1541 1538 out.emplace_back( cand ); 1542 1539 } … … 1561 1558 std::vector< std::string > errors; 1562 1559 for ( CandidateRef & candidate : candidates ) { 1563 satisfyAssertions( candidate, localSyms, satisfied, errors );1560 satisfyAssertions( candidate, symtab, satisfied, errors ); 1564 1561 } 1565 1562 … … 1586 1583 1587 1584 CandidateList pruned = pruneCandidates( candidates ); 1588 1585 1589 1586 if ( mode.failFast && pruned.empty() ) { 1590 1587 std::ostringstream stream; … … 1605 1602 ) 1606 1603 PRINT( 1607 std::cerr << "there are " << candidates.size() << " alternatives after elimination" 1604 std::cerr << "there are " << candidates.size() << " alternatives after elimination" 1608 1605 << std::endl; 1609 1606 ) 1610 1607 } 1611 1608 1612 // adjust types after pruning so that types substituted by pruneAlternatives are correctly 1609 // adjust types after pruning so that types substituted by pruneAlternatives are correctly 1613 1610 // adjusted 1614 1611 if ( mode.adjust ) { 1615 1612 for ( CandidateRef & r : candidates ) { 1616 r->expr = ast::mutate_field( 1617 r->expr.get(), &ast::Expr::result, 1618 adjustExprType( r->expr->result, r->env, localSyms) );1613 r->expr = ast::mutate_field( 1614 r->expr.get(), &ast::Expr::result, 1615 adjustExprType( r->expr->result, r->env, symtab ) ); 1619 1616 } 1620 1617 } … … 1628 1625 } 1629 1626 1630 std::vector< CandidateFinder > CandidateFinder::findSubExprs( 1631 const std::vector< ast::ptr< ast::Expr > > & xs 1627 std::vector< CandidateFinder > CandidateFinder::findSubExprs( 1628 const std::vector< ast::ptr< ast::Expr > > & xs 1632 1629 ) { 1633 1630 std::vector< CandidateFinder > out; 1634 1631 1635 1632 for ( const auto & x : xs ) { 1636 out.emplace_back( localSyms, env );1633 out.emplace_back( symtab, env ); 1637 1634 out.back().find( x, ResolvMode::withAdjustment() ); 1638 1635 1639 1636 PRINT( 1640 1637 std::cerr << "findSubExprs" << std::endl; -
src/ResolvExpr/CandidateFinder.hpp
r1fcc2f3 rd056d0d 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed Jun 5 14:30:00 2019 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Tue Oct 1 9:51:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Wed Jun 5 14:30:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 28 28 struct CandidateFinder { 29 29 CandidateList candidates; ///< List of candidate resolutions 30 const ast::SymbolTable & localSyms; ///< Symbol table to lookup candidates30 const ast::SymbolTable & symtab; ///< Symbol table to lookup candidates 31 31 const ast::TypeEnvironment & env; ///< Substitutions performed in this resolution 32 32 ast::ptr< ast::Type > targetType; ///< Target type for resolution 33 33 34 CandidateFinder( 35 const ast::SymbolTable & sym s, const ast::TypeEnvironment & env,34 CandidateFinder( 35 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 36 36 const ast::Type * tt = nullptr ) 37 : candidates(), localSyms( syms), env( env ), targetType( tt ) {}37 : candidates(), symtab( symtab ), env( env ), targetType( tt ) {} 38 38 39 39 /// Fill candidates with feasible resolutions for `expr` … … 49 49 iterator begin() { return candidates.begin(); } 50 50 const_iterator begin() const { return candidates.begin(); } 51 51 52 52 iterator end() { return candidates.end(); } 53 53 const_iterator end() const { return candidates.end(); } … … 55 55 56 56 /// Computes conversion cost between two types 57 Cost computeConversionCost( 58 const ast::Type * argType, const ast::Type * paramType, bool argIsLvalue,59 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env );57 Cost computeConversionCost( 58 const ast::Type * argType, const ast::Type * paramType, const ast::SymbolTable & symtab, 59 const ast::TypeEnvironment & env ); 60 60 61 61 } // namespace ResolvExpr -
src/ResolvExpr/CastCost.cc
r1fcc2f3 rd056d0d 10 10 // Created On : Sun May 17 06:57:43 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T ue Oct 4 15:00:00 201913 // Update Count : 912 // Last Modified On : Thu Aug 8 16:12:00 2019 13 // Update Count : 8 14 14 // 15 15 … … 142 142 143 143 CastCost_new( 144 const ast::Type * dst, bool srcIsLvalue,const ast::SymbolTable & symtab,144 const ast::Type * dst, const ast::SymbolTable & symtab, 145 145 const ast::TypeEnvironment & env, CostCalculation costFunc ) 146 : ConversionCost_new( dst, s rcIsLvalue, symtab, env, costFunc ) {}146 : ConversionCost_new( dst, symtab, env, costFunc ) {} 147 147 148 148 void postvisit( const ast::BasicType * basicType ) { … … 152 152 cost = Cost::unsafe; 153 153 } else { 154 cost = conversionCost( basicType, dst, s rcIsLvalue, symtab, env );154 cost = conversionCost( basicType, dst, symtab, env ); 155 155 } 156 156 } … … 183 183 } 184 184 }; 185 186 #warning For overload resolution between the two versions.187 int localPtrsCastable(const ast::Type * t1, const ast::Type * t2,188 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) {189 return ptrsCastable( t1, t2, symtab, env );190 }191 Cost localCastCost(192 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,193 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env194 ) { return castCost( src, dst, srcIsLvalue, symtab, env ); }195 185 } // anonymous namespace 196 186 197 198 199 187 Cost castCost( 200 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,201 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env188 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 189 const ast::TypeEnvironment & env 202 190 ) { 203 191 if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { … … 205 193 // check cast cost against bound type, if present 206 194 if ( eqvClass->bound ) { 207 return castCost( src, eqvClass->bound, s rcIsLvalue, symtab, env );195 return castCost( src, eqvClass->bound, symtab, env ); 208 196 } else { 209 197 return Cost::infinity; … … 213 201 auto type = strict_dynamic_cast< const ast::TypeDecl * >( named ); 214 202 if ( type->base ) { 215 return castCost( src, type->base, s rcIsLvalue, symtab, env ) + Cost::safe;203 return castCost( src, type->base, symtab, env ) + Cost::safe; 216 204 } 217 205 } … … 236 224 #warning cast on ptrsCastable artifact of having two functions, remove when port done 237 225 return convertToReferenceCost( 238 src, refType, srcIsLvalue, symtab, env, localPtrsCastable ); 226 src, refType, symtab, env, 227 ( int (*)( 228 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 229 const ast::TypeEnvironment & ) 230 ) ptrsCastable ); 239 231 } else { 240 232 #warning cast on castCost artifact of having two functions, remove when port done 241 ast::Pass< CastCost_new > converter( 242 dst, srcIsLvalue, symtab, env, localCastCost ); 233 ast::Pass< CastCost_new > converter{ 234 dst, symtab, env, 235 ( Cost (*)( 236 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 237 const ast::TypeEnvironment & ) 238 ) castCost }; 243 239 src->accept( converter ); 244 240 return converter.pass.cost; -
src/ResolvExpr/CommonType.cc
r1fcc2f3 rd056d0d 939 939 ast::ptr< ast::Type > result; 940 940 const ast::ReferenceType * ref1 = type1.as< ast::ReferenceType >(); 941 const ast::ReferenceType * ref2 = type 2.as< ast::ReferenceType >();941 const ast::ReferenceType * ref2 = type1.as< ast::ReferenceType >(); 942 942 943 943 if ( depth1 > depth2 ) { -
src/ResolvExpr/ConversionCost.cc
r1fcc2f3 rd056d0d 10 10 // Created On : Sun May 17 07:06:19 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 4 14:45:00 201913 // Update Count : 2 812 // Last Modified On : Mon Aug 12 10:21:00 2019 13 // Update Count : 27 14 14 // 15 15 … … 497 497 } 498 498 499 namespace { 500 # warning For overload resolution between the two versions.501 int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2,502 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 503 return ptrsAssignable( t1, t2, env ); 504 } 505 Cost localConversionCost( 506 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 507 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env508 ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); }509 }499 static int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, 500 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 501 return ptrsAssignable( t1, t2, env ); 502 } 503 504 // TODO: This is used for overload resolution. It might be able to be dropped once the old system 505 // is removed. 506 static Cost localConversionCost( 507 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 508 const ast::TypeEnvironment & env 509 ) { return conversionCost( src, dst, symtab, env ); } 510 510 511 511 Cost conversionCost( 512 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,513 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env512 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 513 const ast::TypeEnvironment & env 514 514 ) { 515 515 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { 516 516 if ( const ast::EqvClass * eqv = env.lookup( inst->name ) ) { 517 517 if ( eqv->bound ) { 518 return conversionCost(src, eqv->bound, s rcIsLvalue, symtab, env );518 return conversionCost(src, eqv->bound, symtab, env ); 519 519 } else { 520 520 return Cost::infinity; … … 524 524 assertf( type, "Unexpected typedef." ); 525 525 if ( type->base ) { 526 return conversionCost( src, type->base, s rcIsLvalue, symtab, env ) + Cost::safe;526 return conversionCost( src, type->base, symtab, env ) + Cost::safe; 527 527 } 528 528 } … … 534 534 } else if ( const ast::ReferenceType * refType = 535 535 dynamic_cast< const ast::ReferenceType * >( dst ) ) { 536 return convertToReferenceCost( src, refType, s rcIsLvalue, symtab, env, localPtrsAssignable );536 return convertToReferenceCost( src, refType, symtab, env, localPtrsAssignable ); 537 537 } else { 538 ast::Pass<ConversionCost_new> converter( dst, s rcIsLvalue, symtab, env, localConversionCost );538 ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost ); 539 539 src->accept( converter ); 540 540 return converter.pass.cost; … … 542 542 } 543 543 544 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,544 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, 545 545 int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 546 PtrsCalculation func ) {546 NumCostCalculation func ) { 547 547 if ( 0 < diff ) { 548 548 Cost cost = convertToReferenceCost( 549 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst,550 srcIsLvalue, (diff - 1), symtab, env, func );549 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, 550 dst, (diff - 1), symtab, env, func ); 551 551 cost.incReference(); 552 552 return cost; … … 554 554 Cost cost = convertToReferenceCost( 555 555 src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base, 556 srcIsLvalue,(diff + 1), symtab, env, func );556 (diff + 1), symtab, env, func ); 557 557 cost.incReference(); 558 558 return cost; … … 579 579 } 580 580 } else { 581 ast::Pass<ConversionCost_new> converter( dst, s rcIsLvalue, symtab, env, localConversionCost );581 ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost ); 582 582 src->accept( converter ); 583 583 return converter.pass.cost; … … 588 588 assert( dstAsRef ); 589 589 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) { 590 if ( src IsLvalue) {590 if ( src->is_lvalue() ) { 591 591 if ( src->qualifiers == dstAsRef->base->qualifiers ) { 592 592 return Cost::reference; … … 607 607 608 608 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst, 609 bool srcIsLvalue,const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,610 PtrsCalculation func ) {609 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 610 NumCostCalculation func ) { 611 611 int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth(); 612 return convertToReferenceCost( src, dst, s rcIsLvalue, sdepth - ddepth, symtab, env, func );612 return convertToReferenceCost( src, dst, sdepth - ddepth, symtab, env, func ); 613 613 } 614 614 … … 667 667 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 668 668 669 cost = costCalc( refType->base, dst, s rcIsLvalue, symtab, env );669 cost = costCalc( refType->base, dst, symtab, env ); 670 670 if ( refType->base->qualifiers == dst->qualifiers ) { 671 671 cost.incReference(); … … 701 701 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) { 702 702 (void)enumInstType; 703 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };704 cost = costCalc( integer, dst, srcIsLvalue, symtab, env );703 static const ast::BasicType integer( ast::BasicType::SignedInt ); 704 cost = costCalc( &integer, dst, symtab, env ); 705 705 if ( cost < Cost::unsafe ) { 706 706 cost.incSafe(); … … 714 714 void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) { 715 715 if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) { 716 cost = costCalc( eqv->bound, dst, s rcIsLvalue, symtab, env );716 cost = costCalc( eqv->bound, dst, symtab, env ); 717 717 } else if ( const ast::TypeInstType * dstAsInst = 718 718 dynamic_cast< const ast::TypeInstType * >( dst ) ) { … … 724 724 assertf( type, "Unexpected typedef."); 725 725 if ( type->base ) { 726 cost = costCalc( type->base, dst, s rcIsLvalue, symtab, env ) + Cost::safe;726 cost = costCalc( type->base, dst, symtab, env ) + Cost::safe; 727 727 } 728 728 } … … 737 737 auto dstEnd = dstAsTuple->types.end(); 738 738 while ( srcIt != srcEnd && dstIt != dstEnd ) { 739 Cost newCost = costCalc( * srcIt++, * dstIt++, s rcIsLvalue, symtab, env );739 Cost newCost = costCalc( * srcIt++, * dstIt++, symtab, env ); 740 740 if ( newCost == Cost::infinity ) { 741 741 return; … … 772 772 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 773 773 } 774 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) {775 cost = Cost::zero;776 // +1 for zero_t ->, +1 for disambiguation777 cost.incSafe( maxIntCost + 2 );778 774 } 779 775 } … … 793 789 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 794 790 } 791 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 792 cost = Cost::zero; 793 cost.incSafe( maxIntCost + 2 ); 795 794 } 796 795 } -
src/ResolvExpr/ConversionCost.h
r1fcc2f3 rd056d0d 10 10 // Created On : Sun May 17 09:37:28 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T ue Oct 4 14:59:00 201913 // Update Count : 712 // Last Modified On : Thu Aug 8 16:13:00 2019 13 // Update Count : 6 14 14 // 15 15 … … 74 74 75 75 // Some function pointer types, differ in return type. 76 using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *, bool,76 using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *, 77 77 const ast::SymbolTable &, const ast::TypeEnvironment &)>; 78 using PtrsCalculation = std::function<int(const ast::Type *, const ast::Type *,78 using NumCostCalculation = std::function<int(const ast::Type *, const ast::Type *, 79 79 const ast::SymbolTable &, const ast::TypeEnvironment &)>; 80 80 … … 83 83 protected: 84 84 const ast::Type * dst; 85 bool srcIsLvalue;86 85 const ast::SymbolTable & symtab; 87 86 const ast::TypeEnvironment & env; … … 90 89 Cost cost; 91 90 92 ConversionCost_new( const ast::Type * dst, bool srcIsLvalue,const ast::SymbolTable & symtab,91 ConversionCost_new( const ast::Type * dst, const ast::SymbolTable & symtab, 93 92 const ast::TypeEnvironment & env, CostCalculation costCalc ) : 94 dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ), 95 costCalc( costCalc ), cost( Cost::infinity ) 93 dst( dst ), symtab( symtab ), env( env ), costCalc( costCalc ), cost( Cost::infinity ) 96 94 {} 97 95 … … 116 114 117 115 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest, 118 bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env, 119 PtrsCalculation func ); 116 const ast::SymbolTable & indexer, const ast::TypeEnvironment & env, NumCostCalculation func ); 120 117 121 118 } // namespace ResolvExpr -
src/ResolvExpr/CurrentObject.cc
r1fcc2f3 rd056d0d 21 21 #include <string> // for string, operator<<, allocator 22 22 23 #include "AST/Copy.hpp" // for shallowCopy24 23 #include "AST/Expr.hpp" // for InitAlternative 25 24 #include "AST/GenericSubstitution.hpp" // for genericSubstitution 26 25 #include "AST/Init.hpp" // for Designation 27 26 #include "AST/Node.hpp" // for readonly 28 #include "AST/Print.hpp" // for readonly29 27 #include "AST/Type.hpp" 30 28 #include "Common/Indenter.h" // for Indenter, operator<< … … 598 596 SimpleIterator( const CodeLocation & loc, const Type * t ) : location( loc ), type( t ) {} 599 597 600 void setPosition( 601 std::deque< ptr< Expr > >::const_iterator begin, 598 void setPosition( 599 std::deque< ptr< Expr > >::const_iterator begin, 602 600 std::deque< ptr< Expr > >::const_iterator end 603 601 ) override { … … 639 637 auto res = eval(expr); 640 638 if ( ! res.second ) { 641 SemanticError( location, 639 SemanticError( location, 642 640 toString("Array designator must be a constant expression: ", expr ) ); 643 641 } … … 646 644 647 645 public: 648 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 646 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 649 647 : location( loc ), array( at ), base( at->base ) { 650 648 PRINT( std::cerr << "Creating array iterator: " << at << std::endl; ) … … 657 655 658 656 void setPosition( const Expr * expr ) { 659 // need to permit integer-constant-expressions, including: integer constants, 660 // enumeration constants, character constants, sizeof expressions, alignof expressions, 657 // need to permit integer-constant-expressions, including: integer constants, 658 // enumeration constants, character constants, sizeof expressions, alignof expressions, 661 659 // cast expressions 662 660 if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) { … … 664 662 index = constExpr->intValue(); 665 663 } catch ( SemanticErrorException & ) { 666 SemanticError( expr, 664 SemanticError( expr, 667 665 "Constant expression of non-integral type in array designator: " ); 668 666 } 669 667 } else if ( auto castExpr = dynamic_cast< const CastExpr * >( expr ) ) { 670 668 setPosition( castExpr->arg ); 671 } else if ( 672 dynamic_cast< const SizeofExpr * >( expr ) 673 || dynamic_cast< const AlignofExpr * >( expr ) 669 } else if ( 670 dynamic_cast< const SizeofExpr * >( expr ) 671 || dynamic_cast< const AlignofExpr * >( expr ) 674 672 ) { 675 673 index = 0; 676 674 } else { 677 assertf( false, 675 assertf( false, 678 676 "bad designator given to ArrayIterator: %s", toString( expr ).c_str() ); 679 677 } 680 678 } 681 679 682 void setPosition( 683 std::deque< ptr< Expr > >::const_iterator begin, 680 void setPosition( 681 std::deque< ptr< Expr > >::const_iterator begin, 684 682 std::deque< ptr< Expr > >::const_iterator end 685 683 ) override { … … 760 758 } 761 759 762 AggregateIterator( 763 const CodeLocation & loc, const std::string k, const std::string & n, const Type * i, 760 AggregateIterator( 761 const CodeLocation & loc, const std::string k, const std::string & n, const Type * i, 764 762 const MemberList & ms ) 765 : location( loc ), kind( k ), name( n ), inst( i ), members( ms ), curMember( ms.begin() ), 763 : location( loc ), kind( k ), name( n ), inst( i ), members( ms ), curMember( ms.begin() ), 766 764 sub( genericSubstitution( i ) ) { 767 765 PRINT( std::cerr << "Creating " << kind << "(" << name << ")"; ) … … 770 768 771 769 public: 772 void setPosition( 773 std::deque< ptr< Expr > >::const_iterator begin, 770 void setPosition( 771 std::deque< ptr< Expr > >::const_iterator begin, 774 772 std::deque< ptr< Expr > >::const_iterator end 775 773 ) final { … … 788 786 return; 789 787 } 790 assertf( false, 788 assertf( false, 791 789 "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 792 790 } else { 793 assertf( false, 791 assertf( false, 794 792 "bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 795 793 } … … 805 803 new VariableExpr{ location, curMember->strict_as< ObjectDecl >() } ); 806 804 // need to substitute for generic types so that casts are to concrete types 807 alt.type = shallowCopy(alt.type.get());808 805 PRINT( std::cerr << " type is: " << alt.type; ) 809 806 sub.apply( alt.type ); // also apply to designation?? … … 845 842 for ( InitAlternative & alt : ret ) { 846 843 PRINT( std::cerr << "iterating and adding designators" << std::endl; ) 847 alt.designation.get_and_mutate()->designators.emplace_front( 844 alt.designation.get_and_mutate()->designators.emplace_front( 848 845 new VariableExpr{ location, curMember->strict_as< ObjectDecl >() } ); 849 846 } … … 900 897 class TupleIterator final : public AggregateIterator { 901 898 public: 902 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 903 : AggregateIterator( 904 loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members 899 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 900 : AggregateIterator( 901 loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members 905 902 ) {} 906 903 … … 929 926 return new UnionIterator{ loc, uit }; 930 927 } else { 931 assertf( 932 dynamic_cast< const EnumInstType * >( type )933 || dynamic_cast< const TypeInstType * >( type ),928 assertf( 929 dynamic_cast< const EnumInstType * >( aggr ) 930 || dynamic_cast< const TypeInstType * >( aggr ), 934 931 "Encountered unhandled ReferenceToType in createMemberIterator: %s", 935 932 toString( type ).c_str() ); … … 952 949 using DesignatorChain = std::deque< ptr< Expr > >; 953 950 PRINT( std::cerr << "___findNext" << std::endl; ) 954 951 955 952 // find all the d's 956 953 std::vector< DesignatorChain > desigAlts{ {} }, newDesigAlts; … … 1016 1013 // set new designators 1017 1014 assertf( ! objStack.empty(), "empty object stack when setting designation" ); 1018 Designation * actualDesignation = 1015 Designation * actualDesignation = 1019 1016 new Designation{ designation->location, DesignatorChain{d} }; 1020 1017 objStack.back()->setPosition( d ); // destroys d -
src/ResolvExpr/PolyCost.cc
r1fcc2f3 rd056d0d 58 58 59 59 // TODO: When the old PolyCost is torn out get rid of the _new suffix. 60 class PolyCost_new { 60 struct PolyCost_new { 61 int result; 61 62 const ast::SymbolTable &symtab; 62 public:63 int result;64 63 const ast::TypeEnvironment &env_; 65 64 66 PolyCost_new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 67 : symtab( symtab ), result( 0), env_( env ) {}65 PolyCost_new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) : 66 result( 0 ), symtab( symtab ), env_( env ) {} 68 67 69 68 void previsit( const ast::TypeInstType * type ) { -
src/ResolvExpr/RenameVars.cc
r1fcc2f3 rd056d0d 19 19 #include <utility> // for pair 20 20 21 #include "AST/ForallSubstitutionTable.hpp"22 21 #include "AST/Pass.hpp" 23 22 #include "AST/Type.hpp" … … 31 30 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 32 31 33 #include "AST/Copy.hpp"34 35 32 namespace ResolvExpr { 36 33 … … 40 37 int resetCount = 0; 41 38 ScopedMap< std::string, std::string > nameMap; 39 42 40 public: 43 ast::ForallSubstitutionTable subs;44 45 41 void reset() { 46 42 level = 0; … … 48 44 } 49 45 46 using mapConstIterator = ScopedMap< std::string, std::string >::const_iterator; 47 50 48 void rename( TypeInstType * type ) { 51 autoit = nameMap.find( type->name );49 mapConstIterator it = nameMap.find( type->name ); 52 50 if ( it != nameMap.end() ) { 53 51 type->name = it->second; … … 67 65 // ditto for assertion names, the next level in 68 66 level++; 69 } 70 } 67 // acceptAll( td->assertions, *this ); 68 } // for 69 } // if 71 70 } 72 71 … … 78 77 79 78 const ast::TypeInstType * rename( const ast::TypeInstType * type ) { 80 // re-linking of base type handled by WithForallSubstitutor 81 82 // rename 83 auto it = nameMap.find( type->name ); 79 mapConstIterator it = nameMap.find( type->name ); 84 80 if ( it != nameMap.end() ) { 85 // unconditionally mutate because map will *always* have different name, 86 // if this mutates, will *always* have been mutated by ForallSubstitutor above 87 ast::TypeInstType * mut = ast::mutate( type ); 88 mut->name = it->second; 89 type = mut; 81 ast::TypeInstType * mutType = ast::mutate( type ); 82 mutType->name = it->second; 83 type = mutType; 90 84 } 91 92 85 return type; 93 86 } … … 95 88 template<typename NodeT> 96 89 const NodeT * openLevel( const NodeT * type ) { 97 if ( type->forall.empty() ) return type; 90 if ( !type->forall.empty() ) { 91 nameMap.beginScope(); 92 // Load new names from this forall clause and perform renaming. 93 NodeT * mutType = ast::mutate( type ); 94 for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) { 95 std::ostringstream output; 96 output << "_" << resetCount << "_" << level << "_" << td->name; 97 std::string newname( output.str() ); 98 nameMap[ td->name ] = newname; 99 ++level; 98 100 99 nameMap.beginScope(); 100 101 // Load new names from this forall clause and perform renaming. 102 NodeT * mutType = ast::mutate( type ); 103 assert( type == mutType && "mutated type must be unique from ForallSubstitutor" ); 104 for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) { 105 std::ostringstream output; 106 output << "_" << resetCount << "_" << level << "_" << td->name; 107 std::string newname = output.str(); 108 nameMap[ td->name ] = newname; 109 ++level; 110 111 ast::TypeDecl * mutDecl = ast::mutate( td.get() ); 112 assert( td == mutDecl && "mutated decl must be unique from ForallSubstitutor" ); 113 mutDecl->name = newname; 114 // assertion above means `td = mutDecl;` is unnecessary 101 ast::TypeDecl * decl = ast::mutate( td.get() ); 102 decl->name = newname; 103 td = decl; 104 } 115 105 } 116 // assertion above means `type = mutType;` is unnecessary117 118 106 return type; 119 107 } 120 108 121 void closeLevel( const ast::ParameterizedType * type ) { 122 if ( type->forall.empty() ) return; 123 124 nameMap.endScope(); 109 template<typename NodeT> 110 const NodeT * closeLevel( const NodeT * type ) { 111 if ( !type->forall.empty() ) { 112 nameMap.endScope(); 113 } 114 return type; 125 115 } 126 116 }; … … 129 119 RenamingData renaming; 130 120 131 struct RenameVars _old{121 struct RenameVars { 132 122 void previsit( TypeInstType * instType ) { 133 123 renaming.openLevel( (Type*)instType ); … … 140 130 renaming.closeLevel( type ); 141 131 } 142 };143 144 struct RenameVars_new /*: public ast::WithForallSubstitutor*/ {145 #warning when old RenameVars goes away, replace hack below with global pass inheriting from WithForallSubstitutor146 ast::ForallSubstitutionTable & subs = renaming.subs;147 132 148 133 const ast::FunctionType * previsit( const ast::FunctionType * type ) { … … 161 146 return renaming.rename( renaming.openLevel( type ) ); 162 147 } 163 voidpostvisit( const ast::ParameterizedType * type ) {164 re naming.closeLevel( type );148 const ast::ParameterizedType * postvisit( const ast::ParameterizedType * type ) { 149 return renaming.closeLevel( type ); 165 150 } 166 151 }; … … 169 154 170 155 void renameTyVars( Type * t ) { 171 PassVisitor<RenameVars _old> renamer;156 PassVisitor<RenameVars> renamer; 172 157 t->accept( renamer ); 173 158 } 174 159 175 160 const ast::Type * renameTyVars( const ast::Type * t ) { 176 ast::Type *tc = ast::deepCopy(t); 177 ast::Pass<RenameVars_new> renamer; 178 // return t->accept( renamer ); 179 return tc->accept( renamer ); 161 ast::Pass<RenameVars> renamer; 162 return t->accept( renamer ); 180 163 } 181 164 -
src/ResolvExpr/ResolveTypeof.cc
r1fcc2f3 rd056d0d 99 99 // replace basetypeof(<enum>) by int 100 100 if ( dynamic_cast<EnumInstType*>(newType) ) { 101 Type* newerType = 102 new BasicType{ newType->get_qualifiers(), BasicType::SignedInt, 101 Type* newerType = 102 new BasicType{ newType->get_qualifiers(), BasicType::SignedInt, 103 103 newType->attributes }; 104 104 delete newType; 105 105 newType = newerType; 106 106 } 107 newType->get_qualifiers().val 107 newType->get_qualifiers().val 108 108 = ( newType->get_qualifiers().val & ~Type::Qualifiers::Mask ) | oldQuals; 109 109 } else { 110 110 newType->get_qualifiers().val |= oldQuals; 111 111 } 112 112 113 113 return newType; 114 114 } … … 120 120 ResolveTypeof_new( const ast::SymbolTable & syms ) : localSymtab( syms ) {} 121 121 122 void pre visit( const ast::TypeofType * ) { visit_children = false; }122 void premutate( const ast::TypeofType * ) { visit_children = false; } 123 123 124 const ast::Type * post visit( const ast::TypeofType * typeofType ) {124 const ast::Type * postmutate( const ast::TypeofType * typeofType ) { 125 125 // pass on null expression 126 126 if ( ! typeofType->expr ) return typeofType; … … 133 133 // typeof wrapping expression 134 134 ast::TypeEnvironment dummy; 135 ast::ptr< ast::Expr > newExpr = 135 ast::ptr< ast::Expr > newExpr = 136 136 resolveInVoidContext( typeofType->expr, localSymtab, dummy ); 137 137 assert( newExpr->result && ! newExpr->result->isVoid() ); … … 143 143 // replace basetypeof(<enum>) by int 144 144 if ( newType.as< ast::EnumInstType >() ) { 145 newType = new ast::BasicType{ 145 newType = new ast::BasicType{ 146 146 ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) }; 147 147 } 148 reset_qualifiers( 149 newType, 148 reset_qualifiers( 149 newType, 150 150 ( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers ); 151 151 } else { … … 153 153 } 154 154 155 return newType .release();155 return newType; 156 156 } 157 157 }; -
src/ResolvExpr/Resolver.cc
r1fcc2f3 rd056d0d 1054 1054 const ast::Expr * postmutate( const ast::CastExpr * castExpr ) { 1055 1055 if ( 1056 castExpr->isGenerated == ast::GeneratedCast1056 castExpr->isGenerated 1057 1057 && typesCompatible( castExpr->arg->result, castExpr->result ) 1058 1058 ) { … … 1108 1108 1109 1109 // set up and resolve expression cast to void 1110 ast:: ptr< ast::CastExpr >untyped = new ast::CastExpr{ expr };1110 ast::CastExpr * untyped = new ast::CastExpr{ expr }; 1111 1111 CandidateRef choice = findUnfinishedKindExpression( 1112 1112 untyped, symtab, "", anyCandidate, ResolvMode::withAdjustment() ); … … 1247 1247 }; 1248 1248 1249 void resolve( std::list< ast::ptr< ast::Decl> >& translationUnit ) {1249 void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit ) { 1250 1250 ast::Pass< Resolver_new > resolver; 1251 1251 accept_all( translationUnit, resolver ); … … 1281 1281 ast::ptr< ast::FunctionDecl > ret = functionDecl; 1282 1282 for ( unsigned i = 0; i < functionDecl->type->params.size(); ++i ) { 1283 const ast::ptr< ast::DeclWithType> & d = functionDecl->type->params[i];1283 const ast::ptr<ast::DeclWithType> & d = functionDecl->type->params[i]; 1284 1284 1285 1285 if ( const ast::ObjectDecl * obj = d.as< ast::ObjectDecl >() ) { … … 1298 1298 } 1299 1299 } 1300 return ret. release();1300 return ret.get(); 1301 1301 } 1302 1302 … … 1321 1321 // in case we decide to allow nested enums 1322 1322 GuardValue( inEnumDecl ); 1323 inEnumDecl = true;1323 inEnumDecl = false; 1324 1324 } 1325 1325 -
src/ResolvExpr/SatisfyAssertions.cpp
r1fcc2f3 rd056d0d 9 9 // Author : Aaron B. Moss 10 10 // Created On : Mon Jun 10 17:45:00 2019 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Tue Oct 1 13:56:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 10 17:45:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 299 299 Cost cost; 300 300 301 OutType( 302 const ast::TypeEnvironment & e, const ast::OpenVarSet & o, 301 OutType( 302 const ast::TypeEnvironment & e, const ast::OpenVarSet & o, 303 303 const std::vector< DeferRef > & as, const ast::SymbolTable & symtab ) 304 304 : env( e ), open( o ), assns( as ), cost( Cost::zero ) { … … 306 306 for ( const DeferRef & assn : assns ) { 307 307 // compute conversion cost from satisfying decl to assertion 308 cost += computeConversionCost( 309 assn.match.adjType, assn.decl->get_type(), false,symtab, env );310 308 cost += computeConversionCost( 309 assn.match.adjType, assn.decl->get_type(), symtab, env ); 310 311 311 // mark vars+specialization on function-type assertions 312 const ast::FunctionType * func = 312 const ast::FunctionType * func = 313 313 GenPoly::getFunctionType( assn.match.cdata.id->get_type() ); 314 314 if ( ! func ) continue; … … 317 317 cost.decSpec( specCost( param->get_type() ) ); 318 318 } 319 319 320 320 cost.incVar( func->forall.size() ); 321 321 322 322 for ( const ast::TypeDecl * td : func->forall ) { 323 323 cost.decSpec( td->assertions.size() ); … … 329 329 }; 330 330 331 CandidateEnvMerger( 332 const ast::TypeEnvironment & env, const ast::OpenVarSet & open, 331 CandidateEnvMerger( 332 const ast::TypeEnvironment & env, const ast::OpenVarSet & open, 333 333 const ast::SymbolTable & syms ) 334 334 : crnt(), envs{ env }, opens{ open }, symtab( syms ) {} -
src/ResolvExpr/SatisfyAssertions.hpp
r1fcc2f3 rd056d0d 28 28 29 29 /// Recursively satisfies all assertions provided in a candidate; returns true if succeeds 30 void satisfyAssertions( 31 CandidateRef & cand, const ast::SymbolTable & symtab, CandidateList & out, 30 void satisfyAssertions( 31 CandidateRef & cand, const ast::SymbolTable & symtab, CandidateList & out, 32 32 std::vector<std::string> & errors ); 33 33 -
src/ResolvExpr/SpecCost.cc
r1fcc2f3 rd056d0d 10 10 // Created On : Tue Oct 02 15:50:00 2018 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 3 11:07:00 2019 13 // Update Count : 3 14 // 15 16 #include <cassert> 12 // Last Modified On : Wed Jun 19 10:43:00 2019 13 // Update Count : 2 14 // 15 17 16 #include <limits> 18 17 #include <list> … … 130 129 typename std::add_pointer<ast::Type const *(typename T::value_type const &)>::type; 131 130 132 #warning Should use a standard maybe_accept133 void maybe_accept( ast::Type const * type ) {134 if ( type ) {135 auto node = type->accept( *visitor );136 assert( node == nullptr || node == type );137 }138 }139 140 131 // Update the minimum to the new lowest non-none value. 141 132 template<typename T> … … 143 134 for ( const auto & node : list ) { 144 135 count = -1; 145 ma ybe_accept( mapper( node ));136 mapper( node )->accept( *visitor ); 146 137 if ( count != -1 && count < minimum ) minimum = count; 147 138 } -
src/ResolvExpr/Unify.cc
r1fcc2f3 rd056d0d 25 25 #include <vector> 26 26 27 #include "AST/Copy.hpp"28 27 #include "AST/Decl.hpp" 29 28 #include "AST/Node.hpp" 30 29 #include "AST/Pass.hpp" 31 #include "AST/Print.hpp"32 30 #include "AST/Type.hpp" 33 31 #include "AST/TypeEnvironment.hpp" … … 137 135 findOpenVars( newSecond, open, closed, need, have, FirstOpen ); 138 136 139 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 137 return unifyExact( 138 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 140 139 } 141 140 … … 149 148 newFirst->get_qualifiers() = Type::Qualifiers(); 150 149 newSecond->get_qualifiers() = Type::Qualifiers(); 151 150 /// std::cerr << "first is "; 151 /// first->print( std::cerr ); 152 /// std::cerr << std::endl << "second is "; 153 /// second->print( std::cerr ); 154 /// std::cerr << std::endl << "newFirst is "; 155 /// newFirst->print( std::cerr ); 156 /// std::cerr << std::endl << "newSecond is "; 157 /// newSecond->print( std::cerr ); 158 /// std::cerr << std::endl; 152 159 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 153 160 delete newFirst; … … 163 170 ast::AssertionSet need, have; 164 171 165 ast::Type * newFirst = shallowCopy( first ); 166 ast::Type * newSecond = shallowCopy( second ); 167 newFirst ->qualifiers = {}; 168 newSecond->qualifiers = {}; 169 ast::ptr< ast::Type > t1_(newFirst ); 170 ast::ptr< ast::Type > t2_(newSecond); 172 ast::ptr<ast::Type> newFirst{ first }, newSecond{ second }; 173 env.apply( newFirst ); 174 env.apply( newSecond ); 175 reset_qualifiers( newFirst ); 176 reset_qualifiers( newSecond ); 171 177 172 178 return unifyExact( 173 env.apply( newFirst ).node, 174 env.apply( newSecond ).node, 175 newEnv, need, have, open, noWiden(), symtab ); 179 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 176 180 } 177 181 … … 322 326 323 327 void markAssertionSet( AssertionSet &assertions, DeclarationWithType *assert ) { 328 /// std::cerr << "assertion set is" << std::endl; 329 /// printAssertionSet( assertions, std::cerr, 8 ); 330 /// std::cerr << "looking for "; 331 /// assert->print( std::cerr ); 332 /// std::cerr << std::endl; 324 333 AssertionSet::iterator i = assertions.find( assert ); 325 334 if ( i != assertions.end() ) { 335 /// std::cerr << "found it!" << std::endl; 326 336 i->second.isUsed = true; 327 337 } // if … … 933 943 934 944 private: 935 // Returns: other, cast as XInstType 936 // Assigns this->result: whether types are compatible (up to generic parameters) 937 template< typename XInstType > 938 const XInstType * handleRefType( const XInstType * inst, const ast::Type * other ) { 945 template< typename RefType > 946 const RefType * handleRefType( const RefType * inst, const ast::Type * other ) { 939 947 // check that the other type is compatible and named the same 940 auto otherInst = dynamic_cast< const XInstType * >( other );941 this->result = otherInst && inst->name == otherInst->name;948 auto otherInst = dynamic_cast< const RefType * >( other ); 949 result = otherInst && inst->name == otherInst->name; 942 950 return otherInst; 943 951 } … … 960 968 } 961 969 962 template< typename XInstType >963 void handleGenericRefType( const XInstType * inst, const ast::Type * other ) {970 template< typename RefType > 971 void handleGenericRefType( const RefType * inst, const ast::Type * other ) { 964 972 // check that other type is compatible and named the same 965 const XInstType * otherInst= handleRefType( inst, other );966 if ( ! this->result) return;973 const RefType * inst2 = handleRefType( inst, other ); 974 if ( ! inst2 ) return; 967 975 968 976 // check that parameters of types unify, if any 969 977 const std::vector< ast::ptr< ast::Expr > > & params = inst->params; 970 const std::vector< ast::ptr< ast::Expr > > & params2 = otherInst->params;978 const std::vector< ast::ptr< ast::Expr > > & params2 = inst2->params; 971 979 972 980 auto it = params.begin(); … … 1194 1202 // force t1 and t2 to be cloned if their qualifiers must be stripped, so that type1 and 1195 1203 // type2 are left unchanged; calling convention forces type{1,2}->strong_ref >= 1 1196 ast::Type * t1 = shallowCopy(type1.get()); 1197 ast::Type * t2 = shallowCopy(type2.get()); 1198 t1->qualifiers = {}; 1199 t2->qualifiers = {}; 1200 ast::ptr< ast::Type > t1_(t1); 1201 ast::ptr< ast::Type > t2_(t2); 1204 ast::ptr<ast::Type> t1{ type1 }, t2{ type2 }; 1205 reset_qualifiers( t1 ); 1206 reset_qualifiers( t2 ); 1202 1207 1203 1208 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) { 1209 t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones 1210 1204 1211 // if exact unification on unqualified types, try to merge qualifiers 1205 1212 if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) { 1206 t1->qualifiers = q1 | q2;1207 common = t1;1213 common = type1; 1214 reset_qualifiers( common, q1 | q2 ); 1208 1215 return true; 1209 1216 } else { … … 1212 1219 1213 1220 } else if (( common = commonType( t1, t2, widen, symtab, env, open ) )) { 1221 t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones 1222 1214 1223 // no exact unification, but common type 1215 auto c = shallowCopy(common.get()); 1216 c->qualifiers = q1 | q2; 1217 common = c; 1224 reset_qualifiers( common, q1 | q2 ); 1218 1225 return true; 1219 1226 } else { -
src/ResolvExpr/typeops.h
r1fcc2f3 rd056d0d 10 10 // Created On : Sun May 17 07:28:22 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T ue Oct 1 09:45:00 201913 // Update Count : 612 // Last Modified On : Thu Aug 8 16:36:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 83 83 const SymTab::Indexer & indexer, const TypeEnvironment & env ); 84 84 Cost castCost( 85 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,86 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env );85 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 86 const ast::TypeEnvironment & env ); 87 87 88 88 // in ConversionCost.cc … … 90 90 const SymTab::Indexer & indexer, const TypeEnvironment & env ); 91 91 Cost conversionCost( 92 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,93 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env );92 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 93 const ast::TypeEnvironment & env ); 94 94 95 95 // in AlternativeFinder.cc -
src/SymTab/Autogen.h
r1fcc2f3 rd056d0d 21 21 22 22 #include "AST/Decl.hpp" 23 #include "AST/Eval.hpp"24 23 #include "AST/Expr.hpp" 25 24 #include "AST/Init.hpp" … … 265 264 } 266 265 267 ast::ptr< ast::Expr > begin, end; 268 std::string cmp, update; 266 ast::ptr< ast::Expr > begin, end, cmp, update; 269 267 270 268 if ( forward ) { … … 272 270 begin = ast::ConstantExpr::from_int( loc, 0 ); 273 271 end = array->dimension; 274 cmp = "?<?";275 update = "++?";272 cmp = new ast::NameExpr{ loc, "?<?" }; 273 update = new ast::NameExpr{ loc, "++?" }; 276 274 } else { 277 275 // generate: for ( int i = N-1; i >= 0; --i ) 278 begin = ast::call( 279 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ) ); 276 begin = new ast::UntypedExpr{ 277 loc, new ast::NameExpr{ loc, "?-?" }, 278 { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } }; 280 279 end = ast::ConstantExpr::from_int( loc, 0 ); 281 cmp = "?>=?";282 update = "--?";280 cmp = new ast::NameExpr{ loc, "?>=?" }; 281 update = new ast::NameExpr{ loc, "--?" }; 283 282 } 284 283 … … 286 285 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 287 286 new ast::SingleInit{ loc, begin } }; 288 ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index }; 289 290 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end ); 291 292 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar ); 293 294 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar ); 287 288 ast::ptr< ast::Expr > cond = new ast::UntypedExpr{ 289 loc, cmp, { new ast::VariableExpr{ loc, index }, end } }; 290 291 ast::ptr< ast::Expr > inc = new ast::UntypedExpr{ 292 loc, update, { new ast::VariableExpr{ loc, index } } }; 293 294 ast::ptr< ast::Expr > dstIndex = new ast::UntypedExpr{ 295 loc, new ast::NameExpr{ loc, "?[?]" }, 296 { dstParam, new ast::VariableExpr{ loc, index } } }; 295 297 296 298 // srcParam must keep track of the array indices to build the source parameter and/or 297 299 // array list initializer 298 srcParam.addArrayIndex( indexVar, array->dimension );300 srcParam.addArrayIndex( new ast::VariableExpr{ loc, index }, array->dimension ); 299 301 300 302 // for stmt's body, eventually containing call … … 382 384 if ( isUnnamedBitfield( obj ) ) return {}; 383 385 384 ast::ptr< ast::Type > addCast ;386 ast::ptr< ast::Type > addCast = nullptr; 385 387 if ( (fname == "?{}" || fname == "^?{}") && ( ! obj || ( obj && ! obj->bitfieldWidth ) ) ) { 386 388 assert( dstParam->result ); -
src/SynTree/Statement.h
r1fcc2f3 rd056d0d 502 502 class ImplicitCtorDtorStmt : public Statement { 503 503 public: 504 // the constructor/destructor call statement; owned here for a while, eventually transferred elsewhere504 // Non-owned pointer to the constructor/destructor statement 505 505 Statement * callStmt; 506 506 -
src/Tuples/Explode.cc
r1fcc2f3 rd056d0d 129 129 for ( const ast::Expr * expr : tupleExpr->exprs ) { 130 130 exprs.emplace_back( applyCast( expr, false ) ); 131 //exprs.emplace_back( ast::ptr< ast::Expr >( applyCast( expr, false ) ) ); 131 132 } 132 133 if ( first ) { -
src/Tuples/Explode.h
r1fcc2f3 rd056d0d 210 210 } 211 211 // Cast a reference away to a value-type to allow further explosion. 212 if ( local->result.as< ast::ReferenceType >() ) {212 if ( dynamic_cast< const ast::ReferenceType *>( local->result.get() ) ) { 213 213 local = new ast::CastExpr{ local, tupleType }; 214 214 } … … 220 220 // delete idx; 221 221 } 222 // delete local; 222 223 } 223 224 } else { -
src/Tuples/TupleAssignment.cc
r1fcc2f3 rd056d0d 465 465 // resolve ctor/dtor for the new object 466 466 ast::ptr< ast::Init > ctorInit = ResolvExpr::resolveCtorInit( 467 InitTweak::genCtorInit( location, ret ), spotter.crntFinder. localSyms);467 InitTweak::genCtorInit( location, ret ), spotter.crntFinder.symtab ); 468 468 // remove environments from subexpressions of stmtExpr 469 469 ast::Pass< EnvRemover > rm{ env }; … … 560 560 // resolve the cast expression so that rhsCand return type is bound by the cast 561 561 // type as needed, and transfer the resulting environment 562 ResolvExpr::CandidateFinder finder{ spotter.crntFinder. localSyms, env };562 ResolvExpr::CandidateFinder finder{ spotter.crntFinder.symtab, env }; 563 563 finder.find( rhsCand->expr, ResolvExpr::ResolvMode::withAdjustment() ); 564 564 assert( finder.candidates.size() == 1 ); … … 609 609 // explode the LHS so that each field of a tuple-valued expr is assigned 610 610 ResolvExpr::CandidateList lhs; 611 explode( *lhsCand, crntFinder. localSyms, back_inserter(lhs), true );611 explode( *lhsCand, crntFinder.symtab, back_inserter(lhs), true ); 612 612 for ( ResolvExpr::CandidateRef & cand : lhs ) { 613 613 // each LHS value must be a reference - some come in with a cast, if not … … 629 629 if ( isTuple( rhsCand->expr ) ) { 630 630 // multiple assignment 631 explode( *rhsCand, crntFinder. localSyms, back_inserter(rhs), true );631 explode( *rhsCand, crntFinder.symtab, back_inserter(rhs), true ); 632 632 matcher.reset( 633 633 new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } ); … … 648 648 // multiple assignment 649 649 ResolvExpr::CandidateList rhs; 650 explode( rhsCand, crntFinder. localSyms, back_inserter(rhs), true );650 explode( rhsCand, crntFinder.symtab, back_inserter(rhs), true ); 651 651 matcher.reset( 652 652 new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } ); … … 678 678 ) 679 679 680 ResolvExpr::CandidateFinder finder{ crntFinder. localSyms, matcher->env };680 ResolvExpr::CandidateFinder finder{ crntFinder.symtab, matcher->env }; 681 681 682 682 try { -
src/Tuples/TupleExpansion.cc
r1fcc2f3 rd056d0d 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 4 15:38:00 201913 // Update Count : 2 312 // Last Modified On : Fri Jul 19 14:39:00 2019 13 // Update Count : 22 14 14 // 15 15 … … 323 323 std::vector<ast::ptr<ast::Type>> types; 324 324 ast::CV::Qualifiers quals{ 325 ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | 325 ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue | 326 326 ast::CV::Atomic | ast::CV::Mutex }; 327 327 -
src/main.cc
r1fcc2f3 rd056d0d 29 29 #include <string> // for char_traits, operator<< 30 30 31 #include "AST/Convert.hpp"32 31 #include "CompilationState.h" 33 32 #include "../config.h" // for CFA_LIBDIR … … 304 303 } // if 305 304 306 // PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 307 { 308 auto transUnit = convert( move( translationUnit ) ); 309 PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); 310 translationUnit = convert( move( transUnit ) ); 311 } 312 305 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 313 306 if ( exprp ) { 314 307 dump( translationUnit );
Note:
See TracChangeset
for help on using the changeset viewer.