/** * raw identifier string (used by method table). */ public String getId() { return name.idString(); }
public AssignableNode addAssign(ISourcePosition position, RubySymbol symbolID, Node value) { int slot = addVariable(symbolID.idString()); // No bit math to store level since we know level is zero for this case return new DAsgnNode(position, symbolID, slot, value); }
/** set_method_visibility * */ public void setMethodVisibility(IRubyObject[] methods, Visibility visibility) { for (int i = 0; i < methods.length; i++) { exportMethod(TypeConverter.checkID(methods[i]).idString(), visibility); } }
public LocalVariable getNewLocalVariable(RubySymbol name, int scopeDepth) { assert scopeDepth == 0: "Scope depth is non-zero for new-var request " + name + " in " + this; LocalVariable lvar = new LocalVariable(name, scopeDepth, getStaticScope().addVariable(name.idString())); localVars.put(name, lvar); return lvar; }
@JRubyMethod(name = "remove_method", rest = true) public RubyModule remove_method(ThreadContext context, IRubyObject[] args) { for(int i=0;i<args.length;i++) { removeMethod(context, TypeConverter.checkID(args[i]).idString()); } return this; }
private IRubyObject defaultObjectUnmarshal() throws IOException { RubySymbol className = (RubySymbol) unmarshalObject(false); RubyClass type = getClassFromPath(runtime, className.idString()); IRubyObject result = (IRubyObject)type.unmarshal(this); return result; }
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); } }
/** * Validates name is a valid constant name and returns its id string. * @param name object to verify as a valid constant. * @return the id for this valid constant name. */ protected final String validateConstant(IRubyObject name) { RubySymbol symbol = RubySymbol.retrieveIDSymbol(name); if (!symbol.validConstantName()) { throw getRuntime().newNameError(str(getRuntime(), "wrong constant name ", name), symbol.idString()); } return symbol.idString(); }
private RubyBoolean constantDefined(Ruby runtime, RubySymbol symbol, boolean inherit) { if (symbol.validConstantName()) { return runtime.newBoolean(getConstantSkipAutoload(symbol.idString(), inherit, inherit) != null); } throw runtime.newNameError(str(runtime, "wrong constant name", ids(runtime, symbol)), symbol.idString()); }
@JRubyMethod(name = "alias_method", required = 2) public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) { RubySymbol newSym = TypeConverter.checkID(newId); RubySymbol oldSym = TypeConverter.checkID(oldId); // MRI uses rb_to_id but we return existing symbol defineAlias(newSym.idString(), oldSym.idString()); if (isSingleton()) { ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym); } else { callMethod(context, "method_added", newSym); } return this; }
protected String validateInstanceVariable(IRubyObject name) { RubySymbol symbol = RubySymbol.retrieveIDSymbol(name); if (!symbol.validInstanceVariableName()) { throw getRuntime().newNameError("`%1$s' is not allowable as an instance variable name", this, name); } return symbol.idString(); }
public static RubySymbol addInstanceMethod(RubyModule containingClass, RubySymbol symbol, DynamicMethod method, Visibility visibility, ThreadContext context, Ruby runtime) { containingClass.addMethod(symbol.idString(), method); if (!containingClass.isRefinement()) callNormalMethodHook(containingClass, context, symbol); if (visibility == Visibility.MODULE_FUNCTION) addModuleMethod(containingClass, method, context, symbol); return symbol; }
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); }
@JRubyMethod(name = "public_method_defined?", required = 1) public IRubyObject public_method_defined(ThreadContext context, IRubyObject symbol) { DynamicMethod method = searchMethod(TypeConverter.checkID(symbol).idString()); return context.runtime.newBoolean(!method.isUndefined() && method.getVisibility() == PUBLIC); }
protected String validateClassVariable(Ruby runtime, IRubyObject object) { RubySymbol name = TypeConverter.checkID(object); if (!name.validClassVariableName()) { throw getRuntime().newNameError(str(runtime, "`", ids(runtime, name), "' is not allowed as a class variable name"), this, object); } return name.idString(); }
@JRubyMethod(name = "private_method_defined?", required = 1) public IRubyObject private_method_defined(ThreadContext context, IRubyObject symbol) { DynamicMethod method = searchMethod(TypeConverter.checkID(symbol).idString()); return context.runtime.newBoolean(!method.isUndefined() && method.getVisibility() == PRIVATE); }
@JRubyMethod(name = "protected_method_defined?", required = 1) public IRubyObject protected_method_defined(ThreadContext context, IRubyObject symbol) { DynamicMethod method = searchMethod(TypeConverter.checkID(symbol).idString()); return context.runtime.newBoolean(!method.isUndefined() && method.getVisibility() == PROTECTED); }
@JIT public static void defCompiledClassMethod(ThreadContext context, MethodHandle handle, IRScope method, IRubyObject obj) { RubySymbol methodName = method.getName(); RubyClass rubyClass = checkClassForDef(context, method, obj); // FIXME: needs checkID and proper encoding to force hard symbol rubyClass.addMethod(methodName.idString(), new CompiledIRMethod(handle, method, Visibility.PUBLIC, rubyClass)); if (!rubyClass.isRefinement()) { // FIXME: needs checkID and proper encoding to force hard symbol obj.callMethod(context, "singleton_method_added", methodName); } }
private int identifierToken(int result, ByteList value) { Ruby runtime = parserSupport.getConfiguration().getRuntime(); String id = runtime.newSymbol(value).idString(); if (result == RubyParser.tIDENTIFIER && !isLexState(last_state, EXPR_DOT|EXPR_FNAME) && parserSupport.getCurrentScope().isDefined(id) >= 0) { setState(EXPR_END|EXPR_LABEL); } yaccValue = value; return result; }
private static void addModuleMethod(RubyModule containingClass, DynamicMethod method, ThreadContext context, RubySymbol sym) { DynamicMethod singletonMethod = method.dup(); singletonMethod.setImplementationClass(containingClass.getSingletonClass()); singletonMethod.setVisibility(Visibility.PUBLIC); containingClass.getSingletonClass().addMethod(sym.idString(), singletonMethod); containingClass.callMethod(context, "singleton_method_added", sym); }