Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r095b99a r09867ec  
    6464#include "Common/UniqueName.h"         // for UniqueName
    6565#include "Common/utility.h"            // for operator+, cloneAll, deleteAll
     66#include "CompilationState.h"          // skip some passes in new-ast build
    6667#include "Concurrency/Keywords.h"      // for applyKeywords
    6768#include "FixFunction.h"               // for FixFunction
     
    270271        };
    271272
    272         struct ArrayLength : public WithIndexer {
     273        struct InitializerLength {
    273274                /// for array types without an explicit length, compute the length and store it so that it
    274275                /// is known to the rest of the phases. For example,
     
    281282
    282283                void previsit( ObjectDecl * objDecl );
     284        };
     285
     286        struct ArrayLength : public WithIndexer {
     287                static void computeLength( std::list< Declaration * > & translationUnit );
     288
    283289                void previsit( ArrayType * arrayType );
    284290        };
     
    311317                        Stats::Heap::newPass("validate-A");
    312318                        Stats::Time::BlockGuard guard("validate-A");
     319                        VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    313320                        acceptAll( translationUnit, hoistDecls );
    314321                        ReplaceTypedef::replaceTypedef( translationUnit );
     
    336343                        Stats::Time::BlockGuard guard("validate-C");
    337344                        acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old
    338                         VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    339345                        ReturnChecker::checkFunctionReturns( translationUnit );
    340346                        InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
     
    368374                                mutateAll( translationUnit, compoundliteral );
    369375                        });
    370                         Stats::Time::TimeBlock("Resolve With Expressions", [&]() {
    371                                 ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables
    372                         });
     376                        if (!useNewAST) {
     377                                Stats::Time::TimeBlock("Resolve With Expressions", [&]() {
     378                                        ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables
     379                                });
     380                        }
    373381                }
    374382                {
    375383                        Stats::Heap::newPass("validate-F");
    376384                        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);
     385                        if (!useNewAST) {
     386                                Stats::Time::TimeCall("Fix Object Type",
     387                                        FixObjectType::fix, translationUnit);
     388                        }
     389                        Stats::Time::TimeCall("Initializer Length",
     390                                InitializerLength::computeLength, translationUnit);
     391                        if (!useNewAST) {
     392                                Stats::Time::TimeCall("Array Length",
     393                                        ArrayLength::computeLength, translationUnit);
     394                        }
    381395                        Stats::Time::TimeCall("Find Special Declarations",
    382396                                Validate::findSpecialDecls, translationUnit);
    383397                        Stats::Time::TimeCall("Fix Label Address",
    384398                                mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer);
    385                         Stats::Time::TimeCall("Handle Attributes",
    386                                 Validate::handleAttributes, translationUnit);
     399                        if (!useNewAST) {
     400                                Stats::Time::TimeCall("Handle Attributes",
     401                                        Validate::handleAttributes, translationUnit);
     402                        }
    387403                }
    388404        }
     
    960976        }
    961977
     978        static bool isNonParameterAttribute( Attribute * attr ) {
     979                static const std::vector<std::string> bad_names = {
     980                        "aligned", "__aligned__",
     981                };
     982                for ( auto name : bad_names ) {
     983                        if ( name == attr->name ) {
     984                                return true;
     985                        }
     986                }
     987                return false;
     988        }
     989
    962990        Type * ReplaceTypedef::postmutate( TypeInstType * typeInst ) {
    963991                // instances of typedef types will come here. If it is an instance
     
    968996                        ret->location = typeInst->location;
    969997                        ret->get_qualifiers() |= typeInst->get_qualifiers();
    970                         // attributes are not carried over from typedef to function parameters/return values
    971                         if ( ! inFunctionType ) {
    972                                 ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
    973                         } else {
    974                                 deleteAll( ret->attributes );
    975                                 ret->attributes.clear();
    976                         }
     998                        // GCC ignores certain attributes if they arrive by typedef, this mimics that.
     999                        if ( inFunctionType ) {
     1000                                ret->attributes.remove_if( isNonParameterAttribute );
     1001                        }
     1002                        ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
    9771003                        // place instance parameters on the typedef'd type
    9781004                        if ( ! typeInst->parameters.empty() ) {
     
    11821208                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    11831209                        if ( params.size() == 0 ) {
    1184                                 SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
     1210                                SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." );
    11851211                        }
    11861212                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    11871213                        if ( ! refType ) {
    1188                                 SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
     1214                                SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." );
    11891215                        }
    11901216                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    1191                                 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
     1217                                if(!returnVals.front()->get_type()->isVoid()) {
     1218                                        SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." );
     1219                                }
    11921220                        }
    11931221                }
     
    13131341        }
    13141342
     1343        void InitializerLength::computeLength( std::list< Declaration * > & translationUnit ) {
     1344                PassVisitor<InitializerLength> len;
     1345                acceptAll( translationUnit, len );
     1346        }
     1347
    13151348        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
    13161349                PassVisitor<ArrayLength> len;
     
    13181351        }
    13191352
    1320         void ArrayLength::previsit( ObjectDecl * objDecl ) {
     1353        void InitializerLength::previsit( ObjectDecl * objDecl ) {
    13211354                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->type ) ) {
    13221355                        if ( at->dimension ) return;
     
    13721405        /// Replaces enum types by int, and function/array types in function parameter and return
    13731406        /// lists by appropriate pointers
     1407        /*
    13741408        struct EnumAndPointerDecay_new {
    13751409                const ast::EnumDecl * previsit( const ast::EnumDecl * enumDecl ) {
     
    14221456                }
    14231457        };
     1458        */
    14241459
    14251460        /// expand assertions from a trait instance, performing appropriate type variable substitutions
     
    14401475        }
    14411476
     1477        /*
     1478
    14421479        /// Associates forward declarations of aggregates with their definitions
    14431480        class LinkReferenceToTypes_new final
     
    15061543                }
    15071544
    1508                 void checkGenericParameters( const ast::ReferenceToType * inst ) {
     1545                void checkGenericParameters( const ast::BaseInstType * inst ) {
    15091546                        for ( const ast::Expr * param : inst->params ) {
    15101547                                if ( ! dynamic_cast< const ast::TypeExpr * >( param ) ) {
     
    17701807                static const node_t * forallFixer(
    17711808                        const CodeLocation & loc, const node_t * node,
    1772                         ast::ParameterizedType::ForallList parent_t::* forallField
     1809                        ast::FunctionType::ForallList parent_t::* forallField
    17731810                ) {
    17741811                        for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) {
     
    18211858                }
    18221859        };
     1860        */
    18231861} // anonymous namespace
    18241862
     1863/*
    18251864const ast::Type * validateType(
    18261865                const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab ) {
    1827         ast::Pass< EnumAndPointerDecay_new > epc;
     1866        // ast::Pass< EnumAndPointerDecay_new > epc;
    18281867        ast::Pass< LinkReferenceToTypes_new > lrt{ loc, symtab };
    18291868        ast::Pass< ForallPointerDecay_new > fpd{ loc };
    18301869
    1831         return type->accept( epc )->accept( lrt )->accept( fpd );
     1870        return type->accept( lrt )->accept( fpd );
    18321871}
     1872*/
    18331873
    18341874} // namespace SymTab
Note: See TracChangeset for help on using the changeset viewer.