Changeset d76c588


Ignore:
Timestamp:
May 30, 2019, 4:10:24 PM (6 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
Files:
4 added
26 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
  • src/GenPoly/GenPoly.cc

    reba615c rd76c588  
    2424#include <vector>                       // for vector
    2525
     26#include "AST/Type.hpp"
    2627#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
    2728#include "ResolvExpr/typeops.h"         // for flatten
     
    262263                } else {
    263264                        return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
     265                }
     266        }
     267
     268        const ast::FunctionType * getFunctionType( const ast::Type * ty ) {
     269                if ( auto pty = dynamic_cast< const ast::PointerType * >( ty ) ) {
     270                        return pty->base.as< ast::FunctionType >();
     271                } else {
     272                        return dynamic_cast< const ast::FunctionType * >( ty );
    264273                }
    265274        }
  • src/GenPoly/GenPoly.h

    reba615c rd76c588  
    2020
    2121#include "ErasableScopedMap.h"    // for ErasableScopedMap
     22#include "AST/Fwd.hpp"
    2223#include "SymTab/Mangler.h"       // for Mangler
    2324#include "SynTree/Declaration.h"  // for TypeDecl::Data, AggregateDecl, Type...
     
    7273        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
    7374        FunctionType *getFunctionType( Type *ty );
     75        const ast::FunctionType * getFunctionType( const ast::Type * ty );
    7476
    7577        /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise;
  • src/InitTweak/InitTweak.cc

    reba615c rd76c588  
    756756        }
    757757
     758        bool isCopyFunction( const ast::FunctionDecl * decl ) {
     759                const ast::FunctionType * ftype = decl->type;
     760                if ( ftype->params.size() != 2 ) return false;
     761
     762                const ast::Type * t1 = getPointerBase( ftype->params.front()->get_type() );
     763                if ( ! t1 ) return false;
     764                const ast::Type * t2 = ftype->params.back()->get_type();
     765               
     766                return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2, ast::SymbolTable{} );
     767        }
     768
    758769        FunctionDecl * isAssignment( Declaration * decl ) {
    759770                return isCopyFunction( decl, "?=?" );
  • src/InitTweak/InitTweak.h

    reba615c rd76c588  
    3030        FunctionDecl * isCopyConstructor( Declaration * decl );
    3131        FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
     32        bool isCopyFunction( const ast::FunctionDecl * decl );
    3233
    3334        /// returns the base type of the first parameter to a constructor/destructor/assignment function
  • src/Makefile.in

    reba615c rd76c588  
    170170        AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \
    171171        AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \
    172         AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \
     172        AST/Stmt.$(OBJEXT) AST/SymbolTable.$(OBJEXT) \
     173        AST/Type.$(OBJEXT) AST/TypeEnvironment.$(OBJEXT) \
    173174        AST/TypeSubstitution.$(OBJEXT)
    174175am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \
     
    582583        AST/Print.cpp \
    583584        AST/Stmt.cpp \
     585        AST/SymbolTable.cpp \
    584586        AST/Type.cpp \
     587        AST/TypeEnvironment.cpp \
    585588        AST/TypeSubstitution.cpp
    586589
     
    750753AST/Print.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    751754AST/Stmt.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
     755AST/SymbolTable.$(OBJEXT): AST/$(am__dirstamp) \
     756        AST/$(DEPDIR)/$(am__dirstamp)
    752757AST/Type.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
     758AST/TypeEnvironment.$(OBJEXT): AST/$(am__dirstamp) \
     759        AST/$(DEPDIR)/$(am__dirstamp)
    753760AST/TypeSubstitution.$(OBJEXT): AST/$(am__dirstamp) \
    754761        AST/$(DEPDIR)/$(am__dirstamp)
     
    11841191@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Print.Po@am__quote@
    11851192@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Stmt.Po@am__quote@
     1193@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/SymbolTable.Po@am__quote@
    11861194@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Type.Po@am__quote@
     1195@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/TypeEnvironment.Po@am__quote@
    11871196@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/TypeSubstitution.Po@am__quote@
    11881197@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/CodeGenerator.Po@am__quote@
  • src/ResolvExpr/AlternativeFinder.cc

    reba615c rd76c588  
    2828#include "Alternative.h"           // for AltList, Alternative
    2929#include "AlternativeFinder.h"
     30#include "AST/Expr.hpp"
     31#include "AST/Type.hpp"
    3032#include "Common/SemanticError.h"  // for SemanticError
    3133#include "Common/utility.h"        // for deleteAll, printAll, CodeLocation
     
    222224                        cost.incReference();
    223225                }
     226        }
     227
     228        const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost ) {
     229                if ( expr->result.as< ast::ReferenceType >() ) {
     230                        // cast away reference from expr
     231                        cost.incReference();
     232                        return new ast::CastExpr{ expr->location, expr, expr->result->stripReferences() };
     233                }
     234               
     235                return expr;
    224236        }
    225237
  • src/ResolvExpr/ResolveAssertions.cc

    reba615c rd76c588  
    3030#include "Common/Indenter.h"        // for Indenter
    3131#include "Common/utility.h"         // for sort_mins
     32#include "GenPoly/GenPoly.h"        // for getFunctionType
    3233#include "ResolvExpr/RenameVars.h"  // for renameTyVars
    3334#include "SymTab/Indexer.h"         // for Indexer
     
    154155                        Cost k = Cost::zero;
    155156                        for ( const auto& assn : x.assns ) {
     157                                // compute conversion cost from satisfying decl to assertion
    156158                                k += computeConversionCost(
    157159                                        assn.match.adjType, assn.decl->get_type(), indexer, x.env );
    158160                               
    159161                                // mark vars+specialization cost on function-type assertions
    160                                 Type* assnType = assn.match.cdata.id->get_type();
    161                                 FunctionType* func;
    162                                 if ( PointerType* ptr = dynamic_cast< PointerType* >( assnType ) ) {
    163                                         func = dynamic_cast< FunctionType* >( ptr->base );
    164                                 } else {
    165                                         func = dynamic_cast< FunctionType* >( assnType );
    166                                 }
     162                                FunctionType* func = GenPoly::getFunctionType( assn.match.cdata.id->get_type() );
    167163                                if ( ! func ) continue;
    168164                               
  • src/ResolvExpr/Resolver.cc

    reba615c rd76c588  
    77// Resolver.cc --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Aaron B. Moss
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb 19 18:09:56 2019
    13 // Update Count     : 240
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Wed May 29 11:00:00 2019
     13// Update Count     : 241
    1414//
    1515
     
    2121#include "Alternative.h"                 // for Alternative, AltList
    2222#include "AlternativeFinder.h"           // for AlternativeFinder, resolveIn...
     23#include "CurrentObject.h"               // for CurrentObject
     24#include "RenameVars.h"                  // for RenameVars, global_renamer
     25#include "Resolver.h"
     26#include "ResolvMode.h"                  // for ResolvMode
     27#include "typeops.h"                     // for extractResultType
     28#include "Unify.h"                       // for unify
     29#include "AST/Pass.hpp"
     30#include "AST/SymbolTable.hpp"
    2331#include "Common/PassVisitor.h"          // for PassVisitor
    2432#include "Common/SemanticError.h"        // for SemanticError
    2533#include "Common/utility.h"              // for ValueGuard, group_iterate
    26 #include "CurrentObject.h"               // for CurrentObject
    2734#include "InitTweak/GenInit.h"
    2835#include "InitTweak/InitTweak.h"         // for isIntrinsicSingleArgCallStmt
    29 #include "RenameVars.h"                  // for RenameVars, global_renamer
    3036#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    31 #include "Resolver.h"
    32 #include "ResolvMode.h"                  // for ResolvMode
    3337#include "SymTab/Autogen.h"              // for SizeType
    3438#include "SymTab/Indexer.h"              // for Indexer
     
    4145#include "SynTree/Visitor.h"             // for acceptAll, maybeAccept
    4246#include "Tuples/Tuples.h"
    43 #include "typeops.h"                     // for extractResultType
    44 #include "Unify.h"                       // for unify
    4547
    4648using namespace std;
    4749
    4850namespace ResolvExpr {
    49         struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting, public WithStmtsToAdd {
    50                 Resolver() {}
    51                 Resolver( const SymTab::Indexer & other ) {
     51        struct Resolver_old final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver_old>, public WithShortCircuiting, public WithStmtsToAdd {
     52                Resolver_old() {}
     53                Resolver_old( const SymTab::Indexer & other ) {
    5254                        indexer = other;
    5355                }
     
    100102
    101103        void resolve( std::list< Declaration * > translationUnit ) {
    102                 PassVisitor<Resolver> resolver;
     104                PassVisitor<Resolver_old> resolver;
    103105                acceptAll( translationUnit, resolver );
    104106        }
    105107
    106108        void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) {
    107                 PassVisitor<Resolver> resolver( indexer );
     109                PassVisitor<Resolver_old> resolver( indexer );
    108110                maybeAccept( decl, resolver );
    109111        }
     
    401403        }
    402404
    403         void Resolver::previsit( ObjectDecl * objectDecl ) {
     405        void Resolver_old::previsit( ObjectDecl * objectDecl ) {
    404406                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that
    405407                // class-variable initContext is changed multiple time because the LHS is analysed twice.
     
    417419
    418420        template< typename PtrType >
    419         void Resolver::handlePtrType( PtrType * type ) {
     421        void Resolver_old::handlePtrType( PtrType * type ) {
    420422                if ( type->get_dimension() ) {
    421423                        findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );
     
    423425        }
    424426
    425         void Resolver::previsit( ArrayType * at ) {
     427        void Resolver_old::previsit( ArrayType * at ) {
    426428                handlePtrType( at );
    427429        }
    428430
    429         void Resolver::previsit( PointerType * pt ) {
     431        void Resolver_old::previsit( PointerType * pt ) {
    430432                handlePtrType( pt );
    431433        }
    432434
    433         void Resolver::previsit( FunctionDecl * functionDecl ) {
     435        void Resolver_old::previsit( FunctionDecl * functionDecl ) {
    434436#if 0
    435437                std::cerr << "resolver visiting functiondecl ";
     
    441443        }
    442444
    443         void Resolver::postvisit( FunctionDecl * functionDecl ) {
     445        void Resolver_old::postvisit( FunctionDecl * functionDecl ) {
    444446                // default value expressions have an environment which shouldn't be there and trips up
    445447                // later passes.
     
    456458        }
    457459
    458         void Resolver::previsit( EnumDecl * ) {
     460        void Resolver_old::previsit( EnumDecl * ) {
    459461                // in case we decide to allow nested enums
    460462                GuardValue( inEnumDecl );
     
    462464        }
    463465
    464         void Resolver::previsit( StaticAssertDecl * assertDecl ) {
     466        void Resolver_old::previsit( StaticAssertDecl * assertDecl ) {
    465467                findIntegralExpression( assertDecl->condition, indexer );
    466468        }
    467469
    468         void Resolver::previsit( ExprStmt * exprStmt ) {
     470        void Resolver_old::previsit( ExprStmt * exprStmt ) {
    469471                visit_children = false;
    470472                assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" );
     
    472474        }
    473475
    474         void Resolver::previsit( AsmExpr * asmExpr ) {
     476        void Resolver_old::previsit( AsmExpr * asmExpr ) {
    475477                visit_children = false;
    476478                findVoidExpression( asmExpr->operand, indexer );
     
    480482        }
    481483
    482         void Resolver::previsit( AsmStmt * asmStmt ) {
     484        void Resolver_old::previsit( AsmStmt * asmStmt ) {
    483485                visit_children = false;
    484486                acceptAll( asmStmt->get_input(), *visitor );
     
    486488        }
    487489
    488         void Resolver::previsit( IfStmt * ifStmt ) {
     490        void Resolver_old::previsit( IfStmt * ifStmt ) {
    489491                findIntegralExpression( ifStmt->condition, indexer );
    490492        }
    491493
    492         void Resolver::previsit( WhileStmt * whileStmt ) {
     494        void Resolver_old::previsit( WhileStmt * whileStmt ) {
    493495                findIntegralExpression( whileStmt->condition, indexer );
    494496        }
    495497
    496         void Resolver::previsit( ForStmt * forStmt ) {
     498        void Resolver_old::previsit( ForStmt * forStmt ) {
    497499                if ( forStmt->condition ) {
    498500                        findIntegralExpression( forStmt->condition, indexer );
     
    504506        }
    505507
    506         void Resolver::previsit( SwitchStmt * switchStmt ) {
     508        void Resolver_old::previsit( SwitchStmt * switchStmt ) {
    507509                GuardValue( currentObject );
    508510                findIntegralExpression( switchStmt->condition, indexer );
     
    511513        }
    512514
    513         void Resolver::previsit( CaseStmt * caseStmt ) {
     515        void Resolver_old::previsit( CaseStmt * caseStmt ) {
    514516                if ( caseStmt->condition ) {
    515517                        std::list< InitAlternative > initAlts = currentObject.getOptions();
     
    530532        }
    531533
    532         void Resolver::previsit( BranchStmt * branchStmt ) {
     534        void Resolver_old::previsit( BranchStmt * branchStmt ) {
    533535                visit_children = false;
    534536                // must resolve the argument for a computed goto
     
    541543        }
    542544
    543         void Resolver::previsit( ReturnStmt * returnStmt ) {
     545        void Resolver_old::previsit( ReturnStmt * returnStmt ) {
    544546                visit_children = false;
    545547                if ( returnStmt->expr ) {
     
    548550        }
    549551
    550         void Resolver::previsit( ThrowStmt * throwStmt ) {
     552        void Resolver_old::previsit( ThrowStmt * throwStmt ) {
    551553                visit_children = false;
    552554                // TODO: Replace *exception type with &exception type.
     
    560562        }
    561563
    562         void Resolver::previsit( CatchStmt * catchStmt ) {
     564        void Resolver_old::previsit( CatchStmt * catchStmt ) {
    563565                if ( catchStmt->cond ) {
    564566                        findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer );
     
    575577        }
    576578
    577         void Resolver::previsit( WaitForStmt * stmt ) {
     579        void Resolver_old::previsit( WaitForStmt * stmt ) {
    578580                visit_children = false;
    579581
     
    781783        }
    782784
    783         void Resolver::previsit( SingleInit * singleInit ) {
     785        void Resolver_old::previsit( SingleInit * singleInit ) {
    784786                visit_children = false;
    785787                // resolve initialization using the possibilities as determined by the currentObject cursor
     
    833835        }
    834836
    835         void Resolver::previsit( ListInit * listInit ) {
     837        void Resolver_old::previsit( ListInit * listInit ) {
    836838                visit_children = false;
    837839                // move cursor into brace-enclosed initializer-list
     
    868870
    869871        // ConstructorInit - fall back on C-style initializer
    870         void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
     872        void Resolver_old::fallbackInit( ConstructorInit * ctorInit ) {
    871873                // could not find valid constructor, or found an intrinsic constructor
    872874                // fall back on C-style initializer
     
    881883        void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) {
    882884                assert( ctorInit );
    883                 PassVisitor<Resolver> resolver( indexer );
     885                PassVisitor<Resolver_old> resolver( indexer );
    884886                ctorInit->accept( resolver );
    885887        }
     
    887889        void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) {
    888890                assert( stmtExpr );
    889                 PassVisitor<Resolver> resolver( indexer );
     891                PassVisitor<Resolver_old> resolver( indexer );
    890892                stmtExpr->accept( resolver );
    891893                stmtExpr->computeResult();
     
    893895        }
    894896
    895         void Resolver::previsit( ConstructorInit * ctorInit ) {
     897        void Resolver_old::previsit( ConstructorInit * ctorInit ) {
    896898                visit_children = false;
    897899                // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
     
    927929                // }
    928930        }
     931
     932        ///////////////////////////////////////////////////////////////////////////
     933        //
     934        // *** NEW RESOLVER ***
     935        //
     936        ///////////////////////////////////////////////////////////////////////////
     937
     938        class Resolver_new final
     939        : public ast::WithIndexer, public ast::WithGuards, public ast::WithVisitorRef<Resolver_new>,
     940          public ast::WithShortCircuiting, public ast::WithStmtsToAdd<> {
     941                 
     942        public:
     943                Resolver_new() = default;
     944                Resolver_new( const ast::SymbolTable & syms ) { /*symtab = syms;*/ }
     945
     946                void previsit( ast::FunctionDecl * functionDecl );
     947                ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl );
     948                void previsit( ast::ObjectDecl * objectDecl );
     949                void previsit( ast::EnumDecl * enumDecl );
     950                void previsit( ast::StaticAssertDecl * assertDecl );
     951
     952                void previsit( ast::ArrayType * at );
     953                void previsit( ast::PointerType * pt );
     954
     955                void previsit( ast::ExprStmt * exprStmt );
     956                void previsit( ast::AsmExpr * asmExpr );
     957                void previsit( ast::AsmStmt * asmStmt );
     958                void previsit( ast::IfStmt * ifStmt );
     959                void previsit( ast::WhileStmt * whileStmt );
     960                void previsit( ast::ForStmt * forStmt );
     961                void previsit( ast::SwitchStmt * switchStmt );
     962                void previsit( ast::CaseStmt * caseStmt );
     963                void previsit( ast::BranchStmt * branchStmt );
     964                void previsit( ast::ReturnStmt * returnStmt );
     965                void previsit( ast::ThrowStmt * throwStmt );
     966                void previsit( ast::CatchStmt * catchStmt );
     967                void previsit( ast::WaitForStmt * stmt );
     968
     969                void previsit( ast::SingleInit * singleInit );
     970                void previsit( ast::ListInit * listInit );
     971                void previsit( ast::ConstructorInit * ctorInit );
     972        };
     973
     974        void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit ) {
     975                ast::Pass<Resolver_new> resolver;
     976                accept_all( translationUnit, resolver );
     977        }
     978
     979        void previsit( ast::FunctionDecl * functionDecl ) {
     980                #warning unimplemented; Resolver port in progress
     981                (void)functionDecl;
     982                assert(false);
     983        }
     984
     985        ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl ) {
     986                #warning unimplemented; Resolver port in progress
     987                (void)functionDecl;
     988                assert(false);
     989                return nullptr;
     990        }
     991
     992        void previsit( ast::ObjectDecl * objectDecl ) {
     993                #warning unimplemented; Resolver port in progress
     994                (void)objectDecl;
     995                assert(false);
     996        }
     997
     998        void previsit( ast::EnumDecl * enumDecl ) {
     999                #warning unimplemented; Resolver port in progress
     1000                (void)enumDecl;
     1001                assert(false);
     1002        }
     1003
     1004        void previsit( ast::StaticAssertDecl * assertDecl ) {
     1005                #warning unimplemented; Resolver port in progress
     1006                (void)assertDecl;
     1007                assert(false);
     1008        }
     1009
     1010        void previsit( ast::ArrayType * at ) {
     1011                #warning unimplemented; Resolver port in progress
     1012                (void)at;
     1013                assert(false);
     1014        }
     1015
     1016        void previsit( ast::PointerType * pt ) {
     1017                #warning unimplemented; Resolver port in progress
     1018                (void)pt;
     1019                assert(false);
     1020        }
     1021
     1022        void previsit( ast::ExprStmt * exprStmt ) {
     1023                #warning unimplemented; Resolver port in progress
     1024                (void)exprStmt;
     1025                assert(false);
     1026        }
     1027
     1028        void previsit( ast::AsmExpr * asmExpr ) {
     1029                #warning unimplemented; Resolver port in progress
     1030                (void)asmExpr;
     1031                assert(false);
     1032        }
     1033
     1034        void previsit( ast::AsmStmt * asmStmt ) {
     1035                #warning unimplemented; Resolver port in progress
     1036                (void)asmStmt;
     1037                assert(false);
     1038        }
     1039
     1040        void previsit( ast::IfStmt * ifStmt ) {
     1041                #warning unimplemented; Resolver port in progress
     1042                (void)ifStmt;
     1043                assert(false);
     1044        }
     1045
     1046        void previsit( ast::WhileStmt * whileStmt ) {
     1047                #warning unimplemented; Resolver port in progress
     1048                (void)whileStmt;
     1049                assert(false);
     1050        }
     1051
     1052        void previsit( ast::ForStmt * forStmt ) {
     1053                #warning unimplemented; Resolver port in progress
     1054                (void)forStmt;
     1055                assert(false);
     1056        }
     1057
     1058        void previsit( ast::SwitchStmt * switchStmt ) {
     1059                #warning unimplemented; Resolver port in progress
     1060                (void)switchStmt;
     1061                assert(false);
     1062        }
     1063
     1064        void previsit( ast::CaseStmt * caseStmt ) {
     1065                #warning unimplemented; Resolver port in progress
     1066                (void)caseStmt;
     1067                assert(false);
     1068        }
     1069
     1070        void previsit( ast::BranchStmt * branchStmt ) {
     1071                #warning unimplemented; Resolver port in progress
     1072                (void)branchStmt;
     1073                assert(false);
     1074        }
     1075
     1076        void previsit( ast::ReturnStmt * returnStmt ) {
     1077                #warning unimplemented; Resolver port in progress
     1078                (void)returnStmt;
     1079                assert(false);
     1080        }
     1081
     1082        void previsit( ast::ThrowStmt * throwStmt ) {
     1083                #warning unimplemented; Resolver port in progress
     1084                (void)throwStmt;
     1085                assert(false);
     1086        }
     1087
     1088        void previsit( ast::CatchStmt * catchStmt ) {
     1089                #warning unimplemented; Resolver port in progress
     1090                (void)catchStmt;
     1091                assert(false);
     1092        }
     1093
     1094        void previsit( ast::WaitForStmt * stmt ) {
     1095                #warning unimplemented; Resolver port in progress
     1096                (void)stmt;
     1097                assert(false);
     1098        }
     1099
     1100        void previsit( ast::SingleInit * singleInit ) {
     1101                #warning unimplemented; Resolver port in progress
     1102                (void)singleInit;
     1103                assert(false);
     1104        }
     1105
     1106        void previsit( ast::ListInit * listInit ) {
     1107                #warning unimplemented; Resolver port in progress
     1108                (void)listInit;
     1109                assert(false);
     1110        }
     1111
     1112        void previsit( ast::ConstructorInit * ctorInit ) {
     1113                #warning unimplemented; Resolver port in progress
     1114                (void)ctorInit;
     1115                assert(false);
     1116        }
     1117
    9291118} // namespace ResolvExpr
    9301119
  • src/ResolvExpr/Resolver.h

    reba615c rd76c588  
    1616#pragma once
    1717
    18 #include <list>  // for list
     18#include <list>          // for list
     19#include <AST/Node.hpp>  // for ptr
    1920
    2021class ConstructorInit;
     
    2324class StmtExpr;
    2425namespace SymTab {
    25 class Indexer;
    26 }  // namespace SymTab
     26        class Indexer;
     27} // namespace SymTab
     28
     29namespace ast {
     30        class Decl;
     31} // namespace ast
    2732
    2833namespace ResolvExpr {
     
    4045        /// Resolves with-stmts and with-clauses on functions
    4146        void resolveWithExprs( std::list< Declaration * > & translationUnit );
     47
     48        /// Checks types and binds syntactic constructs to typed representations
     49        void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit );
    4250} // namespace ResolvExpr
    4351
  • src/ResolvExpr/Unify.cc

    reba615c rd76c588  
    1414//
    1515
    16 #include <cassert>                // for assertf, assert
    17 #include <iterator>               // for back_insert_iterator, back_inserter
    18 #include <map>                    // for _Rb_tree_const_iterator, _Rb_tree_i...
    19 #include <memory>                 // for unique_ptr
    20 #include <set>                    // for set
    21 #include <string>                 // for string, operator==, operator!=, bas...
    22 #include <utility>                // for pair, move
     16#include <cassert>                  // for assertf, assert
     17#include <iterator>                 // for back_insert_iterator, back_inserter
     18#include <map>                      // for _Rb_tree_const_iterator, _Rb_tree_i...
     19#include <memory>                   // for unique_ptr
     20#include <set>                      // for set
     21#include <string>                   // for string, operator==, operator!=, bas...
     22#include <utility>                  // for pair, move
    2323#include <vector>
    2424
    2525#include "AST/Node.hpp"
    2626#include "AST/Type.hpp"
    27 #include "Common/PassVisitor.h"   // for PassVisitor
    28 #include "FindOpenVars.h"         // for findOpenVars
    29 #include "Parser/LinkageSpec.h"   // for C
    30 #include "SynTree/Constant.h"     // for Constant
    31 #include "SynTree/Declaration.h"  // for TypeDecl, TypeDecl::Data, Declarati...
    32 #include "SynTree/Expression.h"   // for TypeExpr, Expression, ConstantExpr
    33 #include "SynTree/Mutator.h"      // for Mutator
    34 #include "SynTree/Type.h"         // for Type, TypeInstType, FunctionType
    35 #include "SynTree/Visitor.h"      // for Visitor
    36 #include "Tuples/Tuples.h"        // for isTtype
    37 #include "TypeEnvironment.h"      // for EqvClass, AssertionSet, OpenVarSet
     27#include "AST/TypeEnvironment.hpp"
     28#include "Common/PassVisitor.h"     // for PassVisitor
     29#include "FindOpenVars.h"           // for findOpenVars
     30#include "Parser/LinkageSpec.h"     // for C
     31#include "SynTree/Constant.h"       // for Constant
     32#include "SynTree/Declaration.h"    // for TypeDecl, TypeDecl::Data, Declarati...
     33#include "SynTree/Expression.h"     // for TypeExpr, Expression, ConstantExpr
     34#include "SynTree/Mutator.h"        // for Mutator
     35#include "SynTree/Type.h"           // for Type, TypeInstType, FunctionType
     36#include "SynTree/Visitor.h"        // for Visitor
     37#include "Tuples/Tuples.h"          // for isTtype
     38#include "TypeEnvironment.h"        // for EqvClass, AssertionSet, OpenVarSet
    3839#include "Unify.h"
    39 #include "typeops.h"              // for flatten, occurs, commonType
     40#include "typeops.h"                // for flatten, occurs, commonType
    4041
    4142namespace SymTab {
     
    106107                delete newSecond;
    107108                return result;
     109        }
     110
     111        bool typesCompatible(
     112                        const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
     113                        const ast::TypeEnvironment & env ) {
     114                #warning unimplemented
     115                assert((first, second, symtab, env, false));
     116                return false;
    108117        }
    109118
     
    130139                delete newSecond;
    131140                return result;
     141        }
     142
     143        bool typesCompatibleIgnoreQualifiers(
     144                        const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
     145                        const ast::TypeEnvironment & env ) {
     146                #warning unimplemented
     147                assert((first, second, symtab, env, false));
     148                return false;
    132149        }
    133150
     
    263280        }
    264281
     282        bool unifyInexact(
     283                        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     284                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & openVars,
     285                        WidenMode widenMode, const ast::SymbolTable & symtab, const ast::Type *& common ) {
     286                #warning unimplemented
     287                assert((type1, type2, env, need, have, openVars, widenMode, symtab, common, false));
     288                return false;
     289        }
     290
    265291        Unify::Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer )
    266292                : result( false ), type2( type2 ), env( env ), needAssertions( needAssertions ), haveAssertions( haveAssertions ), openVars( openVars ), widenMode( widenMode ), indexer( indexer ) {
  • src/ResolvExpr/Unify.h

    reba615c rd76c588  
    1818#include <list>                   // for list
    1919
     20#include "AST/TypeEnvironment.hpp"  // for TypeEnvironment, AssertionSet, OpenVarSet
    2021#include "Common/utility.h"       // for deleteAll
    2122#include "SynTree/Declaration.h"  // for TypeDecl, TypeDecl::Data
    2223#include "TypeEnvironment.h"      // for AssertionSet, OpenVarSet
    23 #include "WidenMode.h"            // for WidenMode
     24#include "WidenMode.h"              // for WidenMode
    2425
    2526class Type;
    2627class TypeInstType;
    2728namespace SymTab {
    28 class Indexer;
    29 }  // namespace SymTab
     29        class Indexer;
     30}
     31
     32namespace ast {
     33        class SymbolTable;
     34        class Type;
     35}
    3036
    3137namespace ResolvExpr {
     
    6268        }
    6369
     70        bool unifyInexact(
     71                const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     72                ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & openVars,
     73                WidenMode widenMode, const ast::SymbolTable & symtab, const ast::Type *& common );
     74
    6475} // namespace ResolvExpr
    6576
  • src/ResolvExpr/typeops.h

    reba615c rd76c588  
    1818#include <vector>
    1919
     20#include "AST/Fwd.hpp"
    2021#include "AST/Node.hpp"
     22#include "AST/SymbolTable.hpp"
    2123#include "AST/Type.hpp"
     24#include "AST/TypeEnvironment.hpp"
    2225#include "SynTree/SynTree.h"
    2326#include "SynTree/Type.h"
     
    99102        }
    100103
     104        bool typesCompatible(
     105                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
     106                const ast::TypeEnvironment & env = {} );
     107       
     108        bool typesCompatibleIgnoreQualifiers(
     109                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
     110                const ast::TypeEnvironment & env = {} );
     111
    101112        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
    102113        Type * extractResultType( FunctionType * functionType );
     
    115126        // in Occurs.cc
    116127        bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
     128        // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
    117129
    118130        template<typename Iter>
     
    127139        // in AlternativeFinder.cc
    128140        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
     141        const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );
    129142
    130143        // flatten tuple type into list of types
  • src/SymTab/Mangler.cc

    reba615c rd76c588  
    390390} // namespace SymTab
    391391
     392namespace Mangle {
     393        std::string mangle( const ast::Node * decl, Mangle::Mode mode ) {
     394                #warning unimplemented
     395                assert( decl && mode.val && false );
     396                return "";
     397        }
     398} // namespace Mangle
     399
    392400// Local Variables: //
    393401// tab-width: 4 //
  • src/SymTab/Mangler.h

    reba615c rd76c588  
    2121#include <utility>            // for pair
    2222
     23#include "AST/Bitfield.hpp"
     24#include "AST/Fwd.hpp"
    2325#include "SynTree/SynTree.h"  // for Types
    2426#include "SynTree/Visitor.h"  // for Visitor, maybeAccept
     
    7577} // SymTab
    7678
     79namespace Mangle {
     80        /// Bitflags for mangle modes
     81        enum {
     82                NoOverrideable  = 1 << 0,
     83                Type            = 1 << 1,
     84                NoGenericParams = 1 << 2
     85        };
     86
     87        /// Bitflag type for mangler modes
     88        struct mangle_flags {
     89                union {
     90                        unsigned int val;
     91                        struct {
     92                                bool no_overrideable   : 1;
     93                                bool type              : 1;
     94                                bool no_generic_params : 1;
     95                        };
     96                };
     97
     98                constexpr mangle_flags( unsigned int val ) : val(val) {}
     99        };
     100
     101        using Mode = bitfield<mangle_flags>;
     102
     103        /// Mangle declaration name
     104        std::string mangle( const ast::Node * decl, Mode mode = {} );
     105
     106        namespace Encoding {
     107                using namespace SymTab::Mangler::Encoding;
     108        };
     109}
     110
    77111extern "C" {
    78112        char * cforall_demangle(const char *, int);
Note: See TracChangeset for help on using the changeset viewer.