Changes in / [893e106:ef5ef56]
- Location:
- src
- Files:
-
- 2 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r893e106 ref5ef56 20 20 #include <vector> 21 21 22 #include "GenericSubstitution.hpp"23 22 #include "Stmt.hpp" 24 23 #include "Type.hpp" 25 #include "TypeSubstitution.hpp"26 24 #include "Common/utility.h" 27 25 #include "Common/SemanticError.h" … … 159 157 assert( aggregate->result ); 160 158 161 <<<<<<< HEAD162 // #warning Needs GenericSubsitution.cpp building to work correctly163 // result.set_and_mutate( mem->get_type() )->qualifiers |= aggregate->result->qualifiers | CV::Lvalue; // FIXME temporary patch164 165 // take ownership of member type166 result = mem->get_type();167 // substitute aggregate generic parameters into member type168 genericSubsitution( aggregate->result ).apply( result );169 // ensure lvalue and appropriate restrictions from aggregate type170 result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;171 =======172 159 // assert(!"unimplemented; need TypeSubstitution, genericSubstitution"); 173 >>>>>>> ef5ef56042ce2b547da955746d9986e26cf628ca174 160 } 175 161 -
src/AST/Node.cpp
r893e106 ref5ef56 35 35 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); } 36 36 37 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere. 38 /// Returns a mutable version of the pointer in this node. 37 39 template< typename node_t, enum ast::Node::ref_type ref_t > 38 node_t * ast::ptr_base<node_t, ref_t>::get_and_mutate() { 40 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) { 41 // ensure ownership of `n` by this node to avoid spurious single-owner mutates 42 assign( n ); 39 43 // get mutable version of `n` 40 44 auto r = mutate( node ); … … 42 46 assign( r ); 43 47 return r; 44 }45 46 template< typename node_t, enum ast::Node::ref_type ref_t >47 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {48 // ensure ownership of `n` by this node to avoid spurious single-owner mutates49 assign( n );50 // return mutable version51 return get_and_mutate();52 48 } 53 49 -
src/AST/Node.hpp
r893e106 ref5ef56 94 94 std::ostream& operator<< ( std::ostream& out, const Node * node ); 95 95 96 /// Call a visitor on a possibly-null node97 template<typename node_t>98 auto maybe_accept( const node_t * n, Visitor & v ) -> decltype( n->accept(v) ) {99 return n ? n->accept( v ) : nullptr;100 }101 102 96 /// Base class for the smart pointer types 103 97 /// should never really be used. … … 147 141 const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); } 148 142 149 /// Returns a mutable version of the pointer in this node.150 node_t * get_and_mutate();151 152 143 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere. 153 144 /// Returns a mutable version of the pointer in this node. -
src/AST/Pass.hpp
r893e106 ref5ef56 223 223 }; 224 224 225 /// Apply a pass to an entire translation unit226 225 template<typename pass_t> 227 226 void accept_all( std::list< ast::ptr<ast::Decl> > &, ast::Pass<pass_t> & visitor ); -
src/AST/Print.cpp
r893e106 ref5ef56 495 495 496 496 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) { 497 os << indent << "Types:" << std::endl;498 for ( const auto& i : *node ) {499 os << indent+1 << i.first << " -> ";500 indent += 2;501 i.second->accept( *this );502 indent -= 2;503 os << std::endl;504 }505 os << indent << "Non-types:" << std::endl;506 for ( auto i = node->beginVar(); i != node->endVar(); ++i ) {507 os << indent+1 << i->first << " -> ";508 indent += 2;509 i->second->accept( *this );510 indent -= 2;511 os << std::endl;512 }513 497 return node; 514 498 } -
src/AST/Type.hpp
r893e106 ref5ef56 47 47 bool is_atomic() const { return qualifiers.is_atomic; } 48 48 49 Type * set_const( bool v ) { qualifiers.is_const = v; return this; }50 Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; }51 Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; }52 Type * set_mutex( bool v ) { qualifiers.is_mutex = v; return this; }53 Type * set_atomic( bool v ) { qualifiers.is_atomic = v; return this; }49 void set_const( bool v ) { qualifiers.is_const = v; } 50 void set_restrict( bool v ) { qualifiers.is_restrict = v; } 51 void set_lvalue( bool v ) { qualifiers.is_lvalue = v; } 52 void set_mutex( bool v ) { qualifiers.is_mutex = v; } 53 void set_atomic( bool v ) { qualifiers.is_atomic = v; } 54 54 55 55 /// How many elemental types are represented by this type -
src/AST/TypeSubstitution.hpp
r893e106 ref5ef56 25 25 #include "Fwd.hpp" // for UniqueId 26 26 #include "ParseNode.hpp" 27 #include "Type.hpp" 27 #include "Type.hpp" // for ptr<Type> 28 28 #include "Common/SemanticError.h" // for SemanticError 29 29 #include "Visitor.hpp" 30 30 #include "Decl.hpp" 31 31 #include "Expr.hpp" 32 #include "Node.hpp"33 32 34 33 namespace ast { … … 44 43 TypeSubstitution &operator=( const TypeSubstitution &other ); 45 44 46 template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const; 47 template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const; 48 49 template< typename node_t, enum Node::ref_type ref_t > 50 int apply( ptr_base< node_t, ref_t > & input ) const { 51 const node_t * p = input.get(); 52 int ret = apply(p); 53 input = p; 54 return ret; 55 } 56 57 template< typename node_t, enum Node::ref_type ref_t > 58 int applyFree( ptr_base< node_t, ref_t > & input ) const { 59 const node_t * p = input.get(); 60 int ret = applyFree(p); 61 input = p; 62 return ret; 63 } 45 template< typename SynTreeClass > int apply( SynTreeClass *&input ) const; 46 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const; 64 47 65 48 void add( std::string formalType, const Type *actualType ); … … 179 162 180 163 template< typename SynTreeClass > 181 int TypeSubstitution::apply( const SynTreeClass *&input ) const {164 int TypeSubstitution::apply( SynTreeClass *&input ) const { 182 165 assert( input ); 183 166 Pass<Substituter> sub( *this, false ); 184 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 167 input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) ); 168 assert( input ); 185 169 /// std::cerr << "substitution result is: "; 186 170 /// newType->print( std::cerr ); … … 190 174 191 175 template< typename SynTreeClass > 192 int TypeSubstitution::applyFree( const SynTreeClass *&input ) const {176 int TypeSubstitution::applyFree( SynTreeClass *&input ) const { 193 177 assert( input ); 194 178 Pass<Substituter> sub( *this, true ); 195 input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) ); 179 input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) ); 180 assert( input ); 196 181 /// std::cerr << "substitution result is: "; 197 182 /// newType->print( std::cerr ); -
src/AST/module.mk
r893e106 ref5ef56 21 21 AST/DeclReplacer.cpp \ 22 22 AST/Expr.cpp \ 23 AST/GenericSubstitution.cpp \24 23 AST/Init.cpp \ 25 24 AST/LinkageSpec.cpp \ -
src/AST/porting.md
r893e106 ref5ef56 38 38 39 39 `N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class 40 * **TODO** `Declaration::printShort` should also be integrated 40 * **TODO** write this visitor 41 * **TODO** write `std::ostream& operator<< ( std::ostream& out, const Node* node )` in `Node.hpp` in terms of `ast::Print` 42 * `Declaration::printShort` should also be integrated 41 43 42 44 `clone` is private to `Node` now … … 206 208 207 209 `CompoundStmt` 210 * **TODO** port copy operator 211 * Needs to be an almost-shallow clone, where the declarations are cloned only if needed 212 * **TODO** port `DeclReplacer` 208 213 * Still a `std::list` for children, rather than `std::vector` 209 214 * allows more-efficient splicing for purposes of later code generation … … 224 229 * `getAggr()` => `aggr()` 225 230 * also now returns `const AggregateDecl *` 226 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` 231 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write 227 232 228 233 `BasicType` -
src/Makefile.in
r893e106 ref5ef56 167 167 am__objects_1 = AST/Attribute.$(OBJEXT) AST/Convert.$(OBJEXT) \ 168 168 AST/Decl.$(OBJEXT) AST/DeclReplacer.$(OBJEXT) \ 169 AST/Expr.$(OBJEXT) AST/GenericSubstitution.$(OBJEXT) \ 170 AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \ 171 AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \ 172 AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \ 173 AST/TypeSubstitution.$(OBJEXT) 169 AST/Expr.$(OBJEXT) AST/Init.$(OBJEXT) \ 170 AST/LinkageSpec.$(OBJEXT) AST/Node.$(OBJEXT) \ 171 AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) AST/Stmt.$(OBJEXT) \ 172 AST/Type.$(OBJEXT) AST/TypeSubstitution.$(OBJEXT) 174 173 am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \ 175 174 CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \ … … 575 574 AST/DeclReplacer.cpp \ 576 575 AST/Expr.cpp \ 577 AST/GenericSubstitution.cpp \578 576 AST/Init.cpp \ 579 577 AST/LinkageSpec.cpp \ … … 741 739 AST/$(DEPDIR)/$(am__dirstamp) 742 740 AST/Expr.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp) 743 AST/GenericSubstitution.$(OBJEXT): AST/$(am__dirstamp) \744 AST/$(DEPDIR)/$(am__dirstamp)745 741 AST/Init.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp) 746 742 AST/LinkageSpec.$(OBJEXT): AST/$(am__dirstamp) \ … … 1177 1173 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/DeclReplacer.Po@am__quote@ 1178 1174 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Expr.Po@am__quote@ 1179 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/GenericSubstitution.Po@am__quote@1180 1175 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Init.Po@am__quote@ 1181 1176 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/LinkageSpec.Po@am__quote@
Note:
See TracChangeset
for help on using the changeset viewer.