Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r7e08acf rac3362c  
    6262#include "ResolvExpr/typeops.h"        // for typesCompatible
    6363#include "ResolvExpr/Resolver.h"       // for findSingleExpression
    64 #include "ResolvExpr/ResolveTypeof.h"  // for resolveTypeof
    6564#include "SymTab/Autogen.h"            // for SizeType
    6665#include "SynTree/Attribute.h"         // for noAttributes, Attribute
     
    248247                void previsit( StructInstType * inst );
    249248                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 * );
    259249        };
    260250
     
    322312                Concurrency::implementThreadStarter( translationUnit );
    323313                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 );
    326314                ArrayLength::computeLength( translationUnit );
    327315                acceptAll( translationUnit, finder ); // xxx - remove this pass soon
     
    403391                        assert( aggr ); // TODO: need to handle forward declarations
    404392                        for ( Declaration * member : aggr->members ) {
    405                                 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
     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 ) ) {
    406413                                        // name on the right is a typedef
    407414                                        if ( NamedTypeDecl * aggr = dynamic_cast< NamedTypeDecl * > ( member ) ) {
     
    410417                                                        Type * ret = aggr->base->clone();
    411418                                                        ret->get_qualifiers() = qualType->get_qualifiers();
    412                                                         TypeSubstitution sub = parent->genericSubstitution();
    413                                                         sub.apply(ret);
    414419                                                        return ret;
    415420                                                }
     
    12331238        }
    12341239
    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 
    12601240        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
    12611241                PassVisitor<ArrayLength> len;
Note: See TracChangeset for help on using the changeset viewer.