- Timestamp:
- Jun 3, 2019, 10:54:01 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0e315a5, dafe9e1
- Parents:
- 043a5b6 (diff), 8d70648 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/AST
- Files:
-
- 4 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r043a5b6 ra935892 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 29 1 1:05:00 201913 // Update Count : 812 // Last Modified On : Wed May 29 17:05:00 2019 13 // Update Count : 9 14 14 // 15 15 … … 77 77 std::list< T * > acceptL( const U & container ) { 78 78 std::list< T * > ret; 79 for ( auto ptr : container ) {79 for ( auto ptr : container ) { 80 80 ret.emplace_back( accept1( ptr ) ); 81 81 } … … 168 168 LinkageSpec::Spec( node->linkage.val ), 169 169 get<FunctionType>().accept1( node->type ), 170 get<CompoundStmt>().accept1( node->stmts ),170 {}, 171 171 get<Attribute>().acceptL( node->attributes ), 172 172 Type::FuncSpecifiers( node->funcSpec.val ) 173 173 ); 174 cache.emplace( node, decl ); 175 decl->statements = get<CompoundStmt>().accept1( node->stmts ); 174 176 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 175 177 if ( dereferenceOperator == node ) { … … 1446 1448 old->name, 1447 1449 GET_ACCEPT_1(type, FunctionType), 1448 GET_ACCEPT_1(statements, CompoundStmt),1450 {}, 1449 1451 { old->storageClasses.val }, 1450 1452 { old->linkage.val }, … … 1453 1455 }; 1454 1456 cache.emplace( old, decl ); 1457 decl->withExprs = GET_ACCEPT_V(withExprs, Expr); 1458 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); 1455 1459 decl->scopeLevel = old->scopeLevel; 1456 1460 decl->mangleName = old->mangleName; -
src/AST/Decl.cpp
r043a5b6 ra935892 17 17 18 18 #include <cassert> // for assert, strict_dynamic_cast 19 #include <iostream> 19 20 #include <string> 20 21 #include <unordered_map> … … 70 71 } 71 72 73 std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) { 74 return out << data.kind << ", " << data.isComplete; 75 } 76 72 77 // --- EnumDecl 73 78 -
src/AST/Decl.hpp
r043a5b6 ra935892 16 16 #pragma once 17 17 18 #include <iosfwd> 18 19 #include <string> // for string, to_string 19 20 #include <unordered_map> … … 121 122 ptr<FunctionType> type; 122 123 ptr<CompoundStmt> stmts; 123 std:: list< ptr<Expr> > withExprs;124 std::vector< ptr<Expr> > withExprs; 124 125 125 126 FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type, … … 172 173 173 174 Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {} 174 Data( TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {}175 Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {} 175 176 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {} 176 Data( const Data & d1, const Data& d2 )177 Data( const Data & d1, const Data & d2 ) 177 178 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 178 179 179 bool operator== ( const Data & o ) const {180 bool operator== ( const Data & o ) const { 180 181 return kind == o.kind && isComplete == o.isComplete; 181 182 } 182 bool operator!= ( const Data & o ) const { return !(*this == o); }183 bool operator!= ( const Data & o ) const { return !(*this == o); } 183 184 }; 184 185 … … 200 201 MUTATE_FRIEND 201 202 }; 203 204 std::ostream & operator<< ( std::ostream &, const TypeDecl::Data & ); 202 205 203 206 /// C-style typedef `typedef Foo Bar` -
src/AST/Expr.cpp
r043a5b6 ra935892 64 64 // references have been removed, in which case dereference returns an lvalue of the 65 65 // base type 66 ret->result.set_and_mutate( base )->set_lvalue( true ); 66 ret->result = base; 67 add_lvalue( ret->result ); 67 68 } 68 69 } … … 173 174 assert( var ); 174 175 assert( var->get_type() ); 175 result.set_and_mutate( var->get_type() )->set_lvalue( true ); 176 result = var->get_type(); 177 add_lvalue( result ); 176 178 } 177 179 … … 306 308 : Expr( loc ), init( i ) { 307 309 assert( t && i ); 308 result.set_and_mutate( t )->set_lvalue( true ); 310 result = t; 311 add_lvalue( result ); 309 312 } 310 313 … … 322 325 "index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); 323 326 // like MemberExpr, TupleIndexExpr is always an lvalue 324 result.set_and_mutate( type->types[ index ] )->set_lvalue( true ); 327 result = type->types[ index ]; 328 add_lvalue( result ); 325 329 } 326 330 -
src/AST/Node.hpp
r043a5b6 ra935892 113 113 } 114 114 115 ptr_base( ptr_base && o ) : node(o.node) { 116 if( node ) _inc(node); 117 } 115 ptr_base( ptr_base && o ) : node(o.node) { o.node = nullptr; } 118 116 119 117 template< enum Node::ref_type o_ref_t > … … 139 137 140 138 ptr_base & operator=( ptr_base && o ) { 141 assign(o.node); 139 if ( node == o.node ) return *this; 140 if ( node ) _dec(node); 141 node = o.node; 142 o.node = nullptr; 142 143 return *this; 143 144 } -
src/AST/Pass.hpp
r043a5b6 ra935892 179 179 180 180 template<typename pass_type> 181 friend void accept All( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor );181 friend void accept_all( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor ); 182 182 private: 183 183 -
src/AST/Pass.proto.hpp
r043a5b6 ra935892 312 312 INDEXER_FUNC1( addTrait , const TraitDecl * ); 313 313 INDEXER_FUNC2( addWith , const std::vector< ptr<Expr> > &, const Node * ); 314 INDEXER_FUNC2( addWith , const std::list < ptr<Expr> > &, const Node * );315 314 316 315 // A few extra functions have more complicated behaviour, they are hand written -
src/AST/Print.hpp
r043a5b6 ra935892 17 17 18 18 #include <iosfwd> 19 #include <utility> // for forward 19 20 20 21 #include "AST/Node.hpp" … … 28 29 void print( std::ostream & os, const ast::Node * node, Indenter indent = {} ); 29 30 30 inline void print( std::ostream & os, const ast::Node * node, unsigned int indent ) { 31 print( os, node, Indenter{ Indenter::tabsize, indent }); 31 /// Wrap any standard format printer (matching above) with integer Indenter constructor 32 template<typename T> 33 inline void print( std::ostream & os, T && x, unsigned int indent ) { 34 print( os, std::forward<T>(x), Indenter{ Indenter::tabsize, indent }); 32 35 } 33 36 -
src/AST/Type.cpp
r043a5b6 ra935892 27 27 namespace ast { 28 28 29 const Type * Type::getComponent( unsigned i ) {29 const Type * Type::getComponent( unsigned i ) const { 30 30 assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i ); 31 31 return this; 32 32 } 33 33 34 const Type * Type::stripDeclarator() {34 const Type * Type::stripDeclarator() const { 35 35 const Type * t; 36 36 const Type * a; … … 39 39 } 40 40 41 const Type * Type::stripReferences() {41 const Type * Type::stripReferences() const { 42 42 const Type * t; 43 43 const ReferenceType * r; -
src/AST/Type.hpp
r043a5b6 ra935892 25 25 #include "Decl.hpp" // for AggregateDecl subclasses 26 26 #include "Fwd.hpp" 27 #include "Node.hpp" // for Node, ptr 27 #include "Node.hpp" // for Node, ptr, ptr_base 28 28 #include "TypeVar.hpp" 29 29 #include "Visitor.hpp" … … 58 58 virtual bool isVoid() const { return size() == 0; } 59 59 /// Get the i'th component of this type 60 virtual const Type * getComponent( unsigned i ) ;60 virtual const Type * getComponent( unsigned i ) const; 61 61 62 62 /// type without outer pointers and arrays 63 const Type * stripDeclarator() ;63 const Type * stripDeclarator() const; 64 64 /// type without outer references 65 const Type * stripReferences() ;65 const Type * stripReferences() const; 66 66 /// number of reference occuring consecutively on the outermost layer of this type 67 67 /// (i.e. do not count references nested within other types) … … 75 75 MUTATE_FRIEND 76 76 }; 77 78 /// Set the `is_lvalue` qualifier on this type, cloning only if necessary 79 template< enum Node::ref_type ref_t > 80 void add_lvalue( ptr_base< Type, ref_t > & p ) { 81 if ( ! p->qualifiers.is_lvalue ) p.get_and_mutate()->qualifiers.is_lvalue = true; 82 } 83 84 /// Clear the qualifiers on this type, cloning only if necessary 85 template< enum Node::ref_type ref_t > 86 void clear_qualifiers( ptr_base< Type, ref_t > & p ) { 87 if ( p->qualifiers != CV::Qualifiers{} ) p.get_and_mutate()->qualifiers = CV::Qualifiers{}; 88 } 77 89 78 90 /// `void` … … 437 449 unsigned size() const override { return types.size(); } 438 450 439 const Type * getComponent( unsigned i ) override {451 const Type * getComponent( unsigned i ) const override { 440 452 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 441 453 i, size() ); -
src/AST/module.mk
r043a5b6 ra935892 28 28 AST/Print.cpp \ 29 29 AST/Stmt.cpp \ 30 AST/SymbolTable.cpp \ 30 31 AST/Type.cpp \ 32 AST/TypeEnvironment.cpp \ 31 33 AST/TypeSubstitution.cpp 32 34 -
src/AST/porting.md
r043a5b6 ra935892 104 104 * `LinkageSpec::isMangled(Spec)` etc. => `Spec.is_mangled` etc. 105 105 * `LinkageSpec::Intrinsic` etc. => `ast::Linkage::Intrinsic` etc. 106 * Boolean flags to `SymTab::Mangler::mangle` are now a `SymTab::Mangle::Mode` struct 107 * uses `bitfield` 108 * Because `Indexer` isn't a terribly evocative name: 109 * `SymTab::Indexer` => `ast::SymbolTable` 110 * `SymTab/Indexer.{h,cc}` => `AST/SymbolTable.{hpp,cpp}` 111 * **TODO** `WithIndexer` => `WithSymbolTable` 112 * `indexer` => `symTab` 113 * `IdData::deleteStmt` => `IdData::deleter` 114 * `lookupId()` now returns a vector rather than an out-param list 115 * To avoid name collisions: 116 * `SymTab::Mangler` => `Mangle` 117 * `ResolvExpr::TypeEnvironment` => `ast::TypeEnvironment` 118 * in `AST/TypeEnvironment.hpp` 106 119 * Boolean constructor parameters get replaced with a dedicated flag enum: 107 120 * e.g. `bool isVarLen;` => `enum LengthFlag { FixedLen, VariableLen };` `LengthFlag isVarLen;` … … 261 274 * feature is `type@thing` e.g. `int@MAX` 262 275 276 `referenceToRvalueConversion` 277 * now returns `const Expr *` rather than mutating argument 278 279 `printAssertionSet`, `printOpenVarSet` 280 * `ostream &` now first argument, for consistency 281 282 `EqvClass` 283 * `type` => `bound` 284 285 `TypeEnvironment` 286 * `makeSubstitution()` => `writeToSubstitution()` 287 * `isEmpty()` => `empty()` 288 * removed `clone()` in favour of explicit copies 289 290 `occurs` 291 * moved to be helper function in `TypeEnvironment.cpp` (its only use) 292 263 293 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes 264 294
Note: See TracChangeset
for help on using the changeset viewer.