Ignore:
Timestamp:
Nov 10, 2020, 3:14:14 AM (4 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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())
Note: See TracChangeset for help on using the changeset viewer.