if (keyType.equals(RubySymbol.newSymbol(runtime, "float")) || keyType.equals(RubySymbol.newSymbol(runtime, "double")) || keyType.equals(RubySymbol.newSymbol(runtime, "enum")) || keyType.equals(RubySymbol.newSymbol(runtime, "message"))) throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type."); IRubyObject mapentryDescName = RubySymbol.newSymbol(runtime, name).id2name(context); mapentryDesc.setName(context, mapentryDescName); mapentryDesc.setMapEntry(true); keyField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); keyField.setNumber(context, runtime.newFixnum(1)); keyField.setType(context, keyType); valueField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); valueField.setNumber(context, runtime.newFixnum(2)); valueField.setType(context, valueType);
/** * Gets the methodName. * @return Returns a String */ public String getOperatorName() { return operatorName.asJavaString(); }
/** fix_id2name * */ @JRubyMethod public IRubyObject id2name() { RubySymbol symbol = RubySymbol.getSymbolLong(getRuntime(), value); if (symbol != null) return getRuntime().newString(symbol.asJavaString()); return getRuntime().getNil(); }
private RubyMap newMapForField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor) { RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor); Descriptors.FieldDescriptor keyField = fieldDescriptor.getMessageType().findFieldByNumber(1); Descriptors.FieldDescriptor valueField = fieldDescriptor.getMessageType().findFieldByNumber(2); IRubyObject keyType = RubySymbol.newSymbol(context.runtime, keyField.getType().name()); IRubyObject valueType = RubySymbol.newSymbol(context.runtime, valueField.getType().name()); if (valueField.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) { RubyFieldDescriptor rubyFieldDescriptor = (RubyFieldDescriptor) mapDescriptor.lookup(context, context.runtime.newString("value")); RubyDescriptor rubyDescriptor = (RubyDescriptor) rubyFieldDescriptor.getSubType(context); return (RubyMap) cMap.newInstance(context, keyType, valueType, rubyDescriptor.msgclass(context), Block.NULL_BLOCK); } else { return (RubyMap) cMap.newInstance(context, keyType, valueType, Block.NULL_BLOCK); } }
private IRubyObject defaultObjectUnmarshal() throws IOException { RubySymbol className = (RubySymbol) unmarshalObject(false); RubyClass type = null; try { type = getClassFromPath(runtime, className.toString()); } catch (RaiseException e) { if (runtime.getModule("NameError").isInstance(e.getException())) { throw runtime.newArgumentError("undefined class/module " + className.asJavaString()); } throw e; } assert type != null : "type shouldn't be null."; IRubyObject result = (IRubyObject)type.unmarshal(this); return result; }
@JRubyMethod(name = "lookup_oneof") public IRubyObject lookupOneof(ThreadContext context, IRubyObject name) { if (name instanceof RubySymbol) { name = ((RubySymbol) name).id2name(); } return oneofDefs.containsKey(name) ? oneofDefs.get(name) : context.runtime.getNil(); }
/** * 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); }
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); } }
@JRubyMethod(name = "capitalize", compat = CompatVersion.RUBY1_9) public IRubyObject capitalize(ThreadContext context) { Ruby runtime = context.runtime; return newSymbol(runtime, rubyStringFromString(runtime).capitalize19(context).toString()); }
symbol = new RubySymbol(runtime, internedName); table[index] = new SymbolEntry(hash, internedName, symbol.getBytes(), symbol, table[index], hard); size++;
@Override protected String toString(RubySymbol obj) { return obj.toString(); }
private RubySymbol createSymbol(String name, ByteList value, int hash, SymbolEntry[] table) { ReentrantLock lock; (lock = tableLock).lock(); try { int index; int potentialNewSize = size + 1; table = potentialNewSize > threshold ? rehash() : symbolTable; // try lookup again under lock for (SymbolEntry e = table[index = hash & (table.length - 1)]; e != null; e = e.next) { if (hash == e.hash && name.equals(e.name)) return e.symbol; } String internedName = name.intern(); RubySymbol symbol = new RubySymbol(runtime, internedName, value); table[index] = new SymbolEntry(hash, internedName, symbol, table[index]); size = potentialNewSize; // write-volatile symbolTable = table; return symbol; } finally { lock.unlock(); } }
/** inspect_obj * * The internal helper method that takes care of the part of the * inspection that inspects instance variables. */ private RubyString inspectObj(final Ruby runtime, RubyString part) { final ThreadContext context = runtime.getCurrentContext(); boolean first = true; for (Map.Entry<String, VariableAccessor> entry : metaClass.getVariableTableManager().getVariableAccessorsForRead().entrySet()) { Object value = entry.getValue().get(this); RubySymbol symbol = runtime.newSymbol(entry.getKey()); if (!(value instanceof IRubyObject) || !symbol.validInstanceVariableName()) continue; IRubyObject obj = (IRubyObject) value; if (!first) encStrBufCat(runtime, part, INSPECT_COMMA); encStrBufCat(runtime, part, INSPECT_SPACE); // FIXME: bytelist_love: EPICLY wrong but something in MRI gets around identifiers of arbitrary encoding. encStrBufCat(runtime, part, symbol.asString().encode(context, runtime.getEncodingService().convertEncodingToRubyEncoding(part.getEncoding())).asString().getByteList()); encStrBufCat(runtime, part, INSPECT_EQUALS); encStrBufCat(runtime, part, sites(context).inspect.call(context, obj, obj).convertToString().getByteList()); first = false; } encStrBufCat(runtime, part, INSPECT_GT); return part; }
@Override public boolean shouldMarshalEncoding() { Encoding enc = getMarshalEncoding(); return enc != USASCIIEncoding.INSTANCE && enc != ASCIIEncoding.INSTANCE; }
public final Type findType(Ruby runtime, RubySymbol name) { Object obj = name.getFFIHandle(); if (obj instanceof Type) { return ((Type) obj); } Type type = symbolTypeCache.get(name); if (type != null) { return type; } return lookupAndCacheType(runtime, name); }
RubySymbol.createSymbolClass(this);
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); } }
private static Encoding extractEncodingFromObject(IRubyObject obj) { if (obj instanceof RubyEncoding) return ((RubyEncoding) obj).getEncoding(); if (obj instanceof RubySymbol) return ((RubySymbol) obj).asString().getEncoding(); if (obj instanceof EncodingCapable) return ((EncodingCapable) obj).getEncoding(); return null; }