- Timestamp:
- Jun 4, 2019, 6:39:23 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c6a1e8a
- Parents:
- 7564e10 (diff), 1346914 (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
- 13 edited
 
 - 
          
  Convert.cpp (modified) (7 diffs)
- 
          
  Decl.cpp (modified) (2 diffs)
- 
          
  Decl.hpp (modified) (5 diffs)
- 
          
  Expr.cpp (modified) (5 diffs)
- 
          
  Node.hpp (modified) (8 diffs)
- 
          
  Pass.hpp (modified) (1 diff)
- 
          
  Pass.proto.hpp (modified) (1 diff)
- 
          
  Print.hpp (modified) (2 diffs)
- 
          
  SymbolTable.cpp (added)
- 
          
  SymbolTable.hpp (added)
- 
          
  Type.cpp (modified) (2 diffs)
- 
          
  Type.hpp (modified) (5 diffs)
- 
          
  TypeEnvironment.cpp (added)
- 
          
  TypeEnvironment.hpp (added)
- 
          
  TypeSubstitution.cpp (modified) (2 diffs)
- 
          
  module.mk (modified) (1 diff)
- 
          
  porting.md (modified) (2 diffs)
 
Legend:
- Unmodified
- Added
- Removed
- 
      src/AST/Convert.cppr7564e10 r67130fe 47 47 namespace { 48 48 49 // This is to preserve the SymTab::dereferenceOperatorhack. It does not (and perhaps should not)49 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 50 50 // allow us to use the same stratagy in the new ast. 51 51 ast::FunctionDecl * dereferenceOperator = nullptr; 52 ast::StructDecl * dtorStruct = nullptr; 53 ast::FunctionDecl * dtorStructDestroy = nullptr; 52 54 53 55 } … … 75 77 std::list< T * > acceptL( const U & container ) { 76 78 std::list< T * > ret; 77 for ( auto ptr : container ) {79 for ( auto ptr : container ) { 78 80 ret.emplace_back( accept1( ptr ) ); 79 81 } … … 176 178 Validate::dereferenceOperator = decl; 177 179 } 180 if ( dtorStructDestroy == node ) { 181 Validate::dtorStructDestroy = decl; 182 } 178 183 return declWithTypePostamble( decl, node ); 179 184 } … … 231 236 LinkageSpec::Spec( node->linkage.val ) 232 237 ); 238 239 if ( dtorStruct == node ) { 240 Validate::dtorStruct = decl; 241 } 242 233 243 return aggregatePostamble( decl, node ); 234 244 } … … 1445 1455 }; 1446 1456 cache.emplace( old, decl ); 1457 decl->withExprs = GET_ACCEPT_V(withExprs, Expr); 1447 1458 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); 1448 1459 decl->scopeLevel = old->scopeLevel; … … 1456 1467 if ( Validate::dereferenceOperator == old ) { 1457 1468 dereferenceOperator = decl; 1469 } 1470 1471 if ( Validate::dtorStructDestroy == old ) { 1472 dtorStructDestroy = decl; 1458 1473 } 1459 1474 } … … 1478 1493 1479 1494 this->node = decl; 1495 1496 if ( Validate::dtorStruct == old ) { 1497 dtorStruct = decl; 1498 } 1480 1499 } 1481 1500 
- 
      src/AST/Decl.cppr7564e10 r67130fe 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.hppr7564e10 r67130fe 16 16 #pragma once 17 17 18 #include <iosfwd> 18 19 #include <string> // for string, to_string 19 20 #include <unordered_map> … … 101 102 ptr<Expr> bitfieldWidth; 102 103 103 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, Init * init = nullptr, 104 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, Expr * bitWd = nullptr, 105 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {}) 104 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, 105 Init * init = nullptr, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, 106 Expr * bitWd = nullptr, std::vector< ptr<Attribute> > && attrs = {}, 107 Function::Specs fs = {} ) 106 108 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ), 107 109 init( init ), bitfieldWidth( bitWd ) {} … … 121 123 ptr<FunctionType> type; 122 124 ptr<CompoundStmt> stmts; 123 std:: list< ptr<Expr> > withExprs;125 std::vector< ptr<Expr> > withExprs; 124 126 125 127 FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type, … … 172 174 173 175 Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {} 174 Data( TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {}176 Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {} 175 177 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {} 176 Data( const Data & d1, const Data& d2 )178 Data( const Data & d1, const Data & d2 ) 177 179 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 178 180 179 bool operator== ( const Data & o ) const {181 bool operator== ( const Data & o ) const { 180 182 return kind == o.kind && isComplete == o.isComplete; 181 183 } 182 bool operator!= ( const Data & o ) const { return !(*this == o); }184 bool operator!= ( const Data & o ) const { return !(*this == o); } 183 185 }; 184 186 … … 200 202 MUTATE_FRIEND 201 203 }; 204 205 std::ostream & operator<< ( std::ostream &, const TypeDecl::Data & ); 202 206 203 207 /// C-style typedef `typedef Foo Bar` 
- 
      src/AST/Expr.cppr7564e10 r67130fe 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_qualifiers( ret->result, CV::Lvalue ); 67 68 } 68 69 } … … 164 165 genericSubsitution( aggregate->result ).apply( result ); 165 166 // ensure lvalue and appropriate restrictions from aggregate type 166 result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;167 add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue ); 167 168 } 168 169 … … 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_qualifiers( result, CV::Lvalue ); 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_qualifiers( result, CV::Lvalue ); 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_qualifiers( result, CV::Lvalue ); 325 329 } 326 330 
- 
      src/AST/Node.hppr7564e10 r67130fe 10 10 // Created On : Wed May 8 10:27:04 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu May 23 16:00:00 201913 // Update Count : 412 // Last Modified On : Mon Jun 3 13:26:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 18 18 #include <cassert> 19 19 #include <iosfwd> 20 21 #include "Common/ErrorObjects.h" // for SemanticErrorException 20 22 21 23 namespace ast { … … 100 102 } 101 103 104 /// Call a visitor on a collection of nodes, throwing any exceptions when completed 105 template< typename Container > 106 void accept_each( const Container & c, Visitor & v ) { 107 SemanticErrorException errors; 108 for ( const auto & i : c ) { 109 try { 110 if ( i ) { 111 i->accept( v ); 112 } 113 } catch ( SemanticErrorException & e ) { 114 errors.append( e ); 115 } 116 } 117 if ( ! errors.isEmpty() ) { 118 throw errors; 119 } 120 } 121 102 122 /// Base class for the smart pointer types 103 123 /// should never really be used. … … 107 127 ptr_base() : node(nullptr) {} 108 128 ptr_base( const node_t * n ) : node(n) { if( node ) _inc(node); } 109 ~ptr_base() { if( node ) _dec(node);}129 ~ptr_base() { if( node ) { auto tmp = node; node = nullptr; _dec(tmp); } } 110 130 111 131 ptr_base( const ptr_base & o ) : node(o.node) { … … 113 133 } 114 134 115 ptr_base( ptr_base && o ) : node(o.node) { 116 if( node ) _inc(node); 117 } 135 ptr_base( ptr_base && o ) : node(o.node) { o.node = nullptr; } 118 136 119 137 template< enum Node::ref_type o_ref_t > … … 129 147 template<typename o_node_t> 130 148 ptr_base & operator=( const o_node_t * node ) { 131 assign( node ? strict_dynamic_cast<const node_t *>(node) : nullptr);149 assign( strict_dynamic_cast<const node_t *, nullptr>(node) ); 132 150 return *this; 133 151 } … … 139 157 140 158 ptr_base & operator=( ptr_base && o ) { 141 assign(o.node); 159 if ( node == o.node ) return *this; 160 if ( node ) _dec(node); 161 node = o.node; 162 o.node = nullptr; 142 163 return *this; 143 164 } … … 165 186 const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); } 166 187 188 /// wrapper for convenient access to strict_dynamic_cast 189 template<typename o_node_t> 190 const o_node_t * strict_as() const { return strict_dynamic_cast<const o_node_t *>(node); } 191 167 192 /// Returns a mutable version of the pointer in this node. 168 193 node_t * get_and_mutate(); 
- 
      src/AST/Pass.hppr7564e10 r67130fe 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.hppr7564e10 r67130fe 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.hppr7564e10 r67130fe 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.cppr7564e10 r67130fe 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.hppr7564e10 r67130fe 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" … … 48 48 49 49 Type * set_const( bool v ) { qualifiers.is_const = v; return this; } 50 Type * set_volatile( bool v ) { qualifiers.is_volatile = v; return this; } 50 51 Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; } 51 52 Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; } … … 58 59 virtual bool isVoid() const { return size() == 0; } 59 60 /// Get the i'th component of this type 60 virtual const Type * getComponent( unsigned i ) ;61 virtual const Type * getComponent( unsigned i ) const; 61 62 62 63 /// type without outer pointers and arrays 63 const Type * stripDeclarator() ;64 const Type * stripDeclarator() const; 64 65 /// type without outer references 65 const Type * stripReferences() ;66 const Type * stripReferences() const; 66 67 /// number of reference occuring consecutively on the outermost layer of this type 67 68 /// (i.e. do not count references nested within other types) … … 75 76 MUTATE_FRIEND 76 77 }; 78 79 /// Clear/reset the qualifiers on this type, cloning only if necessary 80 template< enum Node::ref_type ref_t > 81 void reset_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q = {} ) { 82 if ( p->qualifiers.val != q.val ) p.get_and_mutate()->qualifiers = q; 83 } 84 85 /// Add the specified qualifiers to this type, cloning only if necessary 86 template< enum Node::ref_type ref_t > 87 void add_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 88 if ( ( p->qualifiers.val & q.val ) != q.val ) p.get_and_mutate()->qualifiers |= q; 89 } 90 91 /// Remove the specified qualifiers from this type, cloning only if necessary 92 template< enum Node::ref_type ref_t > 93 void remove_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 94 if ( ( p->qualifiers.val & q.val ) != 0 ) p.get_and_mutate()->qualifiers -= q; 95 } 77 96 78 97 /// `void` … … 437 456 unsigned size() const override { return types.size(); } 438 457 439 const Type * getComponent( unsigned i ) override {458 const Type * getComponent( unsigned i ) const override { 440 459 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 441 460 i, size() ); 
- 
      src/AST/TypeSubstitution.cppr7564e10 r67130fe 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 16 15:54:35201713 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jun 3 13:26:00 2017 13 // Update Count : 5 14 14 // 15 15 … … 26 26 } 27 27 28 TypeSubstitution::~TypeSubstitution() { 29 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 30 delete( i->second ); 31 } 32 for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 33 delete( i->second ); 34 } 35 } 28 TypeSubstitution::~TypeSubstitution() {} 36 29 37 30 TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) { 
- 
      src/AST/module.mkr7564e10 r67130fe 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.mdr7564e10 r67130fe 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 293 `WidenMode` 294 * changed `widenFirst`, `widenSecond` => `first`, `second` 295 * changed `WidenMode widenMode` => `WidenMode widen` 296 263 297 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes 264 298 
  Note:
 See   TracChangeset
 for help on using the changeset viewer.
  