Changeset 0dd9a5e


Ignore:
Timestamp:
Nov 10, 2020, 3:14:14 AM (3 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
3ff4c1e
Parents:
18f0b70
Message:

delay autogen resolve

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r18f0b70 r0dd9a5e  
    423423                }
    424424                catch( SemanticErrorException &e ) {
    425                         errors.append( e );
     425                        if (__pass::onError (visitor.core, *i, 0))
     426                                errors.append( e );
    426427                }
    427428
  • src/AST/Pass.proto.hpp

    r18f0b70 r0dd9a5e  
    266266        static void endTrace(core_t &, long) {}
    267267
     268        // Allows visitor to handle an error on top-level declarations, and possibly suppress the error.
     269        // If onError() returns false, the error will be ignored. By default, it returns true.
     270
     271        template< typename core_t >
     272        static bool onError (core_t &, ptr<Decl> &, long) { return true; }
     273
     274        template< typename core_t >
     275        static auto onError (core_t & core, ptr<Decl> & decl, int) -> decltype(core.onError(decl)) {
     276                return core.onError(decl);
     277        }
     278
    268279        // Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
    269280        // All passes which have such functions are assumed desire this behaviour
  • src/ResolvExpr/ResolveTypeof.cc

    r18f0b70 r0dd9a5e  
    165165}
    166166
     167struct FixArrayDimension {
     168        // should not require a mutable symbol table - prevent pass template instantiation
     169        const ast::SymbolTable & _symtab;
     170        FixArrayDimension(const ast::SymbolTable & symtab): _symtab(symtab) {}
     171
     172        const ast::ArrayType * previsit (const ast::ArrayType * arrayType) {
     173                if (!arrayType->dimension) return arrayType;
     174                auto mutType = mutate(arrayType);
     175                ast::ptr<ast::Type> sizetype = ast::sizeType ? ast::sizeType : new ast::BasicType(ast::BasicType::LongUnsignedInt);
     176                mutType->dimension = findSingleExpression(arrayType->dimension, sizetype, _symtab);
     177
     178                if (InitTweak::isConstExpr(mutType->dimension)) {
     179                        mutType->isVarLen = ast::LengthFlag::FixedLen;
     180                }
     181                else {
     182                        mutType->isVarLen = ast::LengthFlag::VariableLen;
     183                }
     184                return mutType;
     185        }
     186};
     187
     188const ast::Type * fixArrayType( const ast::Type * type, const ast::SymbolTable & symtab) {
     189        ast::Pass<FixArrayDimension> visitor {symtab};
     190        return type->accept(visitor);
     191}
     192
    167193const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ast::SymbolTable & symtab ) {
    168194        if (!decl->isTypeFixed) {
    169195                auto mutDecl = mutate(decl);
    170196                auto resolvedType = resolveTypeof(decl->type, symtab);
     197                resolvedType = fixArrayType(resolvedType, symtab);
    171198                mutDecl->type = resolvedType;
    172199
    173200                // check variable length if object is an array.
    174201                // xxx - should this be part of fixObjectType?
     202
     203                /*
    175204                if (auto arrayType = dynamic_cast<const ast::ArrayType *>(resolvedType)) {
     205                        auto dimExpr = findSingleExpression(arrayType->dimension, ast::sizeType, symtab);
    176206                        if (auto varexpr = arrayType->dimension.as<ast::VariableExpr>()) {// hoisted previously
    177207                                if (InitTweak::isConstExpr(varexpr->var.strict_as<ast::ObjectDecl>()->init)) {
     
    182212                        }
    183213                }
     214                */
     215
    184216
    185217                if (!mutDecl->name.empty())
  • src/ResolvExpr/Resolver.cc

    r18f0b70 r0dd9a5e  
    12891289                void beginScope() { managedTypes.beginScope(); }
    12901290                void endScope() { managedTypes.endScope(); }
     1291                bool onError(ast::ptr<ast::Decl> & decl);
    12911292        };
    12921293        // size_t Resolver_new::traceId = Stats::Heap::new_stacktrace_id("Resolver");
     
    20662067        }
    20672068
     2069        // suppress error on autogen functions and mark invalid autogen as deleted.
     2070        bool Resolver_new::onError(ast::ptr<ast::Decl> & decl) {
     2071                if (auto functionDecl = decl.as<ast::FunctionDecl>()) {
     2072                        // xxx - can intrinsic gen ever fail?
     2073                        if (functionDecl->linkage == ast::Linkage::AutoGen) {
     2074                                auto mutDecl = mutate(functionDecl);
     2075                                mutDecl->isDeleted = true;
     2076                                mutDecl->stmts = nullptr;
     2077                                decl = mutDecl;
     2078                                return false;
     2079                        }
     2080                }
     2081                return true;
     2082        }
     2083
    20682084} // namespace ResolvExpr
    20692085
  • src/SymTab/Autogen.cc

    r18f0b70 r0dd9a5e  
    347347        void FuncGenerator::resolve( FunctionDecl * dcl ) {
    348348                try {
    349                         ResolvExpr::resolveDecl( dcl, indexer );
     349                        if (!useNewAST) // attempt to delay resolver call
     350                                ResolvExpr::resolveDecl( dcl, indexer );
    350351                        if ( functionNesting == 0 ) {
    351352                                // forward declare if top-level struct, so that
Note: See TracChangeset for help on using the changeset viewer.