Ignore:
Timestamp:
Jan 7, 2021, 3:27:00 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b4daf2, 64aeca0
Parents:
3c64c668 (diff), eef8dfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into park_unpark

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ResolveTypeof.cc

    r3c64c668 r58fe85a  
    1515
    1616#include "ResolveTypeof.h"
     17#include "RenameVars.h"
    1718
    1819#include <cassert>               // for assert
     
    2930#include "SynTree/Mutator.h"     // for Mutator
    3031#include "SynTree/Type.h"        // for TypeofType, Type
     32#include "SymTab/Mangler.h"
     33#include "InitTweak/InitTweak.h" // for isConstExpr
    3134
    3235namespace SymTab {
     
    99102                        // replace basetypeof(<enum>) by int
    100103                        if ( dynamic_cast<EnumInstType*>(newType) ) {
    101                                 Type* newerType = 
    102                                         new BasicType{ newType->get_qualifiers(), BasicType::SignedInt, 
     104                                Type* newerType =
     105                                        new BasicType{ newType->get_qualifiers(), BasicType::SignedInt,
    103106                                        newType->attributes };
    104107                                delete newType;
    105108                                newType = newerType;
    106109                        }
    107                         newType->get_qualifiers().val 
     110                        newType->get_qualifiers().val
    108111                                = ( newType->get_qualifiers().val & ~Type::Qualifiers::Mask ) | oldQuals;
    109112                } else {
    110113                        newType->get_qualifiers().val |= oldQuals;
    111114                }
    112                
     115
    113116                return newType;
    114117        }
     
    120123                ResolveTypeof_new( const ast::SymbolTable & syms ) : localSymtab( syms ) {}
    121124
    122                 void premutate( const ast::TypeofType * ) { visit_children = false; }
    123 
    124                 const ast::Type * postmutate( const ast::TypeofType * typeofType ) {
     125                void previsit( const ast::TypeofType * ) { visit_children = false; }
     126
     127                const ast::Type * postvisit( const ast::TypeofType * typeofType ) {
    125128                        // pass on null expression
    126129                        if ( ! typeofType->expr ) return typeofType;
     
    133136                                // typeof wrapping expression
    134137                                ast::TypeEnvironment dummy;
    135                                 ast::ptr< ast::Expr > newExpr = 
     138                                ast::ptr< ast::Expr > newExpr =
    136139                                        resolveInVoidContext( typeofType->expr, localSymtab, dummy );
    137140                                assert( newExpr->result && ! newExpr->result->isVoid() );
     
    143146                                // replace basetypeof(<enum>) by int
    144147                                if ( newType.as< ast::EnumInstType >() ) {
    145                                         newType = new ast::BasicType{ 
     148                                        newType = new ast::BasicType{
    146149                                                ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) };
    147150                                }
    148                                 reset_qualifiers( 
    149                                         newType, 
     151                                reset_qualifiers(
     152                                        newType,
    150153                                        ( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers );
    151154                        } else {
     
    153156                        }
    154157
    155                         return newType;
     158                        return newType.release();
    156159                }
    157160        };
     
    161164        ast::Pass< ResolveTypeof_new > mutator{ symtab };
    162165        return type->accept( mutator );
     166}
     167
     168struct FixArrayDimension {
     169        // should not require a mutable symbol table - prevent pass template instantiation
     170        const ast::SymbolTable & _symtab;
     171        FixArrayDimension(const ast::SymbolTable & symtab): _symtab(symtab) {}
     172
     173        const ast::ArrayType * previsit (const ast::ArrayType * arrayType) {
     174                if (!arrayType->dimension) return arrayType;
     175                auto mutType = mutate(arrayType);
     176                ast::ptr<ast::Type> sizetype = ast::sizeType ? ast::sizeType : new ast::BasicType(ast::BasicType::LongUnsignedInt);
     177                mutType->dimension = findSingleExpression(arrayType->dimension, sizetype, _symtab);
     178
     179                if (InitTweak::isConstExpr(mutType->dimension)) {
     180                        mutType->isVarLen = ast::LengthFlag::FixedLen;
     181                }
     182                else {
     183                        mutType->isVarLen = ast::LengthFlag::VariableLen;
     184                }
     185                return mutType;
     186        }
     187};
     188
     189const ast::Type * fixArrayType( const ast::Type * type, const ast::SymbolTable & symtab) {
     190        ast::Pass<FixArrayDimension> visitor {symtab};
     191        return type->accept(visitor);
     192}
     193
     194const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ast::SymbolTable & symtab ) {
     195        if (!decl->isTypeFixed) {
     196                auto mutDecl = mutate(decl);
     197                auto resolvedType = resolveTypeof(decl->type, symtab);
     198                resolvedType = fixArrayType(resolvedType, symtab);
     199                mutDecl->type = resolvedType;
     200
     201                // check variable length if object is an array.
     202                // xxx - should this be part of fixObjectType?
     203
     204                /*
     205                if (auto arrayType = dynamic_cast<const ast::ArrayType *>(resolvedType)) {
     206                        auto dimExpr = findSingleExpression(arrayType->dimension, ast::sizeType, symtab);
     207                        if (auto varexpr = arrayType->dimension.as<ast::VariableExpr>()) {// hoisted previously
     208                                if (InitTweak::isConstExpr(varexpr->var.strict_as<ast::ObjectDecl>()->init)) {
     209                                        auto mutType = mutate(arrayType);
     210                                        mutType->isVarLen = ast::LengthFlag::VariableLen;
     211                                        mutDecl->type = mutType;
     212                                }
     213                        }
     214                }
     215                */
     216
     217
     218                if (!mutDecl->name.empty())
     219                        mutDecl->mangleName = Mangle::mangle(mutDecl); // do not mangle unnamed variables
     220               
     221                mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID);
     222                mutDecl->isTypeFixed = true;
     223                return mutDecl;
     224        }
     225        return decl;
    163226}
    164227
Note: See TracChangeset for help on using the changeset viewer.