Search in sources :

Example 26 with Name

use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.

the class BlockDeclarationInstantiationGenerator method generate.

private void generate(List<Declaration> declarations, Variable<ExecutionContext> cx, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env, InstructionVisitor mv) {
    Variable<DeclarativeEnvironmentRecord> envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
    Variable<FunctionObject> fo = null;
    getEnvironmentRecord(env, envRec, mv);
    /* steps 1-2 */
    for (Declaration d : declarations) {
        if (!(d instanceof HoistableDeclaration)) {
            for (Name dn : BoundNames(d)) {
                BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, dn);
                if (IsConstantDeclaration(d)) {
                    op.createImmutableBinding(envRec, dn, true, mv);
                } else {
                    op.createMutableBinding(envRec, dn, false, mv);
                }
            }
        } else {
            Name fn = BoundName((HoistableDeclaration) d);
            BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, fn);
            op.createMutableBinding(envRec, fn, false, mv);
            InstantiateFunctionObject(cx, env, d, mv);
            if (fo == null) {
                fo = mv.newVariable("fo", FunctionObject.class);
            }
            mv.store(fo);
            op.initializeBinding(envRec, fn, fo, mv);
        }
    }
}
Also used : HoistableDeclaration(com.github.anba.es6draft.ast.HoistableDeclaration) HoistableDeclaration(com.github.anba.es6draft.ast.HoistableDeclaration) Declaration(com.github.anba.es6draft.ast.Declaration) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name)

Example 27 with Name

use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.

the class ComprehensionGenerator method visit.

/**
     * Runtime Semantics: ComprehensionEvaluation
     */
@Override
public Void visit(LegacyComprehension node, CodeVisitor mv) {
    BlockScope scope = node.getScope();
    if (scope.isPresent()) {
        mv.enterVariableScope();
        Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = mv.newVariable("env", LexicalEnvironment.class).uncheckedCast();
        Variable<DeclarativeEnvironmentRecord> envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
        newDeclarativeEnvironment(scope, mv);
        mv.store(env);
        getEnvRec(env, envRec, mv);
        for (Name name : LexicallyDeclaredNames(node.getScope())) {
            BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, name);
            op.createMutableBinding(envRec, name, false, mv);
            InitializeBoundNameWithUndefined(envRec, name, mv);
        }
        mv.load(env);
        pushLexicalEnvironment(mv);
        mv.exitVariableScope();
    }
    mv.enterScope(node);
    visit((Comprehension) node, mv);
    mv.exitScope();
    if (scope.isPresent()) {
        popLexicalEnvironment(mv);
    }
    return null;
}
Also used : LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name)

Example 28 with Name

use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.

the class ExpressionGenerator method visit.

/**
     * Extension: 'let' expression
     */
@Override
public ValType visit(LetExpression node, CodeVisitor mv) {
    BlockScope scope = node.getScope();
    if (scope.isPresent()) {
        mv.enterVariableScope();
        Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = mv.newVariable("env", LexicalEnvironment.class).uncheckedCast();
        Variable<DeclarativeEnvironmentRecord> envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
        newDeclarativeEnvironment(scope, mv);
        mv.store(env);
        getEnvRec(env, envRec, mv);
        for (LexicalBinding lexical : node.getBindings()) {
            Binding binding = lexical.getBinding();
            Expression initializer = lexical.getInitializer();
            for (Name name : BoundNames(binding)) {
                BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, name);
                op.createMutableBinding(envRec, name, false, mv);
            }
            if (initializer == null) {
                // LexicalBinding : BindingIdentifier
                assert binding instanceof BindingIdentifier;
                Name name = ((BindingIdentifier) binding).getName();
                /* steps 1-2 */
                // stack: [] -> []
                InitializeBoundNameWithUndefined(envRec, name, mv);
            } else if (binding instanceof BindingIdentifier) {
                // LexicalBinding : BindingIdentifier Initializer
                Name name = ((BindingIdentifier) binding).getName();
                /* steps 1-7 */
                InitializeBoundNameWithInitializer(codegen, envRec, name, initializer, mv);
            } else {
                // LexicalBinding : BindingPattern Initializer
                assert binding instanceof BindingPattern;
                /* steps 1-3 */
                expressionBoxed(initializer, mv);
                /* steps 4-5 */
                BindingInitializationGenerator.BindingInitialization(codegen, envRec, (BindingPattern) binding, mv);
            }
        }
        mv.load(env);
        pushLexicalEnvironment(mv);
        mv.exitVariableScope();
    }
    mv.enterScope(node);
    ValType type = node.getExpression().accept(this, mv);
    mv.exitScope();
    if (scope.isPresent()) {
        popLexicalEnvironment(mv);
    }
    return type;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 29 with Name

use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.

the class Parser method checkFormalParameterDuplication.

private void checkFormalParameterDuplication(FunctionNode node, List<Name> boundNames, NameSet names) {
    boolean hasDuplicates = (boundNames.size() != names.size());
    if (hasDuplicates) {
        Name duplicate = findDuplicate(names, boundNames);
        BindingIdentifier parameter = FindParameter.find(node, duplicate);
        reportSyntaxError(parameter, Messages.Key.DuplicateFormalParameter, duplicate);
    }
}
Also used : Name(com.github.anba.es6draft.ast.scope.Name)

Example 30 with Name

use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.

the class Parser method computeBlockFunctionsForScript.

private void computeBlockFunctionsForScript() {
    assert context.kind.isScript();
    if (!isEnabled(CompatibilityOption.BlockFunctionDeclaration)) {
        return;
    }
    ScriptContext scriptScope = context.scriptContext;
    InlineArrayList<FunctionDeclaration> functions = scriptScope.blockFunctions;
    if (functions == null) {
        return;
    }
    assert context.strictMode != StrictMode.Strict : "block functions in strict mode";
    InlineArrayList<FunctionDeclaration> blockFunctions = new InlineArrayList<>();
    for (FunctionDeclaration function : functions) {
        if (hasEnclosingLexicalDeclaration(function, scriptScope)) {
            continue;
        }
        // See 15.1.1 Static Semantics: Early Errors
        Name name = function.getIdentifier().getName();
        if (scriptScope.allowVarDeclaredName(name)) {
            // Function declaration is applicable for legacy semantics, iff
            // (1) Adding a VariableStatement with the same name would not produce an error.
            function.setLegacyBlockScoped(true);
            blockFunctions.add(function);
        }
    }
    scriptScope.setBlockFunctions(blockFunctions);
}
Also used : InlineArrayList(com.github.anba.es6draft.runtime.internal.InlineArrayList) Name(com.github.anba.es6draft.ast.scope.Name)

Aggregations

Name (com.github.anba.es6draft.ast.scope.Name)49 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)31 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)24 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)16 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)13 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)13 StatementListItem (com.github.anba.es6draft.ast.StatementListItem)12 Declaration (com.github.anba.es6draft.ast.Declaration)11 Jump (com.github.anba.es6draft.compiler.assembler.Jump)11 HashSet (java.util.HashSet)11 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)10 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)10 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)9 InitializeBoundName (com.github.anba.es6draft.compiler.BindingInitializationGenerator.InitializeBoundName)9 FunctionDeclaration (com.github.anba.es6draft.ast.FunctionDeclaration)8 VariableStatement (com.github.anba.es6draft.ast.VariableStatement)8 ArrayDeque (java.util.ArrayDeque)8 IdentifierName (com.github.anba.es6draft.ast.IdentifierName)7 VariableDeclaration (com.github.anba.es6draft.ast.VariableDeclaration)6 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)6