Changeset d76c588 for src/AST


Ignore:
Timestamp:
May 30, 2019, 4:10:24 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
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:
8d70648
Parents:
eba615c
Message:

Stubs for new resolver, implementation of new indexer, type environment

Location:
src/AST
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    reba615c rd76c588  
    6363                std::list< T * > acceptL( const U & container ) {
    6464                        std::list< T * > ret;
    65                         for (auto ptr : container ) {
     65                        for ( auto ptr : container ) {
    6666                                ret.emplace_back( accept1( ptr ) );
    6767                        }
     
    14321432                };
    14331433                cache.emplace( old, decl );
     1434                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    14341435                decl->scopeLevel = old->scopeLevel;
    14351436                decl->mangleName = old->mangleName;
  • src/AST/Decl.cpp

    reba615c rd76c588  
    1717
    1818#include <cassert>             // for assert, strict_dynamic_cast
     19#include <iostream>
    1920#include <string>
    2021#include <unordered_map>
     
    7071}
    7172
     73std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) {
     74        return out << data.kind << ", " << data.isComplete;
     75}
     76
    7277// --- EnumDecl
    7378
  • src/AST/Decl.hpp

    reba615c rd76c588  
    1616#pragma once
    1717
     18#include <iosfwd>
    1819#include <string>              // for string, to_string
    1920#include <unordered_map>
     
    121122        ptr<FunctionType> type;
    122123        ptr<CompoundStmt> stmts;
    123         std::list< ptr<Expr> > withExprs;
     124        std::vector< ptr<Expr> > withExprs;
    124125
    125126        FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
     
    172173
    173174                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 ) {}
    175176                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 )
    177178                : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
    178179
    179                 bool operator== ( const Data& o ) const {
     180                bool operator== ( const Data & o ) const {
    180181                        return kind == o.kind && isComplete == o.isComplete;
    181182                }
    182                 bool operator!= ( const Data& o ) const { return !(*this == o); }
     183                bool operator!= ( const Data & o ) const { return !(*this == o); }
    183184        };
    184185
     
    200201        MUTATE_FRIEND
    201202};
     203
     204std::ostream & operator<< ( std::ostream &, const TypeDecl::Data & );
    202205
    203206/// C-style typedef `typedef Foo Bar`
  • src/AST/Expr.cpp

    reba615c rd76c588  
    6464                        // references have been removed, in which case dereference returns an lvalue of the
    6565                        // base type
    66                         ret->result.set_and_mutate( base )->set_lvalue( true );
     66                        ret->result = base;
     67                        add_lvalue( ret->result );
    6768                }
    6869        }
     
    173174        assert( var );
    174175        assert( var->get_type() );
    175         result.set_and_mutate( var->get_type() )->set_lvalue( true );
     176        result = var->get_type();
     177        add_lvalue( result );
    176178}
    177179
     
    306308: Expr( loc ), init( i ) {
    307309        assert( t && i );
    308         result.set_and_mutate( t )->set_lvalue( true );
     310        result = t;
     311        add_lvalue( result );
    309312}
    310313
     
    322325                "index %d in expr %s", type->size(), index, toString( tuple ).c_str() );
    323326        // 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 );
    325329}
    326330
  • src/AST/Node.hpp

    reba615c rd76c588  
    113113        }
    114114
    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; }
    118116
    119117        template< enum Node::ref_type o_ref_t >
     
    139137
    140138        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;
    142143                return *this;
    143144        }
  • src/AST/Pass.hpp

    reba615c rd76c588  
    179179
    180180        template<typename pass_type>
    181         friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor );
     181        friend void accept_all( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor );
    182182private:
    183183
  • src/AST/Pass.proto.hpp

    reba615c rd76c588  
    312312                INDEXER_FUNC1( addTrait  , const TraitDecl *     );
    313313                INDEXER_FUNC2( addWith   , const std::vector< ptr<Expr> > &, const Node * );
    314                 INDEXER_FUNC2( addWith   , const std::list  < ptr<Expr> > &, const Node * );
    315314
    316315                // A few extra functions have more complicated behaviour, they are hand written
  • src/AST/Print.hpp

    reba615c rd76c588  
    1717
    1818#include <iosfwd>
     19#include <utility> // for forward
    1920
    2021#include "AST/Node.hpp"
     
    2829void print( std::ostream & os, const ast::Node * node, Indenter indent = {} );
    2930
    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
     32template<typename T>
     33inline void print( std::ostream & os, T && x, unsigned int indent ) {
     34    print( os, std::forward<T>(x), Indenter{ Indenter::tabsize, indent });
    3235}
    3336
  • src/AST/Type.cpp

    reba615c rd76c588  
    2727namespace ast {
    2828
    29 const Type * Type::getComponent( unsigned i ) {
     29const Type * Type::getComponent( unsigned i ) const {
    3030        assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i );
    3131        return this;
    3232}
    3333
    34 const Type * Type::stripDeclarator() {
     34const Type * Type::stripDeclarator() const {
    3535        const Type * t;
    3636        const Type * a;
     
    3939}
    4040
    41 const Type * Type::stripReferences() {
     41const Type * Type::stripReferences() const {
    4242        const Type * t;
    4343        const ReferenceType * r;
  • src/AST/Type.hpp

    reba615c rd76c588  
    2525#include "Decl.hpp"          // for AggregateDecl subclasses
    2626#include "Fwd.hpp"
    27 #include "Node.hpp"          // for Node, ptr
     27#include "Node.hpp"          // for Node, ptr, ptr_base
    2828#include "TypeVar.hpp"
    2929#include "Visitor.hpp"
     
    5858        virtual bool isVoid() const { return size() == 0; }
    5959        /// Get the i'th component of this type
    60         virtual const Type * getComponent( unsigned i );
     60        virtual const Type * getComponent( unsigned i ) const;
    6161
    6262        /// type without outer pointers and arrays
    63         const Type * stripDeclarator();
     63        const Type * stripDeclarator() const;
    6464        /// type without outer references
    65         const Type * stripReferences();
     65        const Type * stripReferences() const;
    6666        /// number of reference occuring consecutively on the outermost layer of this type
    6767        /// (i.e. do not count references nested within other types)
     
    7575        MUTATE_FRIEND
    7676};
     77
     78/// Set the `is_lvalue` qualifier on this type, cloning only if necessary
     79template< enum Node::ref_type ref_t >
     80void 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
     85template< enum Node::ref_type ref_t >
     86void clear_qualifiers( ptr_base< Type, ref_t > & p ) {
     87        if ( p->qualifiers != CV::Qualifiers{} ) p.get_and_mutate()->qualifiers = CV::Qualifiers{};
     88}
    7789
    7890/// `void`
     
    437449        unsigned size() const override { return types.size(); }
    438450
    439         const Type * getComponent( unsigned i ) override {
     451        const Type * getComponent( unsigned i ) const override {
    440452                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d",
    441453                        i, size() );
  • src/AST/module.mk

    reba615c rd76c588  
    2828        AST/Print.cpp \
    2929        AST/Stmt.cpp \
     30        AST/SymbolTable.cpp \
    3031        AST/Type.cpp \
     32        AST/TypeEnvironment.cpp \
    3133        AST/TypeSubstitution.cpp
    3234
  • src/AST/porting.md

    reba615c rd76c588  
    104104          * `LinkageSpec::isMangled(Spec)` etc. => `Spec.is_mangled` etc.
    105105          * `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`
    106119* Boolean constructor parameters get replaced with a dedicated flag enum:
    107120  * e.g. `bool isVarLen;` => `enum LengthFlag { FixedLen, VariableLen };` `LengthFlag isVarLen;`
     
    261274  * feature is `type@thing` e.g. `int@MAX`
    262275
     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
    263293[1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes
    264294
Note: See TracChangeset for help on using the changeset viewer.