Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r98538288 r4615ac8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:43:34 2019
    13 // Update Count     : 363
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  7 6:42:00 2019
     13// Update Count     : 360
    1414//
    1515
     
    6969#include "InitTweak/GenInit.h"         // for fixReturnStatements
    7070#include "InitTweak/InitTweak.h"       // for isCtorDtorAssign
     71#include "Parser/LinkageSpec.h"        // for C
    7172#include "ResolvExpr/typeops.h"        // for typesCompatible
    7273#include "ResolvExpr/Resolver.h"       // for findSingleExpression
    7374#include "ResolvExpr/ResolveTypeof.h"  // for resolveTypeof
    7475#include "SymTab/Autogen.h"            // for SizeType
    75 #include "SynTree/LinkageSpec.h"       // for C
    7676#include "SynTree/Attribute.h"         // for noAttributes, Attribute
    7777#include "SynTree/Constant.h"          // for Constant
     
    8181#include "SynTree/Label.h"             // for operator==, Label
    8282#include "SynTree/Mutator.h"           // for Mutator
     83#include "SynTree/TopLvalue.h"         // for assertTopLvalue, clearInnerLvalue
    8384#include "SynTree/Type.h"              // for Type, TypeInstType, EnumInstType
    8485#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
     
    308309                PassVisitor<FixQualifiedTypes> fixQual;
    309310
     311                assertTopLvalue( translationUnit );
    310312                {
    311313                        Stats::Heap::newPass("validate-A");
    312314                        Stats::Time::BlockGuard guard("validate-A");
    313                         VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    314315                        acceptAll( translationUnit, hoistDecls );
    315316                        ReplaceTypedef::replaceTypedef( translationUnit );
     
    317318                        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
    318319                }
     320                assertTopLvalue( translationUnit );
    319321                {
    320322                        Stats::Heap::newPass("validate-B");
    321323                        Stats::Time::BlockGuard guard("validate-B");
     324                        assertTopLvalue( translationUnit );
    322325                        Stats::Time::TimeBlock("Link Reference To Types", [&]() {
    323326                                acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
    324327                        });
     328                        clearInnerLvalue( translationUnit );
     329                        assertTopLvalue( translationUnit );
    325330                        Stats::Time::TimeBlock("Fix Qualified Types", [&]() {
    326331                                mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed
    327332                        });
     333                        assertTopLvalue( translationUnit );
    328334                        Stats::Time::TimeBlock("Hoist Structs", [&]() {
    329335                                HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
    330336                        });
     337                        assertTopLvalue( translationUnit );
    331338                        Stats::Time::TimeBlock("Eliminate Typedefs", [&]() {
    332339                                EliminateTypedef::eliminateTypedef( translationUnit ); //
    333340                        });
    334341                }
     342                assertTopLvalue( translationUnit );
    335343                {
    336344                        Stats::Heap::newPass("validate-C");
    337345                        Stats::Time::BlockGuard guard("validate-C");
    338346                        acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old
     347                        VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    339348                        ReturnChecker::checkFunctionReturns( translationUnit );
    340349                        InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
    341350                }
     351                assertTopLvalue( translationUnit );
    342352                {
    343353                        Stats::Heap::newPass("validate-D");
    344354                        Stats::Time::BlockGuard guard("validate-D");
     355                        assertTopLvalue( translationUnit );
    345356                        Stats::Time::TimeBlock("Apply Concurrent Keywords", [&]() {
    346357                                Concurrency::applyKeywords( translationUnit );
    347358                        });
     359                        clearInnerLvalue( translationUnit );
     360                        assertTopLvalue( translationUnit );
    348361                        Stats::Time::TimeBlock("Forall Pointer Decay", [&]() {
    349362                                acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
    350363                        });
     364                        assertTopLvalue( translationUnit );
    351365                        Stats::Time::TimeBlock("Hoist Control Declarations", [&]() {
    352366                                ControlStruct::hoistControlDecls( translationUnit );  // hoist initialization out of for statements; must happen before autogenerateRoutines
    353367                        });
     368                        assertTopLvalue( translationUnit );
    354369                        Stats::Time::TimeBlock("Generate Autogen routines", [&]() {
    355370                                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay_old
    356371                        });
    357                 }
     372                        clearInnerLvalue( translationUnit );
     373                }
     374                assertTopLvalue( translationUnit );
    358375                {
    359376                        Stats::Heap::newPass("validate-E");
    360377                        Stats::Time::BlockGuard guard("validate-E");
     378                        assertTopLvalue( translationUnit );
    361379                        Stats::Time::TimeBlock("Implement Mutex Func", [&]() {
    362380                                Concurrency::implementMutexFuncs( translationUnit );
    363381                        });
     382                        clearInnerLvalue( translationUnit );
     383                        assertTopLvalue( translationUnit );
    364384                        Stats::Time::TimeBlock("Implement Thread Start", [&]() {
    365385                                Concurrency::implementThreadStarter( translationUnit );
    366386                        });
     387                        assertTopLvalue( translationUnit );
    367388                        Stats::Time::TimeBlock("Compound Literal", [&]() {
    368389                                mutateAll( translationUnit, compoundliteral );
    369390                        });
     391                        assertTopLvalue( translationUnit );
    370392                        Stats::Time::TimeBlock("Resolve With Expressions", [&]() {
    371393                                ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables
    372394                        });
    373                 }
     395                        clearInnerLvalue( translationUnit );
     396                }
     397                assertTopLvalue( translationUnit );
    374398                {
    375399                        Stats::Heap::newPass("validate-F");
    376400                        Stats::Time::BlockGuard guard("validate-F");
    377                         Stats::Time::TimeCall("Fix Object Type",
    378                                 FixObjectType::fix, translationUnit);
    379                         Stats::Time::TimeCall("Array Length",
    380                                 ArrayLength::computeLength, translationUnit);
    381                         Stats::Time::TimeCall("Find Special Declarations",
    382                                 Validate::findSpecialDecls, translationUnit);
    383                         Stats::Time::TimeCall("Fix Label Address",
    384                                 mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer);
    385                         Stats::Time::TimeCall("Handle Attributes",
    386                                 Validate::handleAttributes, translationUnit);
    387                 }
     401                        assertTopLvalue( translationUnit );
     402                        Stats::Time::TimeBlock("Fix Object Type", [&]() {
     403                                FixObjectType::fix( translationUnit );
     404                        });
     405                        assertTopLvalue( translationUnit );
     406                        Stats::Time::TimeBlock("Array Length", [&]() {
     407                                ArrayLength::computeLength( translationUnit );
     408                        });
     409                        clearInnerLvalue( translationUnit );
     410                        assertTopLvalue( translationUnit );
     411                        Stats::Time::TimeBlock("Find Special Declarations", [&]() {
     412                                Validate::findSpecialDecls( translationUnit );
     413                        });
     414                        assertTopLvalue( translationUnit );
     415                        Stats::Time::TimeBlock("Fix Label Address", [&]() {
     416                                mutateAll( translationUnit, labelAddrFixer );
     417                        });
     418                        assertTopLvalue( translationUnit );
     419                        Stats::Time::TimeBlock("Handle Attributes", [&]() {
     420                                Validate::handleAttributes( translationUnit );
     421                        });
     422                }
     423                assertTopLvalue( translationUnit );
    388424        }
    389425
     
    10441080                Type * designatorType = tyDecl->base->stripDeclarator();
    10451081                if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    1046                         declsToAddBefore.push_back( new StructDecl( aggDecl->name, AggregateDecl::Struct, noAttributes, tyDecl->linkage ) );
     1082                        declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) );
    10471083                } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    10481084                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
     
    11821218                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    11831219                        if ( params.size() == 0 ) {
    1184                                 SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." );
     1220                                SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
    11851221                        }
    11861222                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    11871223                        if ( ! refType ) {
    1188                                 SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." );
     1224                                SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
    11891225                        }
    11901226                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    1191                                 if(!returnVals.front()->get_type()->isVoid()) {
    1192                                         SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." );
    1193                                 }
     1227                                SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
    11941228                        }
    11951229                }
     
    13001334        void FixObjectType::previsit( ObjectDecl * objDecl ) {
    13011335                Type * new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
     1336                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13021337                objDecl->set_type( new_type );
    13031338        }
     
    13051340        void FixObjectType::previsit( FunctionDecl * funcDecl ) {
    13061341                Type * new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
     1342                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13071343                funcDecl->set_type( new_type );
    13081344        }
     
    13111347                if ( typeDecl->get_base() ) {
    13121348                        Type * new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
     1349                        new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13131350                        typeDecl->set_base( new_type );
    13141351                } // if
Note: See TracChangeset for help on using the changeset viewer.