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);
}
}
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations