private Variable argumentResult(RubySymbol name) { boolean isUnderscore = name.getBytes().realSize() == 1 && name.getBytes().charAt(0) == '_'; if (isUnderscore && underscoreVariableSeen) { return createTemporaryVariable(); } else { if (isUnderscore) underscoreVariableSeen = true; return getNewLocalVariable(name, 0); } }
private Variable argumentResult(RubySymbol name) { boolean isUnderscore = name.getBytes().realSize() == 1 && name.getBytes().charAt(0) == '_'; if (isUnderscore && underscoreVariableSeen) { return createTemporaryVariable(); } else { if (isUnderscore) underscoreVariableSeen = true; return getNewLocalVariable(name, 0); } }
/** * Is the string this constant represents a valid constant identifier name. */ public boolean validConstantName() { boolean valid = ByteListHelper.eachCodePoint(getBytes(), (int index, int codepoint, Encoding encoding) -> index == 0 && encoding.isUpper(codepoint) || index != 0 && (encoding.isAlnum(codepoint) || !Encoding.isAscii(codepoint) || codepoint == '_')); return valid && getBytes().length() >= 1; }
/** * Is the string this constant represents a valid constant identifier name. */ public boolean validConstantName() { boolean valid = ByteListHelper.eachCodePoint(getBytes(), (int index, int codepoint, Encoding encoding) -> index == 0 && encoding.isUpper(codepoint) || index != 0 && (encoding.isAlnum(codepoint) || !Encoding.isAscii(codepoint) || codepoint == '_')); return valid && getBytes().length() >= 1; }
private void determineIfMaybeUsingMethod(RubySymbol methodName, Operand[] args) { IRScope outerScope = scope.getNearestTopLocalVariableScope(); // 'using single_mod_arg' possible nearly everywhere but method scopes. if (CommonByteLists.USING_METHOD.equals(methodName.getBytes()) && !(outerScope instanceof IRMethod) && args.length == 1) { scope.setIsMaybeUsingRefinements(); } }
private void determineIfProcNew(Node receiverNode, RubySymbol name, CallInstr callInstr) { // This is to support the ugly Proc.new with no block, which must see caller's frame if (CommonByteLists.NEW_METHOD.equals(name.getBytes()) && receiverNode instanceof ConstNode && ((ConstNode)receiverNode).getName().idString().equals("Proc")) { callInstr.setProcNew(true); } }
/** * Is the string this constant represents a valid constant identifier name. */ public boolean validClassVariableName() { boolean valid = ByteListHelper.eachCodePoint(getBytes(), (int index, int codepoint, Encoding encoding) -> index == 0 && codepoint == '@' || index == 1 && codepoint == '@' || index == 2 && (!encoding.isDigit(codepoint)) && (encoding.isAlnum(codepoint) || !Encoding.isAscii(codepoint) || codepoint == '_') || index > 2 && (encoding.isAlnum(codepoint) || !Encoding.isAscii(codepoint) || codepoint == '_')); return valid && getBytes().length() >= 3; // FIXME: good enough on length check? Trying to avoid counter. }
/** * Is the string this constant represents a valid constant identifier name. */ public boolean validClassVariableName() { boolean valid = ByteListHelper.eachCodePoint(getBytes(), (int index, int codepoint, Encoding encoding) -> index == 0 && codepoint == '@' || index == 1 && codepoint == '@' || index == 2 && (!encoding.isDigit(codepoint)) && (encoding.isAlnum(codepoint) || !Encoding.isAscii(codepoint) || codepoint == '_') || index > 2 && (encoding.isAlnum(codepoint) || !Encoding.isAscii(codepoint) || codepoint == '_')); return valid && getBytes().length() >= 3; // FIXME: good enough on length check? Trying to avoid counter. }
/** * Make an instance variable out of this symbol (e.g. :foo will generate :foo=). * @return the new symbol */ public RubySymbol asWriter() { ByteList bytes = getBytes().dup(); bytes.append((byte) '='); return newIDSymbol(getRuntime(), bytes); }
/** * Make an instance variable out of this symbol (e.g. :foo will generate :foo=). * @return the new symbol */ public RubySymbol asWriter() { ByteList bytes = getBytes().dup(); bytes.append((byte) '='); return newIDSymbol(getRuntime(), bytes); }
public RubySymbol asInstanceVariable() { ByteList bytes = getBytes().dup(); bytes.prepend((byte) '@'); return newIDSymbol(getRuntime(), bytes); }
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { lexer.setCurrentArg(null); yyVal = new OptArgNode(support.getPosition(((Node)yyVals[0+yyTop])), support.assignableLabelOrIdentifier(((ArgumentNode)yyVals[-2+yyTop]).getName().getBytes(), ((Node)yyVals[0+yyTop]))); return yyVal; } };
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { lexer.setCurrentArg(null); yyVal = new OptArgNode(support.getPosition(((Node)yyVals[0+yyTop])), support.assignableLabelOrIdentifier(((ArgumentNode)yyVals[-2+yyTop]).getName().getBytes(), ((Node)yyVals[0+yyTop]))); return yyVal; } };
@Deprecated public static RubySymbol newSymbol(Ruby runtime, IRubyObject name) { if (name instanceof RubySymbol) { return runtime.getSymbolTable().getSymbol(((RubySymbol) name).getBytes(), false); } else if (name instanceof RubyString) { return runtime.getSymbolTable().getSymbol(((RubyString) name).getByteList(), false); } else { return newSymbol(runtime, name.asString().getByteList()); } }
private void writeAndRegister(IRubyObject value) throws IOException { ByteList sym; if (value instanceof RubySymbol && cache.isSymbolRegistered(sym = ((RubySymbol) value).getBytes())) { cache.writeSymbolLink(this, sym); } else if (!(value instanceof RubySymbol) && cache.isRegistered(value)) { cache.writeLink(this, value); } else { value.getMetaClass().smartDump(this, value); } }
private void dumpVariablesShared(List<Variable<Object>> vars) throws IOException { for (Variable<Object> var : vars) { if (var.getValue() instanceof IRubyObject) { writeAndRegisterSymbol(RubySymbol.newSymbol(runtime, var.getName()).getBytes()); dumpObject((IRubyObject)var.getValue()); } } }
private void writeAndRegister(IRubyObject value) throws IOException { ByteList sym; if (value instanceof RubySymbol && cache.isSymbolRegistered(sym = ((RubySymbol) value).getBytes())) { cache.writeSymbolLink(this, sym); } else if (!(value instanceof RubySymbol) && cache.isRegistered(value)) { cache.writeLink(this, value); } else { value.getMetaClass().smartDump(this, value); } }
public void dumpDefaultObjectHeader(char tp, RubyClass type) throws IOException { dumpExtended(type); write(tp); writeAndRegisterSymbol(RubySymbol.newSymbol(runtime, getPathFromClass(type.getRealClass())).getBytes()); }
public static RubySymbol newHardSymbol(Ruby runtime, IRubyObject name) { if (name instanceof RubySymbol) { return runtime.getSymbolTable().getSymbol(((RubySymbol) name).getBytes(), true); } else if (name instanceof RubyString) { return runtime.getSymbolTable().getSymbol(((RubyString) name).getByteList(), true); } return newSymbol(runtime, name.asString().getByteList()); }
@Override public void ConstMissingInstr(ConstMissingInstr constmissinginstr) { visit(constmissinginstr.getReceiver()); jvmAdapter().checkcast("org/jruby/RubyModule"); jvmMethod().loadContext(); jvmAdapter().ldc("const_missing"); jvmMethod().pushSymbol(constmissinginstr.getMissingConst().getBytes()); jvmMethod().invokeVirtual(Type.getType(RubyModule.class), Method.getMethod("org.jruby.runtime.builtin.IRubyObject callMethod(org.jruby.runtime.ThreadContext, java.lang.String, org.jruby.runtime.builtin.IRubyObject)")); jvmStoreLocal(constmissinginstr.getResult()); }