Goose  Artifact [1de1acfea6]

Artifact 1de1acfea6dfb583bfa4be448e1bed6112807da89d9c7b0901546c0e7a657372:

  • File bs/parse/scope.cpp — part of check-in [52280a3c5c] at 2021-01-11 20:20:37 on branch trunk — Reorganized symbols visibility a bit to avoid local variables from the enclosing function to be visible inside of function parameter list declarations (which prevented reusing them as parameter names). (user: achavasse size: 1504)

#include "parse.h"

using namespace goose;
using namespace goose::parse;
using namespace goose::builtins;

VisibilityScope::VisibilityScope( Parser& p ) :
    m_identityGuard( p )
{
    auto parentBaseIdentity = p.context().identity();
    parentBaseIdentity = TakeVectorTerm( parentBaseIdentity, VecSize( parentBaseIdentity ) - 1 );

    // We construct an identity to hold all the compilation time constants for this scope,
    // that will be visible in every nested scopes and functions.

    // We create a separate identity for the local variables, from which both all inherited constants
    // and local variables from the parent scope will be visible. That one will be made current,
    // and can be truncated to find the "compmilation constant" identity where we need to see only the
    // compilation constants (for instance, in parameter lists).

    // TODO: see if we can replace this unique id with something that is just unique within the current
    // function. This would avoid wild changes in the mangled names based on unrelated definitions being added
    // elsewhere.
    auto localIdentity = AppendToVectorTerm( parentBaseIdentity, TERM( StringId( Env::NewUniqueId() ) ) );
    auto localVarsIdentity = AppendToVectorTerm( localIdentity, TSID( locvars ) );

    p.context().env()->addVisibilityRule( parentBaseIdentity, localIdentity );
    p.context().env()->addVisibilityRule( p.context().identity(), localVarsIdentity );

    p.context().setIdentity( localVarsIdentity );
}