本文整理汇总了C#中Heap.ToHeapObject方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.ToHeapObject方法的具体用法?C# Heap.ToHeapObject怎么用?C# Heap.ToHeapObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.ToHeapObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Unpack
//@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
//@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
/// <summary>
/// Do the recursive unpacking of the data structure into mirror objects
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static Obj Unpack(StackValue val, Heap heap, RuntimeCore runtimeCore, int type = (int)PrimitiveType.Pointer)
{
Executable exe = runtimeCore.DSExecutable;
switch (val.optype)
{
case AddressType.ArrayPointer:
{
DsasmArray ret = new DsasmArray();
//Pull the item out of the heap
var array = heap.ToHeapObject<DSArray>(val);
StackValue[] nodes = array.Values.ToArray();
ret.members = new Obj[array.Count];
for (int i = 0; i < ret.members.Length; i++)
{
ret.members[i] = Unpack(nodes[i], heap, runtimeCore, type);
}
// TODO Jun: ret.members[0] is hardcoded and means we are assuming a homogenous collection
// How to handle mixed-type arrays?
Obj retO = new Obj(val)
{
Payload = ret,
};
return retO;
}
case AddressType.String:
{
string str = heap.ToHeapObject<DSString>(val).Value;
Obj o = new Obj(val)
{
Payload = str,
};
return o;
}
case AddressType.Int:
{
Obj o = new Obj(val)
{
Payload = val.IntegerValue,
};
return o;
}
case AddressType.Boolean:
{
Obj o = new Obj(val)
{
Payload = val.BooleanValue,
};
return o;
}
case AddressType.Null:
{
Obj o = new Obj(val)
{
Payload = null,
};
return o;
}
case AddressType.Char:
{
Obj o = new Obj(val)
{
Payload = val.CharValue,
};
return o;
}
case AddressType.Double:
{
Obj o = new Obj(val)
{
Payload = val.DoubleValue,
};
return o;
}
case AddressType.Pointer:
{
Obj o = new Obj(val)
{
Payload = val.Pointer,
};
return o;
}
case AddressType.FunctionPointer:
{
Obj o = new Obj(val)
{
Payload = val.FunctionPointer,
//.........这里部分代码省略.........
示例2: GetStringValue
public string GetStringValue(StackValue val, Heap heap, int langblock, int maxArraySize, int maxOutputDepth, bool forPrint = false)
{
if (formatParams == null)
formatParams = new OutputFormatParameters(maxArraySize, maxOutputDepth);
if (val.IsInteger)
{
return val.IntegerValue.ToString();
}
else if (val.IsDouble)
{
return val.DoubleValue.ToString("F6");
}
else if (val.IsNull)
{
return "null";
}
else if (val.IsPointer)
{
return GetClassTrace(val, heap, langblock, forPrint);
}
else if (val.IsArray)
{
HashSet<int> pointers = new HashSet<int> { val.ArrayPointer };
string arrTrace = GetArrayTrace(val, heap, langblock, pointers, forPrint);
if (forPrint)
return "{" + arrTrace + "}";
else
return "{ " + arrTrace + " }";
}
else if (val.IsFunctionPointer)
{
ProcedureNode procNode;
if (runtimeCore.DSExecutable.FuncPointerTable.TryGetFunction(val, runtimeCore, out procNode))
{
string className = String.Empty;
if (procNode.ClassID != Constants.kGlobalScope)
{
className = runtimeCore.DSExecutable.classTable.GetTypeName(procNode.ClassID).Split('.').Last() + ".";
}
return "function: " + className + procNode.Name;
}
return "function: " + val.FunctionPointer.ToString();
}
else if (val.IsBoolean)
{
return val.BooleanValue ? "true" : "false";
}
else if (val.IsString)
{
if (forPrint)
return heap.ToHeapObject<DSString>(val).Value;
else
return "\"" + heap.ToHeapObject<DSString>(val).Value + "\"";
}
else if (val.IsChar)
{
Char character = Convert.ToChar(val.CharValue);
if (forPrint)
return character.ToString();
else
return "'" + character + "'";
}
else
{
return "null"; // "Value not yet supported for tracing";
}
}
示例3: GetArrayTrace
private string GetArrayTrace(StackValue svArray, Heap heap, int langblock, HashSet<int> pointers, bool forPrint)
{
if (!formatParams.ContinueOutputTrace())
return "...";
StringBuilder arrayElements = new StringBuilder();
var array = heap.ToHeapObject<DSArray>(svArray);
int halfArraySize = -1;
if (formatParams.MaxArraySize > 0) // If the caller did specify a max value...
{
// And our array is larger than that max value...
if (array.Count > formatParams.MaxArraySize)
halfArraySize = (int)Math.Floor(formatParams.MaxArraySize * 0.5);
}
int totalElementCount = array.Count;
if (svArray.IsArray)
{
totalElementCount = heap.ToHeapObject<DSArray>(svArray).Values.Count();
}
for (int n = 0; n < array.Count; ++n)
{
// As we try to output the next element in the array, there
// should be a comma if there were previously output element.
if (arrayElements.Length > 0)
if(forPrint)
arrayElements.Append(",");
else
arrayElements.Append(", ");
StackValue sv = array.GetValueFromIndex(n, runtimeCore);
if (sv.IsArray)
{
arrayElements.Append(GetPointerTrace(sv, heap, langblock, pointers, forPrint));
}
else
{
arrayElements.Append(GetStringValue(array.GetValueFromIndex(n, runtimeCore), heap, langblock, forPrint));
}
// If we need to truncate this array (halfArraySize > 0), and we have
// already reached the first half of it, then offset the loop counter
// to the next half of the array.
if (halfArraySize > 0 && (n == halfArraySize - 1))
{
arrayElements.Append(", ...");
n = totalElementCount - halfArraySize - 1;
}
}
formatParams.RestoreOutputTraceDepth();
return arrayElements.ToString();
}
示例4: GetClassTrace
public string GetClassTrace(StackValue val, Heap heap, int langblock, bool forPrint)
{
if (!formatParams.ContinueOutputTrace())
return "...";
RuntimeMemory rmem = MirrorTarget.rmem;
Executable exe = MirrorTarget.exe;
ClassTable classTable = MirrorTarget.RuntimeCore.DSExecutable.classTable;
int classtype = val.metaData.type;
if (classtype < 0 || (classtype >= classTable.ClassNodes.Count))
{
formatParams.RestoreOutputTraceDepth();
return string.Empty;
}
ClassNode classnode = classTable.ClassNodes[classtype];
if (classnode.IsImportedClass)
{
var helper = DLLFFIHandler.GetModuleHelper(FFILanguage.CSharp);
var marshaller = helper.GetMarshaller(runtimeCore);
var strRep = marshaller.GetStringValue(val);
formatParams.RestoreOutputTraceDepth();
return strRep;
}
else
{
var obj = heap.ToHeapObject<DSObject>(val);
List<string> visibleProperties = null;
if (null != propertyFilter)
{
if (!propertyFilter.TryGetValue(classnode.Name, out visibleProperties))
visibleProperties = null;
}
StringBuilder classtrace = new StringBuilder();
if (classnode.Symbols != null && classnode.Symbols.symbolList.Count > 0)
{
bool firstPropertyDisplayed = false;
for (int n = 0; n < obj.Count; ++n)
{
SymbolNode symbol = classnode.Symbols.symbolList[n];
string propName = symbol.name;
if ((null != visibleProperties) && visibleProperties.Contains(propName) == false)
continue; // This property is not to be displayed.
if (firstPropertyDisplayed)
classtrace.Append(", ");
string propValue = "";
if (symbol.isStatic)
{
var staticSymbol = exe.runtimeSymbols[langblock].symbolList[symbol.symbolTableIndex];
StackValue staticProp = rmem.GetSymbolValue(staticSymbol);
propValue = GetStringValue(staticProp, heap, langblock, forPrint);
}
else
{
propValue = GetStringValue(obj.GetValueFromIndex(symbol.index, runtimeCore), heap, langblock, forPrint);
}
classtrace.Append(string.Format("{0} = {1}", propName, propValue));
firstPropertyDisplayed = true;
}
}
else
{
var stringValues = obj.Values.Select(x => GetStringValue(x, heap, langblock, forPrint))
.ToList();
for (int n = 0; n < stringValues.Count(); ++n)
{
if (0 != n)
classtrace.Append(", ");
classtrace.Append(stringValues[n]);
}
}
formatParams.RestoreOutputTraceDepth();
if (classtype >= (int)ProtoCore.PrimitiveType.MaxPrimitive)
if (forPrint)
return (string.Format("{0}{{{1}}}", classnode.Name, classtrace.ToString()));
else
{
string tempstr = (string.Format("{0}({1})", classnode.Name, classtrace.ToString()));
return tempstr;
}
return classtrace.ToString();
}
}
示例5: GetStringValue
public string GetStringValue(StackValue val, Heap heap, int langblock, int maxArraySize, int maxOutputDepth, bool forPrint = false)
{
if (formatParams == null)
formatParams = new OutputFormatParameters(maxArraySize, maxOutputDepth);
switch (val.optype)
{
case AddressType.Int:
return val.opdata.ToString();
case AddressType.Double:
return val.RawDoubleValue.ToString(runtimeCore.Options.FormatToPrintFloatingPoints);
case AddressType.Null:
return "null";
case AddressType.Pointer:
return GetClassTrace(val, heap, langblock, forPrint);
case AddressType.ArrayPointer:
HashSet<int> pointers = new HashSet<int>{(int)val.opdata};
string arrTrace = GetArrayTrace(val, heap, langblock, pointers, forPrint);
if (forPrint)
return "{" + arrTrace + "}";
else
return "{ " + arrTrace + " }";
case AddressType.FunctionPointer:
ProcedureNode procNode;
if (runtimeCore.DSExecutable.FuncPointerTable.TryGetFunction(val, runtimeCore, out procNode))
{
string className = String.Empty;
if (procNode.classScope != Constants.kGlobalScope)
{
className = runtimeCore.DSExecutable.classTable.GetTypeName(procNode.classScope).Split('.').Last() + ".";
}
return "function: " + className + procNode.name;
}
return "function: " + val.opdata.ToString();
case AddressType.Boolean:
return (val.opdata == 0) ? "false" : "true";
case AddressType.String:
if (forPrint)
return heap.ToHeapObject<DSString>(val).Value;
else
return "\"" + heap.ToHeapObject<DSString>(val).Value + "\"";
case AddressType.Char:
Char character = ProtoCore.Utils.EncodingUtils.ConvertInt64ToCharacter(val.opdata);
if (forPrint)
return character.ToString();
else
return "'" + character + "'";
default:
return "null"; // "Value not yet supported for tracing";
}
}
示例6: Unpack
//@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
//@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
/// <summary>
/// Do the recursive unpacking of the data structure into mirror objects
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static Obj Unpack(StackValue val, Heap heap, RuntimeCore runtimeCore, int type = (int)PrimitiveType.kTypePointer)
{
Executable exe = runtimeCore.DSExecutable;
switch (val.optype)
{
case AddressType.ArrayPointer:
{
DsasmArray ret = new DsasmArray();
//Pull the item out of the heap
var array = heap.ToHeapObject<DSArray>(val);
StackValue[] nodes = array.VisibleItems.ToArray();
ret.members = new Obj[array.VisibleSize];
for (int i = 0; i < ret.members.Length; i++)
{
ret.members[i] = Unpack(nodes[i], heap, runtimeCore, type);
}
// TODO Jun: ret.members[0] is hardcoded and means we are assuming a homogenous collection
// How to handle mixed-type arrays?
Obj retO = new Obj(val)
{
Payload = ret,
Type = exe.TypeSystem.BuildTypeObject(
(ret.members.Length > 0)
? exe.TypeSystem.GetType(ret.members[0].Type.Name)
: (int)ProtoCore.PrimitiveType.kTypeVoid, Constants.kArbitraryRank)
};
return retO;
}
case AddressType.String:
{
string str = heap.ToHeapObject<DSString>(val).Value;
Obj o = new Obj(val)
{
Payload = str,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeString, 0)
};
return o;
}
case AddressType.Int:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = data,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 0)
};
return o;
}
case AddressType.Boolean:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = (data != 0),
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeBool, 0)
};
return o;
}
case AddressType.Null:
{
Obj o = new Obj(val)
{
Payload = null,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0)
};
return o;
}
case AddressType.Char:
{
Int64 data = val.opdata;
Obj o = new Obj(val)
{
Payload = data,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeChar, 0)
};
return o;
}
case AddressType.Double:
{
double data = val.RawDoubleValue;
Obj o = new Obj(val)
{
Payload = data, Type =
TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0)
};
return o;
//.........这里部分代码省略.........