Ignore:
Timestamp:
Sep 25, 2018, 11:35:34 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
c6bbcdb
Parents:
341bb80 (diff), 7428ad9 (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 shared_library

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r341bb80 r6d44da1  
    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                ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables
     325                FixObjectType::fix( translationUnit );
    314326                ArrayLength::computeLength( translationUnit );
    315327                acceptAll( translationUnit, finder ); // xxx - remove this pass soon
     
    391403                        assert( aggr ); // TODO: need to handle forward declarations
    392404                        for ( Declaration * member : aggr->members ) {
    393                                 if ( StructInstType * inst = dynamic_cast< StructInstType * >( child ) ) {
    394                                         if ( StructDecl * aggr = dynamic_cast< StructDecl * >( member ) ) {
    395                                                 if ( aggr->name == inst->name ) {
    396                                                         // TODO: is this case, and other non-TypeInstType cases, necessary?
    397                                                         return new StructInstType( qualType->get_qualifiers(), aggr );
    398                                                 }
    399                                         }
    400                                 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( child ) ) {
    401                                         if ( UnionDecl * aggr = dynamic_cast< UnionDecl * > ( member ) ) {
    402                                                 if ( aggr->name == inst->name ) {
    403                                                         return new UnionInstType( qualType->get_qualifiers(), aggr );
    404                                                 }
    405                                         }
    406                                 } else if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( child ) ) {
    407                                         if ( EnumDecl * aggr = dynamic_cast< EnumDecl * > ( member ) ) {
    408                                                 if ( aggr->name == inst->name ) {
    409                                                         return new EnumInstType( qualType->get_qualifiers(), aggr );
    410                                                 }
    411                                         }
    412                                 } else if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
     405                                if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
    413406                                        // name on the right is a typedef
    414407                                        if ( NamedTypeDecl * aggr = dynamic_cast< NamedTypeDecl * > ( member ) ) {
     
    417410                                                        Type * ret = aggr->base->clone();
    418411                                                        ret->get_qualifiers() = qualType->get_qualifiers();
     412                                                        TypeSubstitution sub = parent->genericSubstitution();
     413                                                        sub.apply(ret);
    419414                                                        return ret;
    420415                                                }
     
    12381233        }
    12391234
     1235        void FixObjectType::fix( std::list< Declaration * > & translationUnit ) {
     1236                PassVisitor<FixObjectType> fixer;
     1237                acceptAll( translationUnit, fixer );
     1238        }
     1239
     1240        void FixObjectType::previsit( ObjectDecl * objDecl ) {
     1241                Type *new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
     1242                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
     1243                objDecl->set_type( new_type );
     1244        }
     1245
     1246        void FixObjectType::previsit( FunctionDecl * funcDecl ) {
     1247                Type *new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
     1248                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
     1249                funcDecl->set_type( new_type );
     1250        }
     1251
     1252        void FixObjectType::previsit( TypeDecl *typeDecl ) {
     1253                if ( typeDecl->get_base() ) {
     1254                        Type *new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
     1255                        new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
     1256                        typeDecl->set_base( new_type );
     1257                } // if
     1258        }
     1259
    12401260        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
    12411261                PassVisitor<ArrayLength> len;
Note: See TracChangeset for help on using the changeset viewer.