Changeset 2b79a70


Ignore:
Timestamp:
Aug 21, 2018, 2:21:53 PM (3 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer
Children:
cdbab55
Parents:
51fcdbc7
git-author:
Rob Schluntz <rschlunt@…> (08/21/18 13:23:01)
git-committer:
Rob Schluntz <rschlunt@…> (08/21/18 14:21:53)
Message:

Resolve typeof earlier so that constructors are chosen appropriately [fixes #102]

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r51fcdbc7 r2b79a70  
    3030#include "RenameVars.h"                  // for RenameVars, global_renamer
    3131#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    32 #include "ResolveTypeof.h"               // for resolveTypeof
    3332#include "Resolver.h"
    3433#include "SymTab/Autogen.h"              // for SizeType
     
    5756                void postvisit( FunctionDecl *functionDecl );
    5857                void previsit( ObjectDecl *objectDecll );
    59                 void previsit( TypeDecl *typeDecl );
    6058                void previsit( EnumDecl * enumDecl );
    6159                void previsit( StaticAssertDecl * assertDecl );
     
    303301
    304302        void Resolver::previsit( ObjectDecl *objectDecl ) {
    305                 Type *new_type = resolveTypeof( objectDecl->get_type(), indexer );
    306                 new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    307                 objectDecl->set_type( new_type );
    308303                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable
    309304                // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes
     
    335330        }
    336331
    337         void Resolver::previsit( TypeDecl *typeDecl ) {
    338                 if ( typeDecl->get_base() ) {
    339                         Type *new_type = resolveTypeof( typeDecl->get_base(), indexer );
    340                         typeDecl->set_base( new_type );
    341                 } // if
    342         }
    343 
    344332        void Resolver::previsit( FunctionDecl *functionDecl ) {
    345333#if 0
     
    348336                std::cerr << std::endl;
    349337#endif
    350                 Type *new_type = resolveTypeof( functionDecl->type, indexer );
    351                 functionDecl->set_type( new_type );
    352338                GuardValue( functionReturn );
    353339                functionReturn = ResolvExpr::extractResultType( functionDecl->type );
  • src/SymTab/Validate.cc

    r51fcdbc7 r2b79a70  
    6262#include "ResolvExpr/typeops.h"        // for typesCompatible
    6363#include "ResolvExpr/Resolver.h"       // for findSingleExpression
     64#include "ResolvExpr/ResolveTypeof.h"  // for resolveTypeof
    6465#include "SymTab/Autogen.h"            // for SizeType
    6566#include "SynTree/Attribute.h"         // for noAttributes, Attribute
     
    247248                void previsit( StructInstType * inst );
    248249                void previsit( UnionInstType * inst );
     250        };
     251
     252        struct FixObjectType : public WithIndexer {
     253                /// resolves typeof type in object, function, and type declarations
     254                static void fix( std::list< Declaration * > & translationUnit );
     255
     256                void previsit( ObjectDecl * );
     257                void previsit( FunctionDecl * );
     258                void previsit( TypeDecl * );
    249259        };
    250260
     
    312322                Concurrency::implementThreadStarter( translationUnit );
    313323                mutateAll( translationUnit, compoundliteral );
     324                FixObjectType::fix( translationUnit );
    314325                ArrayLength::computeLength( translationUnit );
    315326                acceptAll( translationUnit, finder ); // xxx - remove this pass soon
     
    12381249        }
    12391250
     1251        void FixObjectType::fix( std::list< Declaration * > & translationUnit ) {
     1252                PassVisitor<FixObjectType> fixer;
     1253                acceptAll( translationUnit, fixer );
     1254        }
     1255
     1256        void FixObjectType::previsit( ObjectDecl * objDecl ) {
     1257                Type *new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
     1258                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
     1259                objDecl->set_type( new_type );
     1260        }
     1261
     1262        void FixObjectType::previsit( FunctionDecl * funcDecl ) {
     1263                Type *new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
     1264                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
     1265                funcDecl->set_type( new_type );
     1266        }
     1267
     1268        void FixObjectType::previsit( TypeDecl *typeDecl ) {
     1269                if ( typeDecl->get_base() ) {
     1270                        Type *new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
     1271                        new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
     1272                        typeDecl->set_base( new_type );
     1273                } // if
     1274        }
     1275
    12401276        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
    12411277                PassVisitor<ArrayLength> len;
  • src/tests/.expect/gccExtensions.x64.txt

    r51fcdbc7 r2b79a70  
    2929    volatile signed int __v1__Vi_2;
    3030    volatile signed int __v2__Vi_2;
    31     signed int __t1___2;
    32     signed int __t2___2;
     31    signed int __t1__i_2;
     32    signed int __t2__i_2;
    3333    __extension__ const signed int __ex__Ci_2;
    3434    struct S {
  • src/tests/.expect/gccExtensions.x86.txt

    r51fcdbc7 r2b79a70  
    2929    volatile signed int __v1__Vi_2;
    3030    volatile signed int __v2__Vi_2;
    31     signed int __t1___2;
    32     signed int __t2___2;
     31    signed int __t1__i_2;
     32    signed int __t2__i_2;
    3333    __extension__ const signed int __ex__Ci_2;
    3434    struct S {
Note: See TracChangeset for help on using the changeset viewer.