Changeset 67130fe for src/AST


Ignore:
Timestamp:
Jun 4, 2019, 6:39:23 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r7564e10 r67130fe  
    4747namespace {
    4848
    49 // This is to preserve the SymTab::dereferenceOperator hack. It does not (and perhaps should not)
     49// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5050// allow us to use the same stratagy in the new ast.
    5151ast::FunctionDecl * dereferenceOperator = nullptr;
     52ast::StructDecl   * dtorStruct = nullptr;
     53ast::FunctionDecl * dtorStructDestroy = nullptr;
    5254
    5355}
     
    7577                std::list< T * > acceptL( const U & container ) {
    7678                        std::list< T * > ret;
    77                         for (auto ptr : container ) {
     79                        for ( auto ptr : container ) {
    7880                                ret.emplace_back( accept1( ptr ) );
    7981                        }
     
    176178                        Validate::dereferenceOperator = decl;
    177179                }
     180                if ( dtorStructDestroy == node ) {
     181                        Validate::dtorStructDestroy = decl;
     182                }
    178183                return declWithTypePostamble( decl, node );
    179184        }
     
    231236                        LinkageSpec::Spec( node->linkage.val )
    232237                );
     238
     239                if ( dtorStruct == node ) {
     240                        Validate::dtorStruct = decl;
     241                }
     242
    233243                return aggregatePostamble( decl, node );
    234244        }
     
    14451455                };
    14461456                cache.emplace( old, decl );
     1457                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    14471458                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
    14481459                decl->scopeLevel = old->scopeLevel;
     
    14561467                if ( Validate::dereferenceOperator == old ) {
    14571468                        dereferenceOperator = decl;
     1469                }
     1470
     1471                if ( Validate::dtorStructDestroy == old ) {
     1472                        dtorStructDestroy = decl;
    14581473                }
    14591474        }
     
    14781493
    14791494                this->node = decl;
     1495
     1496                if ( Validate::dtorStruct == old ) {
     1497                        dtorStruct = decl;
     1498                }
    14801499        }
    14811500
  • src/AST/Decl.cpp

    r7564e10 r67130fe  
    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

    r7564e10 r67130fe  
    1616#pragma once
    1717
     18#include <iosfwd>
    1819#include <string>              // for string, to_string
    1920#include <unordered_map>
     
    101102        ptr<Expr> bitfieldWidth;
    102103
    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 = {} )
    106108        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ),
    107109          init( init ), bitfieldWidth( bitWd ) {}
     
    121123        ptr<FunctionType> type;
    122124        ptr<CompoundStmt> stmts;
    123         std::list< ptr<Expr> > withExprs;
     125        std::vector< ptr<Expr> > withExprs;
    124126
    125127        FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
     
    172174
    173175                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 ) {}
    175177                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 )
    177179                : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
    178180
    179                 bool operator== ( const Data& o ) const {
     181                bool operator== ( const Data & o ) const {
    180182                        return kind == o.kind && isComplete == o.isComplete;
    181183                }
    182                 bool operator!= ( const Data& o ) const { return !(*this == o); }
     184                bool operator!= ( const Data & o ) const { return !(*this == o); }
    183185        };
    184186
     
    200202        MUTATE_FRIEND
    201203};
     204
     205std::ostream & operator<< ( std::ostream &, const TypeDecl::Data & );
    202206
    203207/// C-style typedef `typedef Foo Bar`
  • src/AST/Expr.cpp

    r7564e10 r67130fe  
    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_qualifiers( ret->result, CV::Lvalue );
    6768                }
    6869        }
     
    164165        genericSubsitution( aggregate->result ).apply( result );
    165166        // 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 );
    167168}
    168169
     
    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_qualifiers( result, CV::Lvalue );
    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_qualifiers( result, CV::Lvalue );
    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_qualifiers( result, CV::Lvalue );
    325329}
    326330
  • src/AST/Node.hpp

    r7564e10 r67130fe  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 23 16:00:00 2019
    13 // Update Count     : 4
     12// Last Modified On : Mon Jun  3 13:26:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    1818#include <cassert>
    1919#include <iosfwd>
     20
     21#include "Common/ErrorObjects.h"  // for SemanticErrorException
    2022
    2123namespace ast {
     
    100102}
    101103
     104/// Call a visitor on a collection of nodes, throwing any exceptions when completed
     105template< typename Container >
     106void 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
    102122/// Base class for the smart pointer types
    103123/// should never really be used.
     
    107127        ptr_base() : node(nullptr) {}
    108128        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); } }
    110130
    111131        ptr_base( const ptr_base & o ) : node(o.node) {
     
    113133        }
    114134
    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; }
    118136
    119137        template< enum Node::ref_type o_ref_t >
     
    129147        template<typename o_node_t>
    130148        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) );
    132150                return *this;
    133151        }
     
    139157
    140158        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;
    142163                return *this;
    143164        }
     
    165186        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
    166187
     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
    167192        /// Returns a mutable version of the pointer in this node.
    168193        node_t * get_and_mutate();
  • src/AST/Pass.hpp

    r7564e10 r67130fe  
    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

    r7564e10 r67130fe  
    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

    r7564e10 r67130fe  
    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

    r7564e10 r67130fe  
    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

    r7564e10 r67130fe  
    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"
     
    4848
    4949        Type * set_const( bool v ) { qualifiers.is_const = v; return this; }
     50        Type * set_volatile( bool v ) { qualifiers.is_volatile = v; return this; }
    5051        Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; }
    5152        Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; }
     
    5859        virtual bool isVoid() const { return size() == 0; }
    5960        /// Get the i'th component of this type
    60         virtual const Type * getComponent( unsigned i );
     61        virtual const Type * getComponent( unsigned i ) const;
    6162
    6263        /// type without outer pointers and arrays
    63         const Type * stripDeclarator();
     64        const Type * stripDeclarator() const;
    6465        /// type without outer references
    65         const Type * stripReferences();
     66        const Type * stripReferences() const;
    6667        /// number of reference occuring consecutively on the outermost layer of this type
    6768        /// (i.e. do not count references nested within other types)
     
    7576        MUTATE_FRIEND
    7677};
     78
     79/// Clear/reset the qualifiers on this type, cloning only if necessary
     80template< enum Node::ref_type ref_t >
     81void 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
     86template< enum Node::ref_type ref_t >
     87void 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
     92template< enum Node::ref_type ref_t >
     93void 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}
    7796
    7897/// `void`
     
    437456        unsigned size() const override { return types.size(); }
    438457
    439         const Type * getComponent( unsigned i ) override {
     458        const Type * getComponent( unsigned i ) const override {
    440459                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d",
    441460                        i, size() );
  • src/AST/TypeSubstitution.cpp

    r7564e10 r67130fe  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 15:54:35 2017
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jun  3 13:26:00 2017
     13// Update Count     : 5
    1414//
    1515
     
    2626}
    2727
    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 }
     28TypeSubstitution::~TypeSubstitution() {}
    3629
    3730TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) {
  • src/AST/module.mk

    r7564e10 r67130fe  
    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

    r7564e10 r67130fe  
    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
     293`WidenMode`
     294* changed `widenFirst`, `widenSecond` => `first`, `second`
     295* changed `WidenMode widenMode` => `WidenMode widen`
     296
    263297[1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes
    264298
Note: See TracChangeset for help on using the changeset viewer.