Ignore:
Timestamp:
Mar 15, 2022, 10:14:05 AM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
48a91e2
Parents:
d824715
Message:

Added another check to checkInvariants for code locations. I also went through and made sure you can put it every after every new AST pass not followed by a forceFillCodeLocations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInitNew.cpp

    rd824715 r33b7d49  
    1616#include "CodeGen/GenType.h"           // for genPrettyType
    1717#include "CodeGen/OperatorTable.h"
     18#include "Common/CodeLocationTools.hpp"
    1819#include "Common/PassVisitor.h"        // for PassVisitor, WithStmtsToAdd
    1920#include "Common/SemanticError.h"      // for SemanticError
     
    553554                ast::ptr<ast::Expr> guard = mutArg;
    554555
    555                 ast::ptr<ast::ObjectDecl> tmp = new ast::ObjectDecl({}, "__tmp", mutResult, nullptr );
     556                ast::ptr<ast::ObjectDecl> tmp = new ast::ObjectDecl(loc, "__tmp", mutResult, nullptr );
    556557
    557558                // create and resolve copy constructor
     
    799800        // to prevent warnings ('_unq0' may be used uninitialized in this function),
    800801        // insert an appropriate zero initializer for UniqueExpr temporaries.
    801         ast::Init * makeInit( const ast::Type * t ) {
     802        ast::Init * makeInit( const ast::Type * t, CodeLocation const & loc ) {
    802803                if ( auto inst = dynamic_cast< const ast::StructInstType * >( t ) ) {
    803804                        // initizer for empty struct must be empty
    804                         if ( inst->base->members.empty() ) return new ast::ListInit({}, {});
     805                        if ( inst->base->members.empty() ) {
     806                                return new ast::ListInit( loc, {} );
     807                        }
    805808                } else if ( auto inst = dynamic_cast< const ast::UnionInstType * >( t ) ) {
    806809                        // initizer for empty union must be empty
    807                         if ( inst->base->members.empty() ) return new ast::ListInit({}, {});
    808                 }
    809 
    810                 return new ast::ListInit( {}, { new ast::SingleInit( {}, ast::ConstantExpr::from_int({}, 0) ) } );
     810                        if ( inst->base->members.empty() ) {
     811                                return new ast::ListInit( loc, {} );
     812                        }
     813                }
     814
     815                return new ast::ListInit( loc, {
     816                        new ast::SingleInit( loc, ast::ConstantExpr::from_int( loc, 0 ) )
     817                } );
    811818        }
    812819
     
    832839                        } else {
    833840                                // expr isn't a call expr, so create a new temporary variable to use to hold the value of the unique expression
    834                                 mutExpr->object = new ast::ObjectDecl( mutExpr->location, toString("_unq", mutExpr->id), mutExpr->result, makeInit( mutExpr->result ) );
     841                                mutExpr->object = new ast::ObjectDecl( mutExpr->location, toString("_unq", mutExpr->id), mutExpr->result, makeInit( mutExpr->result, mutExpr->location ) );
    835842                                mutExpr->var = new ast::VariableExpr( mutExpr->location, mutExpr->object );
    836843                        }
     
    12291236
    12301237                                                        auto destructor = new ast::ObjectDecl(loc, memberDtorNamer.newName(), new ast::StructInstType( ast::dtorStruct ), new ast::ListInit(loc, { new ast::SingleInit(loc, thisExpr ), new ast::SingleInit(loc, new ast::CastExpr( dtorExpr, dtorType ) ) } ) );
    1231                                                         destructor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr({}, ast::dtorStructDestroy ) } ) );
     1238                                                        destructor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr( loc, ast::dtorStructDestroy ) } ) );
    12321239                                                        mutStmts->push_front( new ast::DeclStmt(loc, destructor ) );
    12331240                                                        mutStmts->kids.splice( mutStmts->kids.begin(), stmtsToAdd );
     
    13231330
    13241331        const ast::Expr * GenStructMemberCalls::postvisit( const ast::UntypedExpr * untypedExpr ) {
    1325                 // Expression * newExpr = untypedExpr;
    13261332                // xxx - functions returning ast::ptr seems wrong...
    13271333                auto res = ResolvExpr::findVoidExpression( untypedExpr, symtab );
    1328                 return res.release();
    1329                 // return newExpr;
     1334                // Fix CodeLocation (at least until resolver is fixed).
     1335                auto fix = localFillCodeLocations( untypedExpr->location, res.release() );
     1336                return strict_dynamic_cast<const ast::Expr *>( fix );
    13301337        }
    13311338
Note: See TracChangeset for help on using the changeset viewer.