Changeset 74ec742 for src/SymTab


Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (4 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (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/SymTab
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    r29d8c02 r74ec742  
    2121
    2222#include "AST/Decl.hpp"
    23 #include "AST/Eval.hpp"
    2423#include "AST/Expr.hpp"
    2524#include "AST/Init.hpp"
     
    7170        template< typename OutIter >
    7271        ast::ptr< ast::Stmt > genCall(
    73                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    74                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
     72                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     73                const CodeLocation & loc, const std::string & fname, OutIter && out,
    7574                const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
    7675
     
    128127        }
    129128
    130         /// inserts into out a generated call expression to function fname with arguments dstParam and 
     129        /// inserts into out a generated call expression to function fname with arguments dstParam and
    131130        /// srcParam. Should only be called with non-array types.
    132         /// optionally returns a statement which must be inserted prior to the containing loop, if 
     131        /// optionally returns a statement which must be inserted prior to the containing loop, if
    133132        /// there is one
    134133        template< typename OutIter >
    135         ast::ptr< ast::Stmt > genScalarCall( 
    136                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    137                 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 
     134        ast::ptr< ast::Stmt > genScalarCall(
     135                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     136                const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type,
    138137                const ast::Type * addCast = nullptr
    139138        ) {
     
    153152
    154153                if ( addCast ) {
    155                         // cast to T& with qualifiers removed, so that qualified objects can be constructed and 
    156                         // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 
    157                         // is considered a qualifier - for AddressExpr to resolve, its argument must have an 
     154                        // cast to T& with qualifiers removed, so that qualified objects can be constructed and
     155                        // destructed with the same functions as non-qualified objects. Unfortunately, lvalue
     156                        // is considered a qualifier - for AddressExpr to resolve, its argument must have an
    158157                        // lvalue-qualified type, so remove all qualifiers except lvalue.
    159158                        // xxx -- old code actually removed lvalue too...
    160159                        ast::ptr< ast::Type > guard = addCast;  // prevent castType from mutating addCast
    161160                        ast::ptr< ast::Type > castType = addCast;
    162                         ast::remove_qualifiers( 
    163                                 castType, 
     161                        ast::remove_qualifiers(
     162                                castType,
    164163                                ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic );
    165164                        dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } };
     
    181180
    182181                srcParam.clearArrayIndices();
    183                
     182
    184183                return listInit;
    185184        }
     
    249248        }
    250249
    251         /// Store in out a loop which calls fname on each element of the array with srcParam and 
     250        /// Store in out a loop which calls fname on each element of the array with srcParam and
    252251        /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0
    253252        template< typename OutIter >
    254253        void genArrayCall(
    255                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    256                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
    257                 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 
    258                 LoopDirection forward = LoopForward 
     254                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     255                const CodeLocation & loc, const std::string & fname, OutIter && out,
     256                const ast::ArrayType * array, const ast::Type * addCast = nullptr,
     257                LoopDirection forward = LoopForward
    259258        ) {
    260259                static UniqueName indexName( "_index" );
     
    279278                } else {
    280279                        // generate: for ( int i = N-1; i >= 0; --i )
    281                         begin = ast::call(
    282                                 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ) );
     280                        begin = ast::UntypedExpr::createCall( loc, "?-?",
     281                                { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } );
    283282                        end = ast::ConstantExpr::from_int( loc, 0 );
    284283                        cmp = "?>=?";
     
    286285                }
    287286
    288                 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 
    289                         loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 
     287                ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{
     288                        loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt },
    290289                        new ast::SingleInit{ loc, begin } };
    291290                ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index };
    292                
    293                 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end );
    294                
    295                 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar );
    296                
    297                 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar );
    298                
    299                 // srcParam must keep track of the array indices to build the source parameter and/or
     291
     292                ast::ptr< ast::Expr > cond = ast::UntypedExpr::createCall(
     293                        loc, cmp, { indexVar, end } );
     294
     295                ast::ptr< ast::Expr > inc = ast::UntypedExpr::createCall(
     296                        loc, update, { indexVar } );
     297
     298                ast::ptr< ast::Expr > dstIndex = ast::UntypedExpr::createCall(
     299                        loc, "?[?]", { dstParam, indexVar } );
     300
     301                // srcParam must keep track of the array indices to build the source parameter and/or
    300302                // array list initializer
    301303                srcParam.addArrayIndex( indexVar, array->dimension );
     
    303305                // for stmt's body, eventually containing call
    304306                ast::CompoundStmt * body = new ast::CompoundStmt{ loc };
    305                 ast::ptr< ast::Stmt > listInit = genCall( 
    306                         srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 
     307                ast::ptr< ast::Stmt > listInit = genCall(
     308                        srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast,
    307309                        forward );
    308                
     310
    309311                // block containing the stmt and index variable
    310312                ast::CompoundStmt * block = new ast::CompoundStmt{ loc };
     
    328330        template< typename OutIter >
    329331        ast::ptr< ast::Stmt > genCall(
    330                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    331                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
     332                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     333                const CodeLocation & loc, const std::string & fname, OutIter && out,
    332334                const ast::Type * type, const ast::Type * addCast, LoopDirection forward
    333335        ) {
    334336                if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    335                         genArrayCall( 
    336                                 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 
     337                        genArrayCall(
     338                                srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
    337339                                forward );
    338340                        return {};
    339341                } else {
    340                         return genScalarCall( 
     342                        return genScalarCall(
    341343                                srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
    342344                }
     
    377379        }
    378380
    379         static inline ast::ptr< ast::Stmt > genImplicitCall( 
    380                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    381                 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 
    382                 LoopDirection forward = LoopForward 
     381        static inline ast::ptr< ast::Stmt > genImplicitCall(
     382                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     383                const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
     384                LoopDirection forward = LoopForward
    383385        ) {
    384386                // unnamed bit fields are not copied as they cannot be accessed
     
    392394
    393395                std::vector< ast::ptr< ast::Stmt > > stmts;
    394                 genCall( 
     396                genCall(
    395397                        srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
    396398
     
    400402                        const ast::Stmt * callStmt = stmts.front();
    401403                        if ( addCast ) {
    402                                 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 
     404                                // implicitly generated ctor/dtor calls should be wrapped so that later passes are
    403405                                // aware they were generated.
    404406                                callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt };
     
    417419// compile-command: "make install" //
    418420// End: //
    419 
  • src/SymTab/Demangle.cc

    r29d8c02 r74ec742  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Demangler.cc --
     7// Demangle.cc -- Convert a mangled name into a human readable name.
    88//
    99// Author           : Rob Schluntz
  • src/SymTab/Mangler.h

    r29d8c02 r74ec742  
    111111}
    112112
    113 extern "C" {
    114         char * cforall_demangle(const char *, int);
    115 }
    116 
    117113// Local Variables: //
    118114// tab-width: 4 //
  • src/SymTab/Validate.cc

    r29d8c02 r74ec742  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Nov 12 11:00:00 2021
    13 // Update Count     : 364
     12// Last Modified On : Tue May 17 14:36:00 2022
     13// Update Count     : 366
    1414//
    1515
     
    7474#include "ResolvExpr/ResolveTypeof.h"  // for resolveTypeof
    7575#include "SymTab/Autogen.h"            // for SizeType
     76#include "SymTab/ValidateType.h"       // for decayEnumsAndPointers, decayFo...
    7677#include "SynTree/LinkageSpec.h"       // for C
    7778#include "SynTree/Attribute.h"         // for noAttributes, Attribute
     
    134135        };
    135136
    136         /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    137         struct EnumAndPointerDecay_old {
    138                 void previsit( EnumDecl * aggregateDecl );
    139                 void previsit( FunctionType * func );
    140         };
    141 
    142         /// Associates forward declarations of aggregates with their definitions
    143         struct LinkReferenceToTypes_old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {
    144                 LinkReferenceToTypes_old( const Indexer * indexer );
    145                 void postvisit( TypeInstType * typeInst );
    146 
    147                 void postvisit( EnumInstType * enumInst );
    148                 void postvisit( StructInstType * structInst );
    149                 void postvisit( UnionInstType * unionInst );
    150                 void postvisit( TraitInstType * traitInst );
    151                 void previsit( QualifiedType * qualType );
    152                 void postvisit( QualifiedType * qualType );
    153 
    154                 void postvisit( EnumDecl * enumDecl );
    155                 void postvisit( StructDecl * structDecl );
    156                 void postvisit( UnionDecl * unionDecl );
    157                 void postvisit( TraitDecl * traitDecl );
    158 
    159                 void previsit( StructDecl * structDecl );
    160                 void previsit( UnionDecl * unionDecl );
    161 
    162                 void renameGenericParams( std::list< TypeDecl * > & params );
    163 
    164           private:
    165                 const Indexer * local_indexer;
    166 
    167                 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
    168                 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
    169                 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
    170                 ForwardEnumsType forwardEnums;
    171                 ForwardStructsType forwardStructs;
    172                 ForwardUnionsType forwardUnions;
    173                 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately
    174                 bool inGeneric = false;
    175         };
    176 
    177137        /// Does early resolution on the expressions that give enumeration constants their values
    178138        struct ResolveEnumInitializers final : public WithIndexer, public WithGuards, public WithVisitorRef<ResolveEnumInitializers>, public WithShortCircuiting {
     
    192152                void previsit( StructDecl * aggrDecl );
    193153                void previsit( UnionDecl * aggrDecl );
    194         };
    195 
    196         // These structs are the sub-sub-passes of ForallPointerDecay_old.
    197 
    198         struct TraitExpander_old final {
    199                 void previsit( FunctionType * );
    200                 void previsit( StructDecl * );
    201                 void previsit( UnionDecl * );
    202         };
    203 
    204         struct AssertionFixer_old final {
    205                 void previsit( FunctionType * );
    206                 void previsit( StructDecl * );
    207                 void previsit( UnionDecl * );
    208         };
    209 
    210         struct CheckOperatorTypes_old final {
    211                 void previsit( ObjectDecl * );
    212         };
    213 
    214         struct FixUniqueIds_old final {
    215                 void previsit( DeclarationWithType * );
    216154        };
    217155
     
    357295
    358296        void validate_A( std::list< Declaration * > & translationUnit ) {
    359                 PassVisitor<EnumAndPointerDecay_old> epc;
    360297                PassVisitor<HoistTypeDecls> hoistDecls;
    361298                {
     
    366303                        ReplaceTypedef::replaceTypedef( translationUnit );
    367304                        ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
    368                         acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling
     305                        decayEnumsAndPointers( translationUnit ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling
    369306                }
    370307        }
    371308
    372309        void validate_B( std::list< Declaration * > & translationUnit ) {
    373                 PassVisitor<LinkReferenceToTypes_old> lrt( nullptr );
    374310                PassVisitor<FixQualifiedTypes> fixQual;
    375311                {
    376312                        Stats::Heap::newPass("validate-B");
    377313                        Stats::Time::BlockGuard guard("validate-B");
    378                         acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
     314                        //linkReferenceToTypes( translationUnit );
    379315                        mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed
    380316                        HoistStruct::hoistStruct( translationUnit );
     
    407343                        });
    408344                }
    409         }
    410 
    411         static void decayForallPointers( std::list< Declaration * > & translationUnit ) {
    412                 PassVisitor<TraitExpander_old> te;
    413                 acceptAll( translationUnit, te );
    414                 PassVisitor<AssertionFixer_old> af;
    415                 acceptAll( translationUnit, af );
    416                 PassVisitor<CheckOperatorTypes_old> cot;
    417                 acceptAll( translationUnit, cot );
    418                 PassVisitor<FixUniqueIds_old> fui;
    419                 acceptAll( translationUnit, fui );
    420345        }
    421346
     
    496421        }
    497422
    498         void validateType( Type * type, const Indexer * indexer ) {
    499                 PassVisitor<EnumAndPointerDecay_old> epc;
    500                 PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
    501                 PassVisitor<TraitExpander_old> te;
    502                 PassVisitor<AssertionFixer_old> af;
    503                 PassVisitor<CheckOperatorTypes_old> cot;
    504                 PassVisitor<FixUniqueIds_old> fui;
    505                 type->accept( epc );
    506                 type->accept( lrt );
    507                 type->accept( te );
    508                 type->accept( af );
    509                 type->accept( cot );
    510                 type->accept( fui );
    511         }
    512 
    513423        void HoistTypeDecls::handleType( Type * type ) {
    514424                // some type declarations are buried in expressions and not easy to hoist during parsing; hoist them here
     
    703613        }
    704614
    705         void EnumAndPointerDecay_old::previsit( EnumDecl * enumDecl ) {
    706                 // Set the type of each member of the enumeration to be EnumConstant
    707                 for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) {
    708                         ObjectDecl * obj = dynamic_cast< ObjectDecl * >( * i );
    709                         assert( obj );
    710                         obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->name ) );
    711                 } // for
    712         }
    713 
    714         namespace {
    715                 template< typename DWTList >
    716                 void fixFunctionList( DWTList & dwts, bool isVarArgs, FunctionType * func ) {
    717                         auto nvals = dwts.size();
    718                         bool containsVoid = false;
    719                         for ( auto & dwt : dwts ) {
    720                                 // fix each DWT and record whether a void was found
    721                                 containsVoid |= fixFunction( dwt );
    722                         }
    723 
    724                         // the only case in which "void" is valid is where it is the only one in the list
    725                         if ( containsVoid && ( nvals > 1 || isVarArgs ) ) {
    726                                 SemanticError( func, "invalid type void in function type " );
    727                         }
    728 
    729                         // one void is the only thing in the list; remove it.
    730                         if ( containsVoid ) {
    731                                 delete dwts.front();
    732                                 dwts.clear();
    733                         }
    734                 }
    735         }
    736 
    737         void EnumAndPointerDecay_old::previsit( FunctionType * func ) {
    738                 // Fix up parameters and return types
    739                 fixFunctionList( func->parameters, func->isVarArgs, func );
    740                 fixFunctionList( func->returnVals, false, func );
    741         }
    742 
    743         LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) : WithIndexer( false ) {
    744                 if ( other_indexer ) {
    745                         local_indexer = other_indexer;
    746                 } else {
    747                         local_indexer = &indexer;
    748                 } // if
    749         }
    750 
    751         void LinkReferenceToTypes_old::postvisit( EnumInstType * enumInst ) {
    752                 const EnumDecl * st = local_indexer->lookupEnum( enumInst->name );
    753                 // it's not a semantic error if the enum is not found, just an implicit forward declaration
    754                 if ( st ) {
    755                         enumInst->baseEnum = const_cast<EnumDecl *>(st); // Just linking in the node
    756                 } // if
    757                 if ( ! st || ! st->body ) {
    758                         // use of forward declaration
    759                         forwardEnums[ enumInst->name ].push_back( enumInst );
    760                 } // if
    761         }
    762 
    763         void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {
    764                 const StructDecl * st = local_indexer->lookupStruct( structInst->name );
    765                 // it's not a semantic error if the struct is not found, just an implicit forward declaration
    766                 if ( st ) {
    767                         structInst->baseStruct = const_cast<StructDecl *>(st); // Just linking in the node
    768                 } // if
    769                 if ( ! st || ! st->body ) {
    770                         // use of forward declaration
    771                         forwardStructs[ structInst->name ].push_back( structInst );
    772                 } // if
    773         }
    774 
    775         void LinkReferenceToTypes_old::postvisit( UnionInstType * unionInst ) {
    776                 const UnionDecl * un = local_indexer->lookupUnion( unionInst->name );
    777                 // it's not a semantic error if the union is not found, just an implicit forward declaration
    778                 if ( un ) {
    779                         unionInst->baseUnion = const_cast<UnionDecl *>(un); // Just linking in the node
    780                 } // if
    781                 if ( ! un || ! un->body ) {
    782                         // use of forward declaration
    783                         forwardUnions[ unionInst->name ].push_back( unionInst );
    784                 } // if
    785         }
    786 
    787         void LinkReferenceToTypes_old::previsit( QualifiedType * ) {
    788                 visit_children = false;
    789         }
    790 
    791         void LinkReferenceToTypes_old::postvisit( QualifiedType * qualType ) {
    792                 // linking only makes sense for the 'oldest ancestor' of the qualified type
    793                 qualType->parent->accept( * visitor );
    794         }
    795 
    796         template< typename Decl >
    797         void normalizeAssertions( std::list< Decl * > & assertions ) {
    798                 // ensure no duplicate trait members after the clone
    799                 auto pred = [](Decl * d1, Decl * d2) {
    800                         // only care if they're equal
    801                         DeclarationWithType * dwt1 = dynamic_cast<DeclarationWithType *>( d1 );
    802                         DeclarationWithType * dwt2 = dynamic_cast<DeclarationWithType *>( d2 );
    803                         if ( dwt1 && dwt2 ) {
    804                                 if ( dwt1->name == dwt2->name && ResolvExpr::typesCompatible( dwt1->get_type(), dwt2->get_type(), SymTab::Indexer() ) ) {
    805                                         // std::cerr << "=========== equal:" << std::endl;
    806                                         // std::cerr << "d1: " << d1 << std::endl;
    807                                         // std::cerr << "d2: " << d2 << std::endl;
    808                                         return false;
    809                                 }
    810                         }
    811                         return d1 < d2;
    812                 };
    813                 std::set<Decl *, decltype(pred)> unique_members( assertions.begin(), assertions.end(), pred );
    814                 // if ( unique_members.size() != assertions.size() ) {
    815                 //      std::cerr << "============different" << std::endl;
    816                 //      std::cerr << unique_members.size() << " " << assertions.size() << std::endl;
    817                 // }
    818 
    819                 std::list< Decl * > order;
    820                 order.splice( order.end(), assertions );
    821                 std::copy_if( order.begin(), order.end(), back_inserter( assertions ), [&]( Decl * decl ) {
    822                         return unique_members.count( decl );
    823                 });
    824         }
    825 
    826615        // expand assertions from trait instance, performing the appropriate type variable substitutions
    827616        template< typename Iterator >
     
    834623                // substitute trait decl parameters for instance parameters
    835624                applySubstitution( inst->baseTrait->parameters.begin(), inst->baseTrait->parameters.end(), inst->parameters.begin(), asserts.begin(), asserts.end(), out );
    836         }
    837 
    838         void LinkReferenceToTypes_old::postvisit( TraitDecl * traitDecl ) {
    839                 if ( traitDecl->name == "sized" ) {
    840                         // "sized" is a special trait - flick the sized status on for the type variable
    841                         assertf( traitDecl->parameters.size() == 1, "Built-in trait 'sized' has incorrect number of parameters: %zd", traitDecl->parameters.size() );
    842                         TypeDecl * td = traitDecl->parameters.front();
    843                         td->set_sized( true );
    844                 }
    845 
    846                 // move assertions from type parameters into the body of the trait
    847                 for ( TypeDecl * td : traitDecl->parameters ) {
    848                         for ( DeclarationWithType * assert : td->assertions ) {
    849                                 if ( TraitInstType * inst = dynamic_cast< TraitInstType * >( assert->get_type() ) ) {
    850                                         expandAssertions( inst, back_inserter( traitDecl->members ) );
    851                                 } else {
    852                                         traitDecl->members.push_back( assert->clone() );
    853                                 }
    854                         }
    855                         deleteAll( td->assertions );
    856                         td->assertions.clear();
    857                 } // for
    858         }
    859 
    860         void LinkReferenceToTypes_old::postvisit( TraitInstType * traitInst ) {
    861                 // handle other traits
    862                 const TraitDecl * traitDecl = local_indexer->lookupTrait( traitInst->name );
    863                 if ( ! traitDecl ) {
    864                         SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
    865                 } // if
    866                 if ( traitDecl->parameters.size() != traitInst->parameters.size() ) {
    867                         SemanticError( traitInst, "incorrect number of trait parameters: " );
    868                 } // if
    869                 traitInst->baseTrait = const_cast<TraitDecl *>(traitDecl); // Just linking in the node
    870 
    871                 // need to carry over the 'sized' status of each decl in the instance
    872                 for ( auto p : group_iterate( traitDecl->parameters, traitInst->parameters ) ) {
    873                         TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );
    874                         if ( ! expr ) {
    875                                 SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );
    876                         }
    877                         if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
    878                                 TypeDecl * formalDecl = std::get<0>(p);
    879                                 TypeDecl * instDecl = inst->baseType;
    880                                 if ( formalDecl->get_sized() ) instDecl->set_sized( true );
    881                         }
    882                 }
    883                 // normalizeAssertions( traitInst->members );
    884         }
    885 
    886         void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {
    887                 // visit enum members first so that the types of self-referencing members are updated properly
    888                 if ( enumDecl->body ) {
    889                         ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->name );
    890                         if ( fwds != forwardEnums.end() ) {
    891                                 for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    892                                         (* inst)->baseEnum = enumDecl;
    893                                 } // for
    894                                 forwardEnums.erase( fwds );
    895                         } // if
    896                 } // if
    897         }
    898 
    899         void LinkReferenceToTypes_old::renameGenericParams( std::list< TypeDecl * > & params ) {
    900                 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g.
    901                 //   forall(otype T)
    902                 //   struct Box {
    903                 //     T x;
    904                 //   };
    905                 //   forall(otype T)
    906                 //   void f(Box(T) b) {
    907                 //     ...
    908                 //   }
    909                 // The T in Box and the T in f are different, so internally the naming must reflect that.
    910                 GuardValue( inGeneric );
    911                 inGeneric = ! params.empty();
    912                 for ( TypeDecl * td : params ) {
    913                         td->name = "__" + td->name + "_generic_";
    914                 }
    915         }
    916 
    917         void LinkReferenceToTypes_old::previsit( StructDecl * structDecl ) {
    918                 renameGenericParams( structDecl->parameters );
    919         }
    920 
    921         void LinkReferenceToTypes_old::previsit( UnionDecl * unionDecl ) {
    922                 renameGenericParams( unionDecl->parameters );
    923         }
    924 
    925         void LinkReferenceToTypes_old::postvisit( StructDecl * structDecl ) {
    926                 // visit struct members first so that the types of self-referencing members are updated properly
    927                 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)
    928                 if ( structDecl->body ) {
    929                         ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->name );
    930                         if ( fwds != forwardStructs.end() ) {
    931                                 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    932                                         (* inst)->baseStruct = structDecl;
    933                                 } // for
    934                                 forwardStructs.erase( fwds );
    935                         } // if
    936                 } // if
    937         }
    938 
    939         void LinkReferenceToTypes_old::postvisit( UnionDecl * unionDecl ) {
    940                 if ( unionDecl->body ) {
    941                         ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name );
    942                         if ( fwds != forwardUnions.end() ) {
    943                                 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    944                                         (* inst)->baseUnion = unionDecl;
    945                                 } // for
    946                                 forwardUnions.erase( fwds );
    947                         } // if
    948                 } // if
    949         }
    950 
    951         void LinkReferenceToTypes_old::postvisit( TypeInstType * typeInst ) {
    952                 // ensure generic parameter instances are renamed like the base type
    953                 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;
    954                 if ( const NamedTypeDecl * namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {
    955                         if ( const TypeDecl * typeDecl = dynamic_cast< const TypeDecl * >( namedTypeDecl ) ) {
    956                                 typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );
    957                         } // if
    958                 } // if
    959625        }
    960626
     
    985651                                                }
    986652                                        }
    987                                        
    988653                                }
    989654                        }
     
    1073738        void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) {
    1074739                forallFixer( aggrDecl->parameters, aggrDecl );
    1075         }
    1076 
    1077         void TraitExpander_old::previsit( FunctionType * ftype ) {
    1078                 expandTraits( ftype->forall );
    1079         }
    1080 
    1081         void TraitExpander_old::previsit( StructDecl * aggrDecl ) {
    1082                 expandTraits( aggrDecl->parameters );
    1083         }
    1084 
    1085         void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {
    1086                 expandTraits( aggrDecl->parameters );
    1087         }
    1088 
    1089         void AssertionFixer_old::previsit( FunctionType * ftype ) {
    1090                 fixAssertions( ftype->forall, ftype );
    1091         }
    1092 
    1093         void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {
    1094                 fixAssertions( aggrDecl->parameters, aggrDecl );
    1095         }
    1096 
    1097         void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {
    1098                 fixAssertions( aggrDecl->parameters, aggrDecl );
    1099         }
    1100 
    1101         void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {
    1102                 // ensure that operator names only apply to functions or function pointers
    1103                 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
    1104                         SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." )  );
    1105                 }
    1106         }
    1107 
    1108         void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {
    1109                 decl->fixUniqueId();
    1110740        }
    1111741
  • src/SymTab/Validate.h

    r29d8c02 r74ec742  
    1010// Author           : Richard C. Bilson
    1111// Created On       : Sun May 17 21:53:34 2015
    12 // Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sat Jul 22 09:46:07 2017
    14 // Update Count     : 4
     12// Last Modified By : Andrew Beach
     13// Last Modified On : Tue May 17 14:35:00 2022
     14// Update Count     : 5
    1515//
    1616
     
    3333        /// Normalizes struct and function declarations
    3434        void validate( std::list< Declaration * > &translationUnit, bool doDebug = false );
    35         void validateType( Type *type, const Indexer *indexer );
    3635
    3736        // Sub-passes of validate.
     
    4241        void validate_E( std::list< Declaration * > &translationUnit );
    4342        void validate_F( std::list< Declaration * > &translationUnit );
    44 
    45         const ast::Type * validateType(
    46                 const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab );
    4743} // namespace SymTab
    4844
  • src/SymTab/demangler.cc

    r29d8c02 r74ec742  
    1 #include "Mangler.h"
     1#include "Demangle.h"
    22#include <iostream>
    33#include <fstream>
  • src/SymTab/module.mk

    r29d8c02 r74ec742  
    1111## Created On       : Mon Jun  1 17:49:17 2015
    1212## Last Modified By : Andrew Beach
    13 ## Last Modified On : Thr Aug 10 16:08:00 2017
    14 ## Update Count     : 4
     13## Last Modified On : Tue May 17 14:46:00 2022
     14## Update Count     : 5
    1515###############################################################################
    1616
    1717SRC_SYMTAB = \
    18       SymTab/Autogen.cc \
    19       SymTab/Autogen.h \
    20       SymTab/FixFunction.cc \
    21       SymTab/FixFunction.h \
    22       SymTab/Indexer.cc \
    23       SymTab/Indexer.h \
    24       SymTab/Mangler.cc \
    25       SymTab/ManglerCommon.cc \
    26       SymTab/Mangler.h \
    27       SymTab/Validate.cc \
    28       SymTab/Validate.h
     18        SymTab/Autogen.cc \
     19        SymTab/Autogen.h \
     20        SymTab/FixFunction.cc \
     21        SymTab/FixFunction.h \
     22        SymTab/Indexer.cc \
     23        SymTab/Indexer.h \
     24        SymTab/Mangler.cc \
     25        SymTab/ManglerCommon.cc \
     26        SymTab/Mangler.h \
     27        SymTab/ValidateType.cc \
     28        SymTab/ValidateType.h
    2929
    30 SRC += $(SRC_SYMTAB)
    31 SRCDEMANGLE += $(SRC_SYMTAB) SymTab/Demangle.cc
     30SRC += $(SRC_SYMTAB) \
     31        SymTab/Validate.cc \
     32        SymTab/Validate.h
     33
     34SRCDEMANGLE += $(SRC_SYMTAB) \
     35        SymTab/Demangle.cc \
     36        SymTab/Demangle.h
Note: See TracChangeset for help on using the changeset viewer.