Changeset cde3891 for src/SymTab


Ignore:
Timestamp:
Jan 23, 2019, 4:52:16 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a200795
Parents:
9b086ca (diff), 1d832f4 (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' into cleanup-dtors

Location:
src/SymTab
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Demangle.cc

    r9b086ca rcde3891  
    392392                                parsers.emplace_back(Encoding::enum_t, [this](Type::Qualifiers tq) { return parseEnum(tq); });
    393393                                parsers.emplace_back(Encoding::type, [this](Type::Qualifiers tq) { return parseType(tq); });
    394                                 parsers.emplace_back(Encoding::zero, [this](Type::Qualifiers tq) { return new ZeroType(tq); });
    395                                 parsers.emplace_back(Encoding::one, [this](Type::Qualifiers tq) { return new OneType(tq); });
     394                                parsers.emplace_back(Encoding::zero, [](Type::Qualifiers tq) { return new ZeroType(tq); });
     395                                parsers.emplace_back(Encoding::one, [](Type::Qualifiers tq) { return new OneType(tq); });
    396396                        }
    397397
  • src/SymTab/Mangler.cc

    r9b086ca rcde3891  
    1515#include "Mangler.h"
    1616
    17 #include <algorithm>                // for copy, transform
    18 #include <cassert>                  // for assert, assertf
    19 #include <functional>               // for const_mem_fun_t, mem_fun
    20 #include <iterator>                 // for ostream_iterator, back_insert_ite...
    21 #include <list>                     // for _List_iterator, list, _List_const...
    22 #include <string>                   // for string, char_traits, operator<<
    23 
    24 #include "CodeGen/OperatorTable.h"  // for OperatorInfo, operatorLookup
     17#include <algorithm>                     // for copy, transform
     18#include <cassert>                       // for assert, assertf
     19#include <functional>                    // for const_mem_fun_t, mem_fun
     20#include <iterator>                      // for ostream_iterator, back_insert_ite...
     21#include <list>                          // for _List_iterator, list, _List_const...
     22#include <string>                        // for string, char_traits, operator<<
     23
     24#include "CodeGen/OperatorTable.h"       // for OperatorInfo, operatorLookup
    2525#include "Common/PassVisitor.h"
    26 #include "Common/SemanticError.h"   // for SemanticError
    27 #include "Common/utility.h"         // for toString
    28 #include "Parser/LinkageSpec.h"     // for Spec, isOverridable, AutoGen, Int...
    29 #include "SynTree/Declaration.h"    // for TypeDecl, DeclarationWithType
    30 #include "SynTree/Expression.h"     // for TypeExpr, Expression, operator<<
    31 #include "SynTree/Type.h"           // for Type, ReferenceToType, Type::Fora...
     26#include "Common/SemanticError.h"        // for SemanticError
     27#include "Common/utility.h"              // for toString
     28#include "Parser/LinkageSpec.h"          // for Spec, isOverridable, AutoGen, Int...
     29#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
     30#include "SynTree/Declaration.h"         // for TypeDecl, DeclarationWithType
     31#include "SynTree/Expression.h"          // for TypeExpr, Expression, operator<<
     32#include "SynTree/Type.h"                // for Type, ReferenceToType, Type::Fora...
    3233
    3334namespace SymTab {
     
    3738                        struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler>, public WithGuards {
    3839                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
     40                                Mangler( const ResolvExpr::TypeEnvironment& env );
    3941                                Mangler( const Mangler & ) = delete;
    4042
     
    6567                          private:
    6668                                std::ostringstream mangleName;  ///< Mangled name being constructed
    67                                 typedef std::map< std::string, std::pair< int, int > > VarMapType;
     69                                typedef std::map< std::string, std::pair< std::string, int > > VarMapType;
    6870                                VarMapType varNums;             ///< Map of type variables to indices
    6971                                int nextVarNum;                 ///< Next type variable index
     72                                const ResolvExpr::TypeEnvironment* env;  ///< optional environment for substitutions
    7073                                bool isTopLevel;                ///< Is the Mangler at the top level
    7174                                bool mangleOverridable;         ///< Specially mangle overridable built-in methods
     
    7578                                bool inQualifiedType = false;   ///< Add start/end delimiters around qualified type
    7679
     80                          public:
     81                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
     82                                        int nextVarNum, const ResolvExpr::TypeEnvironment* env,
     83                                        const VarMapType& varNums );
     84
     85                          private:
    7786                                void mangleDecl( DeclarationWithType *declaration );
    7887                                void mangleRef( ReferenceToType *refType, std::string prefix );
     
    100109                }
    101110
     111                std::string mangleAssnKey( DeclarationWithType* decl,
     112                                const ResolvExpr::TypeEnvironment& env ) {
     113                        PassVisitor<Mangler> mangler( env );
     114                        maybeAccept( decl, mangler );
     115                        return mangler.pass.get_mangleName();
     116                }
     117
    102118                namespace {
    103119                        Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams )
    104                                 : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ), mangleGenericParams( mangleGenericParams ) {}
     120                                : nextVarNum( 0 ), env(nullptr), isTopLevel( true ),
     121                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
     122                                mangleGenericParams( mangleGenericParams ) {}
     123                       
     124                        Mangler::Mangler( const ResolvExpr::TypeEnvironment& env )
     125                                : nextVarNum( 0 ), env( &env ), isTopLevel( true ), mangleOverridable( false ),
     126                                typeMode( false ), mangleGenericParams( true ) {}
     127                       
     128                        Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
     129                                int nextVarNum, const ResolvExpr::TypeEnvironment* env,
     130                                const VarMapType& varNums )
     131                                : varNums( varNums ), nextVarNum( nextVarNum ), env( env ), isTopLevel( false ),
     132                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
     133                                mangleGenericParams( mangleGenericParams ) {}
    105134
    106135                        void Mangler::mangleDecl( DeclarationWithType * declaration ) {
     
    329358                                                        assert( false );
    330359                                                } // switch
    331                                                 varNums[ (*i)->name ] = std::pair< int, int >( nextVarNum++, (int)(*i)->get_kind() );
     360                                                std::string varName;
     361                                                // replace type with substitution name if environment is available and bound
     362                                                if ( env ) {
     363                                                        const ResolvExpr::EqvClass* varClass = env->lookup( (*i)->name );
     364                                                        if ( varClass && varClass->type ) {
     365                                                                PassVisitor<Mangler> sub_mangler(
     366                                                                        mangleOverridable, typeMode, mangleGenericParams, nextVarNum,
     367                                                                        env, varNums );
     368                                                                varClass->type->accept( sub_mangler );
     369                                                                varName = std::string{"%"} + sub_mangler.pass.get_mangleName();
     370                                                        }
     371                                                }
     372                                                // otherwise just give type numeric name
     373                                                if ( varName.empty() ) {
     374                                                        varName = std::to_string( nextVarNum++ );
     375                                                }
     376                                                varNums[ (*i)->name ] = std::make_pair( varName, (int)(*i)->get_kind() );
    332377                                                for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) {
    333                                                         PassVisitor<Mangler> sub_mangler( mangleOverridable, typeMode, mangleGenericParams );
    334                                                         sub_mangler.pass.nextVarNum = nextVarNum;
    335                                                         sub_mangler.pass.isTopLevel = false;
    336                                                         sub_mangler.pass.varNums = varNums;
     378                                                        PassVisitor<Mangler> sub_mangler(
     379                                                                mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env,
     380                                                                varNums );
    337381                                                        (*assert)->accept( sub_mangler );
    338                                                         assertionNames.push_back( sub_mangler.pass.mangleName.str() );
     382                                                        assertionNames.push_back( sub_mangler.pass.get_mangleName() );
    339383                                                        acount++;
    340384                                                } // for
  • src/SymTab/Mangler.h

    r9b086ca rcde3891  
    3131// * Currently name compression is not implemented.
    3232
     33namespace ResolvExpr {
     34        class TypeEnvironment;
     35}
     36
    3337namespace SymTab {
    3438        namespace Mangler {
     
    4044                /// Mangle ignoring generic type parameters
    4145                std::string mangleConcrete( Type* ty );
     46                /// Mangle for assertion key
     47                std::string mangleAssnKey( DeclarationWithType* decl,
     48                        const ResolvExpr::TypeEnvironment& env );
    4249
    4350                namespace Encoding {
  • src/SymTab/Validate.cc

    r9b086ca rcde3891  
    398398                        assert( aggr ); // TODO: need to handle forward declarations
    399399                        for ( Declaration * member : aggr->members ) {
    400                                 if ( StructInstType * inst = dynamic_cast< StructInstType * >( child ) ) {
    401                                         if ( StructDecl * aggr = dynamic_cast< StructDecl * >( member ) ) {
    402                                                 if ( aggr->name == inst->name ) {
    403                                                         // TODO: is this case, and other non-TypeInstType cases, necessary?
    404                                                         return new StructInstType( qualType->get_qualifiers(), aggr );
    405                                                 }
    406                                         }
    407                                 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( child ) ) {
    408                                         if ( UnionDecl * aggr = dynamic_cast< UnionDecl * > ( member ) ) {
    409                                                 if ( aggr->name == inst->name ) {
    410                                                         return new UnionInstType( qualType->get_qualifiers(), aggr );
    411                                                 }
    412                                         }
    413                                 } else if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( child ) ) {
    414                                         if ( EnumDecl * aggr = dynamic_cast< EnumDecl * > ( member ) ) {
    415                                                 if ( aggr->name == inst->name ) {
    416                                                         return new EnumInstType( qualType->get_qualifiers(), aggr );
    417                                                 }
    418                                         }
    419                                 } else if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
     400                                if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
    420401                                        // name on the right is a typedef
    421402                                        if ( NamedTypeDecl * aggr = dynamic_cast< NamedTypeDecl * > ( member ) ) {
     
    424405                                                        Type * ret = aggr->base->clone();
    425406                                                        ret->get_qualifiers() = qualType->get_qualifiers();
     407                                                        TypeSubstitution sub = parent->genericSubstitution();
     408                                                        sub.apply(ret);
    426409                                                        return ret;
    427410                                                }
Note: See TracChangeset for help on using the changeset viewer.