public boolean keywordExists(String name) { int slot = exists(name); return slot >= 0 && firstKeywordIndex != -1 && slot >= firstKeywordIndex; }
public boolean keywordExists(String name) { int slot = exists(name); return slot >= 0 && firstKeywordIndex != -1 && slot >= firstKeywordIndex; }
/** * Add a new variable to this (current) scope unless it is already defined in the * current scope. * * @param name of new variable * @return index+depth merged location of scope */ public int addVariableThisScope(String name) { int slot = exists(name); if (slot >= 0) return slot; // This is perhaps innefficient timewise? Optimal spacewise growVariableNames(name); // Returns slot of variable return variableNames.length - 1; }
public IRubyObject shadowing_lvar(IRubyObject identifier) { String name = lexer.getIdent(); if (name == "_") return identifier; StaticScope current = getCurrentScope(); if (current.isBlockScope()) { if (current.exists(name) >= 0) yyerror("duplicated argument name"); if (current.isDefined(name) >= 0) { lexer.warning("shadowing outer local variable - %s", name); } } else if (current.exists(name) >= 0) { yyerror("duplicated argument name"); } return identifier; }
public IRubyObject shadowing_lvar(IRubyObject identifier) { String name = lexer.getIdent(); if (name == "_") return identifier; StaticScope current = getCurrentScope(); if (current.isBlockScope()) { if (current.exists(name) >= 0) yyerror("duplicated argument name"); if (current.isDefined(name) >= 0) { lexer.warning("shadowing outer local variable - %s", name); } } else if (current.exists(name) >= 0) { yyerror("duplicated argument name"); } return identifier; }
public Node declare(ISourcePosition position, RubySymbol symbolID, int depth) { int slot = exists(symbolID.idString()); if (slot >= 0) { return isBlockOrEval ? new DVarNode(position, ((depth << 16) | slot), symbolID) : new LocalVarNode(position, ((depth << 16) | slot), symbolID); } return isBlockOrEval ? enclosingScope.declare(position, symbolID, depth + 1) : new VCallNode(position, symbolID); }
public Node declare(ISourcePosition position, RubySymbol symbolID, int depth) { int slot = exists(symbolID.idString()); if (slot >= 0) { return isBlockOrEval ? new DVarNode(position, ((depth << 16) | slot), symbolID) : new LocalVarNode(position, ((depth << 16) | slot), symbolID); } return isBlockOrEval ? enclosingScope.declare(position, symbolID, depth + 1) : new VCallNode(position, symbolID); }
public Token shadowing_lvar(Token identifier) { String name = (String) identifier.getValue(); if (name == "_") return identifier; StaticScope current = getCurrentScope(); if (current.isBlockScope()) { if (current.exists(name) >= 0) yyerror("duplicated argument name"); if (warnings.isVerbose() && current.isDefined(name) >= 0) { warnings.warning(ID.STATEMENT_NOT_REACHED, identifier.getPosition(), "shadowing outer local variable - " + name); } } else if (current.exists(name) >= 0) { yyerror("duplicated argument name"); } return identifier; }
public Token shadowing_lvar(Token identifier) { String name = (String) identifier.getValue(); if (name == "_") return identifier; StaticScope current = getCurrentScope(); if (current.isBlockScope()) { if (current.exists(name) >= 0) yyerror("duplicated argument name"); if (warnings.isVerbose() && current.isDefined(name) >= 0) { warnings.warning(ID.STATEMENT_NOT_REACHED, identifier.getPosition(), "shadowing outer local variable - " + name); } } else if (current.exists(name) >= 0) { yyerror("duplicated argument name"); } return identifier; }
public ArgsTailHolder new_args_tail(ISourcePosition position, ListNode keywordArg, Token keywordRestArgName, BlockArgNode blockArg) { if (keywordRestArgName == null) return new ArgsTailHolder(position, keywordArg, null, blockArg); String restKwargsName = (String) keywordRestArgName.getValue(); int slot = currentScope.exists(restKwargsName); if (slot == -1) slot = currentScope.addVariable(restKwargsName); KeywordRestArgNode keywordRestArg = new KeywordRestArgNode(position, restKwargsName, slot); return new ArgsTailHolder(position, keywordArg, keywordRestArg, blockArg); }
public ArgsTailHolder new_args_tail(ISourcePosition position, ListNode keywordArg, Token keywordRestArgName, BlockArgNode blockArg) { if (keywordRestArgName == null) return new ArgsTailHolder(position, keywordArg, null, blockArg); String restKwargsName = (String) keywordRestArgName.getValue(); int slot = currentScope.exists(restKwargsName); if (slot == -1) slot = currentScope.addVariable(restKwargsName); KeywordRestArgNode keywordRestArg = new KeywordRestArgNode(position, restKwargsName, slot); return new ArgsTailHolder(position, keywordArg, keywordRestArg, blockArg); }
@Deprecated public String shadowing_lvar(String name) { if (name == "_") return name; StaticScope current = getCurrentScope(); if (current.exists(name) >= 0) yyerror("duplicated argument name"); if (current.isBlockScope() && warnings.isVerbose() && current.isDefined(name) >= 0 && Options.PARSER_WARN_LOCAL_SHADOWING.load()) { warnings.warning(ID.STATEMENT_NOT_REACHED, lexer.getPosition(), "shadowing outer local variable - " + name); } return name; }
public ArgsTailHolder new_args_tail(ISourcePosition position, ListNode keywordArg, ByteList keywordRestArgName, BlockArgNode blockArg) { if (keywordRestArgName == null) return new ArgsTailHolder(position, keywordArg, null, blockArg); ByteList restKwargsName = keywordRestArgName; String raw = restKwargsName.toString(); int slot = currentScope.exists(raw); if (slot == -1) slot = currentScope.addVariable(raw); KeywordRestArgNode keywordRestArg = new KeywordRestArgNode(position, symbolID(restKwargsName), slot); return new ArgsTailHolder(position, keywordArg, keywordRestArg, blockArg); }
@Deprecated public String shadowing_lvar(String name) { if (name == "_") return name; StaticScope current = getCurrentScope(); if (current.exists(name) >= 0) yyerror("duplicated argument name"); if (current.isBlockScope() && warnings.isVerbose() && current.isDefined(name) >= 0 && Options.PARSER_WARN_LOCAL_SHADOWING.load()) { warnings.warning(ID.STATEMENT_NOT_REACHED, lexer.getPosition(), "shadowing outer local variable - " + name); } return name; }
public ArgumentNode arg_var(Token identifier) { String name = (String) identifier.getValue(); StaticScope current = getCurrentScope(); // Multiple _ arguments are allowed. To not screw with tons of arity // issues in our runtime we will allocate unnamed bogus vars so things // still work. MRI does not use name as intern'd value so they don't // have this issue. if (name == "_") { int count = 0; while (current.exists(name) >= 0) { name = "_$" + count++; } } return new ArgumentNode(identifier.getPosition(), name, current.addVariableThisScope(name)); }
public ArgsTailHolder new_args_tail(ISourcePosition position, ListNode keywordArg, ByteList keywordRestArgName, BlockArgNode blockArg) { if (keywordRestArgName == null) return new ArgsTailHolder(position, keywordArg, null, blockArg); ByteList restKwargsName = keywordRestArgName; String raw = restKwargsName.toString(); int slot = currentScope.exists(raw); if (slot == -1) slot = currentScope.addVariable(raw); KeywordRestArgNode keywordRestArg = new KeywordRestArgNode(position, symbolID(restKwargsName), slot); return new ArgsTailHolder(position, keywordArg, keywordRestArg, blockArg); }
public ByteList shadowing_lvar(ByteList nameBytes) { if (nameBytes.realSize() == 1 && nameBytes.charAt(0) == '_') return nameBytes; RubySymbol name = symbolID(nameBytes); String id = name.idString(); StaticScope current = getCurrentScope(); if (current.exists(id) >= 0) yyerror("duplicated argument name"); if (current.isBlockScope() && warnings.isVerbose() && current.isDefined(id) >= 0 && Options.PARSER_WARN_LOCAL_SHADOWING.load()) { Ruby runtime = getConfiguration().getRuntime(); warnings.warning(ID.STATEMENT_NOT_REACHED, lexer.getFile(), lexer.getPosition().getLine(), str(runtime, "shadowing outer local variable - ", ids(runtime, name))); } return nameBytes; }
public ByteList shadowing_lvar(ByteList nameBytes) { if (nameBytes.realSize() == 1 && nameBytes.charAt(0) == '_') return nameBytes; RubySymbol name = symbolID(nameBytes); String id = name.idString(); StaticScope current = getCurrentScope(); if (current.exists(id) >= 0) yyerror("duplicated argument name"); if (current.isBlockScope() && warnings.isVerbose() && current.isDefined(id) >= 0 && Options.PARSER_WARN_LOCAL_SHADOWING.load()) { Ruby runtime = getConfiguration().getRuntime(); warnings.warning(ID.STATEMENT_NOT_REACHED, lexer.getFile(), lexer.getPosition().getLine(), str(runtime, "shadowing outer local variable - ", ids(runtime, name))); } return nameBytes; }