本文整理汇总了C#中ProtoCore.Type类的典型用法代码示例。如果您正苦于以下问题:C# ProtoCore.Type类的具体用法?C# ProtoCore.Type怎么用?C# ProtoCore.Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtoCore.Type类属于命名空间,在下文中一共展示了ProtoCore.Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SymbolNode
public SymbolNode(
string name,
int index,
int functionIndex,
Type datatype,
bool isArgument,
int runtimeIndex,
MemoryRegion memregion = MemoryRegion.InvalidRegion,
int scope = -1,
CompilerDefinitions.AccessModifier access = CompilerDefinitions.AccessModifier.Public,
bool isStatic = false,
int codeBlockId = Constants.kInvalidIndex)
{
this.name = name;
isTemp = name.StartsWith("%");
isSSATemp = name.StartsWith(Constants.kSSATempPrefix);
this.index = index;
this.functionIndex = functionIndex;
this.absoluteFunctionIndex = functionIndex;
this.datatype = datatype;
this.isArgument = isArgument;
this.memregion = memregion;
this.classScope = scope;
this.absoluteClassScope = scope;
runtimeTableIndex = runtimeIndex;
this.access = access;
this.isStatic = isStatic;
this.codeBlockId = codeBlockId;
}
示例2: DescriptionTest
public void DescriptionTest()
{
var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll");
var testClass = assembly.GetType("FFITarget.DummyZeroTouchClass");
MethodInfo methodWithDesc = testClass.GetMethod("FunctionWithDescription");
MethodInfo methodWithoutDesc = testClass.GetMethod("FunctionWithoutDescription");
NodeDescriptionAttribute atr = new NodeDescriptionAttribute("");
IEnumerable<TypedParameter> arguments;
FunctionDescriptor fucDescriptor;
// 1 case. Method with description.
var attributes = methodWithDesc.GetCustomAttributes(typeof(NodeDescriptionAttribute), false);
Assert.IsNotNull(attributes);
Assert.Greater(attributes.Length, 0);
atr = attributes[0] as NodeDescriptionAttribute;
arguments = methodWithDesc.GetParameters().Select(
arg =>
{
var type = new ProtoCore.Type();
type.Name = arg.ParameterType.ToString();
return new TypedParameter(arg.Name, type);
});
fucDescriptor = new FunctionDescriptor(new FunctionDescriptorParams
{
FunctionName = methodWithDesc.Name,
Summary = atr.ElementDescription,
Parameters = arguments
});
NodeModel node = new DSFunction(fucDescriptor);
Assert.AreEqual(atr.ElementDescription + "\n\n" + fucDescriptor.Signature, node.Description);
// 2 case. Method without description.
atr = new NodeDescriptionAttribute("");
attributes = methodWithoutDesc.GetCustomAttributes(typeof(NodeDescriptionAttribute), false);
Assert.IsNotNull(attributes);
Assert.AreEqual(attributes.Length, 0);
arguments = methodWithoutDesc.GetParameters().Select(
arg =>
{
var type = new ProtoCore.Type();
type.Name = arg.ParameterType.ToString();
return new TypedParameter(arg.Name, type);
});
fucDescriptor = new FunctionDescriptor(new FunctionDescriptorParams
{
FunctionName = methodWithDesc.Name,
Summary = atr.ElementDescription,
Parameters = arguments
});
node = new DSFunction(fucDescriptor);
Assert.AreEqual(fucDescriptor.Signature, node.Description);
}
示例3: CLRFFIFunctionPointer
public CLRFFIFunctionPointer(CLRDLLModule module, string name, MemberInfo info, List<ProtoCore.Type> argTypes, ProtoCore.Type returnType)
{
Module = module;
Name = name;
ReflectionInfo = FFIMemberInfo.CreateFrom(info);
if (argTypes == null)
mArgTypes = GetArgumentTypes(ReflectionInfo);
else
mArgTypes = argTypes.ToArray();
mReturnType = returnType;
}
示例4: SymbolNode
public SymbolNode(
string name,
int index,
int heapIndex,
int functionIndex,
ProtoCore.Type datatype,
ProtoCore.Type enforcedType,
int size,
int datasize,
bool isArgument,
int runtimeIndex,
MemoryRegion memregion = MemoryRegion.kInvalidRegion,
bool isArray = false,
List<int> arraySizeList = null,
int scope = -1,
ProtoCore.CompilerDefinitions.AccessModifier access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
bool isStatic = false,
int codeBlockId = ProtoCore.DSASM.Constants.kInvalidIndex)
{
this.name = name;
isTemp = name.StartsWith("%");
this.index = index;
this.functionIndex = functionIndex;
this.absoluteFunctionIndex = functionIndex;
this.datatype = datatype;
this.staticType = enforcedType;
this.size = size;
this.datasize = datasize;
this.isArgument = isArgument;
this.arraySizeList = arraySizeList;
this.memregion = memregion;
this.classScope = scope;
this.absoluteClassScope = scope;
runtimeTableIndex = runtimeIndex;
this.access = access;
this.isStatic = isStatic;
this.codeBlockId = codeBlockId;
}
示例5: PInvokeFunctionPointer
public PInvokeFunctionPointer(PInvokeDLLModule module, String name, ProtoCore.Type returnType)
{
Module = module;
Name = name;
mReturnType = returnType;
//mFunction = new FFICppFunction(module.Name, name);
mFunction = new FFICppFunction(module.ModuleBuilder, module.AssemblyName, module.AssemblyBuilder, name);
}
示例6: ProcessDynamicFunction
private bool ProcessDynamicFunction(Instruction instr)
{
int fptr = ProtoCore.DSASM.Constants.kInvalidIndex;
int functionDynamicIndex = (int)instr.op1.opdata;
int classIndex = (int)instr.op2.opdata;
int depth = (int)instr.op3.opdata;
bool isDotMemFuncBody = functionDynamicIndex == ProtoCore.DSASM.Constants.kInvalidIndex;
bool isFunctionPointerCall = false;
if (isDotMemFuncBody)
{
functionDynamicIndex = (int)rmem.Pop().opdata;
}
DSASM.DynamicFunctionNode dynamicFunctionNode = core.DynamicFunctionTable.functionTable[functionDynamicIndex];
if (isDotMemFuncBody)
{
classIndex = dynamicFunctionNode.classIndex;
}
string procName = dynamicFunctionNode.functionName;
List<ProtoCore.Type> arglist = dynamicFunctionNode.argList;
if (procName == ProtoCore.DSASM.Constants.kFunctionPointerCall && depth == 0)
{
isFunctionPointerCall = true;
classIndex = ProtoCore.DSASM.Constants.kGlobalScope;
StackValue fpSv = rmem.Pop();
if (fpSv.optype != AddressType.FunctionPointer)
{
rmem.Pop(arglist.Count); //remove the arguments
return false;
}
fptr = (int)fpSv.opdata;
}
//retrieve the function arguments
List<StackValue> argSvList = new List<StackValue>();
if (isDotMemFuncBody)
{
arglist = new List<Type>();
StackValue argArraySv = rmem.Pop();
for (int i = 0; i < ArrayUtils.GetElementSize(argArraySv, core); ++i)
{
StackValue sv = core.Heap.Heaplist[(int)argArraySv.opdata].Stack[i];
argSvList.Add(sv); //actual arguments
ProtoCore.Type paramType = new ProtoCore.Type();
paramType.UID = (int)sv.metaData.type;
paramType.rank = 0;
if (sv.optype == AddressType.ArrayPointer)
{
StackValue paramSv = sv;
while (paramSv.optype == AddressType.ArrayPointer)
{
paramType.rank++;
int arrayHeapPtr = (int)paramSv.opdata;
if (core.Heap.Heaplist[arrayHeapPtr].VisibleSize > 0)
{
paramSv = core.Heap.Heaplist[arrayHeapPtr].Stack[0];
paramType.UID = (int)paramSv.metaData.type;
}
else
{
paramType.UID = (int)ProtoCore.PrimitiveType.kTypeArray;
break;
}
}
}
arglist.Add(paramType); //build arglist
}
argSvList.Reverse();
}
else
{
for (int i = 0; i < arglist.Count; i++)
{
StackValue argSv = rmem.Pop();
argSvList.Add(argSv);
}
}
int lefttype = DSASM.Constants.kGlobalScope;
bool isLeftClass = false;
if (isDotMemFuncBody && rmem.Stack.Last().optype == AddressType.Int) //constructor or static function
{
//in this case, ptr won't be used
lefttype = (int)rmem.Pop().opdata;
isLeftClass = true;
}
else if (depth > 0)
{
//resolve the identifier list
StackValue pSv = GetFinalPointer(depth);
//push the resolved stack value to stack
rmem.Push(pSv);
lefttype = (int)pSv.metaData.type;
}
int type = lefttype;
//.........这里部分代码省略.........
示例7: Associative_DecoratedIdentifier
void Associative_DecoratedIdentifier(out ProtoCore.AST.AssociativeAST.AssociativeNode node)
{
node = null;
if (IsTypedVariable()) {
Expect(1);
if (IsKeyWord(t.val, true))
{
errors.SemErr(t.line, t.col, String.Format("\"{0}\" is a keyword, identifier expected", t.val));
}
var typedVar = new ProtoCore.AST.AssociativeAST.TypedIdentifierNode();
typedVar.Name = typedVar.Value = t.val;
NodeUtils.SetNodeLocation(typedVar, t);
Expect(48);
Expect(1);
int type = core.TypeSystem.GetType(t.val);
if (type == ProtoCore.DSASM.Constants.kInvalidIndex)
{
var unknownType = new ProtoCore.Type();
unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex;
unknownType.Name = t.val;
typedVar.datatype = unknownType;
}
else
{
typedVar.datatype = core.TypeSystem.BuildTypeObject(type, false, 0);
}
if (la.kind == 7) {
var datatype = typedVar.datatype;
Get();
Expect(8);
datatype.rank = 1;
if (la.kind == 7 || la.kind == 21) {
if (la.kind == 21) {
Get();
Expect(7);
Expect(8);
datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
} else {
while (la.kind == 7) {
Get();
Expect(8);
datatype.rank++;
}
}
}
typedVar.datatype = datatype;
}
node = typedVar;
} else if (la.kind == 1 || la.kind == 9 || la.kind == 44) {
Associative_IdentifierList(out node);
} else SynErr(94);
}
示例8: BuildRealDependencyForIdentList
protected void BuildRealDependencyForIdentList(AssociativeGraph.GraphNode graphNode)
{
if (ssaPointerStack.Count == 0)
{
return;
}
// Push all dependent pointers
ProtoCore.AST.AssociativeAST.IdentifierListNode identList = BuildIdentifierList(ssaPointerStack.Peek());
// Comment Jun: perhaps this can be an assert?
if (null != identList)
{
ProtoCore.Type type = new ProtoCore.Type();
type.UID = globalClassIndex;
ProtoCore.AssociativeGraph.UpdateNodeRef nodeRef = new AssociativeGraph.UpdateNodeRef();
int functionIndex = globalProcIndex;
DFSGetSymbolList_Simple(identList, ref type, ref functionIndex, nodeRef);
if (null != graphNode && nodeRef.nodeList.Count > 0)
{
ProtoCore.AssociativeGraph.GraphNode dependentNode = new ProtoCore.AssociativeGraph.GraphNode();
dependentNode.updateNodeRefList.Add(nodeRef);
graphNode.PushDependent(dependentNode);
// If the pointerList is a setter, then it should also be in the lhs of a graphNode
// Given:
// a.x = 1
// Which was converted to:
// tvar = a.set_x(1)
// Set a.x as lhs of the graphnode.
// This means that statement that depends on a.x can re-execute, such as:
// p = a.x;
//
List<ProtoCore.AST.AssociativeAST.AssociativeNode> topList = ssaPointerStack.Peek();
string propertyName = topList[topList.Count - 1].Name;
bool isSetter = propertyName.StartsWith(Constants.kSetterPrefix);
if (isSetter)
{
graphNode.updateNodeRefList.Add(nodeRef);
graphNode.IsLHSIdentList = true;
AutoGenerateUpdateArgumentReference(nodeRef, graphNode);
}
}
}
}
示例9: functiondecl
void functiondecl(out Node node)
{
FunctionDefinitionNode funcDecl = new FunctionDefinitionNode();
ProtoCore.Type rtype = new ProtoCore.Type(); rtype.Name = "var"; rtype.UID = 0;
Expect(18);
Expect(1);
funcDecl.Name = t.val;
if (la.kind == 36) {
Get();
ReturnType(out rtype);
}
funcDecl.ReturnType = rtype;
Expect(8);
if (la.kind == 1 || la.kind == 25) {
ArgumentSignatureNode args = new ArgumentSignatureNode();
Node argdecl;
ArgDecl(out argdecl);
args.AddArgument(argdecl as VarDeclNode);
while (la.kind == 30) {
Get();
ArgDecl(out argdecl);
args.AddArgument(argdecl as VarDeclNode);
}
funcDecl.Signature = args;
}
Expect(9);
isGlobalScope = false;
Expect(32);
funcDecl.FunctionBody = new CodeBlockNode();
NodeList body = new NodeList();
stmtlist(out body);
Expect(33);
funcDecl.localVars = localVarCount;
funcDecl.FunctionBody.Body = body;
node = funcDecl;
isGlobalScope = true;
localVarCount= 0;
}
示例10: BuildRealDependencyForIdentList
protected void BuildRealDependencyForIdentList(AssociativeGraph.GraphNode graphNode)
{
// Push all dependent pointers
ProtoCore.AST.AssociativeAST.IdentifierListNode identList = BuildIdentifierList(ssaPointerList);
// Comment Jun: perhaps this can be an assert?
if (null != identList)
{
ProtoCore.Type type = new ProtoCore.Type();
type.UID = globalClassIndex;
ProtoCore.AssociativeGraph.UpdateNodeRef nodeRef = new AssociativeGraph.UpdateNodeRef();
int functionIndex = globalProcIndex;
DFSGetSymbolList_Simple(identList, ref type, ref functionIndex, nodeRef);
if (null != graphNode && nodeRef.nodeList.Count > 0)
{
ProtoCore.AssociativeGraph.GraphNode dependentNode = new ProtoCore.AssociativeGraph.GraphNode();
dependentNode.updateNodeRefList.Add(nodeRef);
graphNode.PushDependent(dependentNode);
}
}
}
示例11: Imperative_ReturnType
void Imperative_ReturnType(out ProtoCore.Type type) {
ProtoCore.Type rtype = new ProtoCore.Type();
Expect(1);
rtype.Name = t.val; rtype.rank = 0;
if (la.kind == 10) {
Get();
Expect(11);
rtype.rank = 1;
if (la.kind == 10 || la.kind == 24) {
if (la.kind == 24) {
Get();
Expect(10);
Expect(11);
rtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
} else {
while (la.kind == 10) {
Get();
Expect(11);
rtype.rank++;
}
}
}
}
type = rtype;
}
示例12: TestRoundTrip_FunctionDefAndCall_01
public void TestRoundTrip_FunctionDefAndCall_01()
{
//=================================
// 1. Build AST
// 2. Execute AST and verify
// 3. Convert AST to source
// 4. Execute source and verify
//=================================
int result1 = 20;
ExecutionMirror mirror = null;
// 1. Build the AST tree
// def foo()
// {
// b = 10;
// return = b + 10;
// }
//
// x = foo();
ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
// Build the function body
ProtoCore.AST.AssociativeAST.BinaryExpressionNode assignment1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
new ProtoCore.AST.AssociativeAST.IntNode(10),
ProtoCore.DSASM.Operator.assign);
ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnExpr = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
new ProtoCore.AST.AssociativeAST.IntNode(10),
ProtoCore.DSASM.Operator.add);
ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
new ProtoCore.AST.AssociativeAST.IdentifierNode(ProtoCore.DSDefinitions.Keyword.Return),
returnExpr,
ProtoCore.DSASM.Operator.assign);
cbn.Body.Add(assignment1);
cbn.Body.Add(returnNode);
// Build the function definition foo
const string functionName = "foo";
ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
funcDefNode.Name = functionName;
funcDefNode.FunctionBody = cbn;
// Function Return type
ProtoCore.Type returnType = new ProtoCore.Type();
returnType.Initialize();
returnType.UID = (int)ProtoCore.PrimitiveType.Var;
returnType.Name = ProtoCore.DSDefinitions.Keyword.Var;
funcDefNode.ReturnType = returnType;
List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
astList.Add(funcDefNode);
// Build the statement that calls the function foo
ProtoCore.AST.AssociativeAST.FunctionCallNode functionCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
functionCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode(functionName);
ProtoCore.AST.AssociativeAST.BinaryExpressionNode callstmt = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
new ProtoCore.AST.AssociativeAST.IdentifierNode("x"),
functionCall,
ProtoCore.DSASM.Operator.assign);
astList.Add(callstmt);
// 2. Execute AST and verify
mirror = thisTest.RunASTSource(astList);
Assert.IsTrue((Int64)mirror.GetValue("x").Payload == result1);
// 3. Convert AST to source
ProtoCore.CodeGenDS codegenDS = new ProtoCore.CodeGenDS(astList);
string code = codegenDS.GenerateCode();
Console.WriteLine(code);
// 4. Execute source and verify
mirror = thisTest.RunScriptSource(code);
Assert.IsTrue((Int64)mirror.GetValue("x").Payload == result1);
}
示例13: Imperative_decoratedIdentifier
void Imperative_decoratedIdentifier(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {
node = null;
if (IsLocallyTypedVariable()) {
Expect(1);
if (IsKeyWord(t.val, true))
{
errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
}
var typedVar = new ProtoCore.AST.ImperativeAST.TypedIdentifierNode();
typedVar.Name = typedVar.Value = t.val;
NodeUtils.SetNodeLocation(typedVar, t);
Expect(47);
Expect(40);
typedVar.IsLocal = true;
Expect(1);
int type = core.TypeSystem.GetType(t.val);
if (type == ProtoCore.DSASM.Constants.kInvalidIndex)
{
var unknownType = new ProtoCore.Type();
unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex;
unknownType.Name = t.val;
typedVar.DataType = unknownType;
}
else
{
typedVar.DataType = core.TypeSystem.BuildTypeObject(type, 0);
}
if (la.kind == 10) {
var datatype = typedVar.DataType;
Get();
Expect(11);
datatype.rank = 1;
if (la.kind == 10 || la.kind == 24) {
if (la.kind == 24) {
Get();
Expect(10);
Expect(11);
datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
} else {
while (la.kind == 10) {
Get();
Expect(11);
datatype.rank++;
}
}
}
typedVar.DataType = datatype;
}
node = typedVar;
} else if (IsLocalVariable()) {
Expect(1);
if (IsKeyWord(t.val, true))
{
errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
}
var identNode = new ProtoCore.AST.ImperativeAST.IdentifierNode();
identNode.Name = identNode.Value = t.val;
NodeUtils.SetNodeLocation(identNode, t);
Expect(47);
Expect(40);
identNode.IsLocal = true;
node = identNode;
} else if (IsTypedVariable()) {
Expect(1);
if (IsKeyWord(t.val, true))
{
errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
}
var typedVar = new ProtoCore.AST.ImperativeAST.TypedIdentifierNode();
typedVar.Name = typedVar.Value = t.val;
NodeUtils.SetNodeLocation(typedVar, t);
Expect(47);
Expect(1);
int type = core.TypeSystem.GetType(t.val);
if (type == ProtoCore.DSASM.Constants.kInvalidIndex)
{
var unknownType = new ProtoCore.Type();
unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex;
unknownType.Name = t.val;
typedVar.DataType = unknownType;
}
else
{
typedVar.DataType = core.TypeSystem.BuildTypeObject(type, 0);
}
if (la.kind == 10) {
var datatype = typedVar.DataType;
Get();
Expect(11);
datatype.rank = 1;
if (la.kind == 10 || la.kind == 24) {
if (la.kind == 24) {
Get();
//.........这里部分代码省略.........
示例14: Imperative_ArgDecl
void Imperative_ArgDecl(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {
ProtoCore.AST.ImperativeAST.IdentifierNode tNode = null;
ProtoCore.AST.ImperativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.ImperativeAST.VarDeclNode();
NodeUtils.SetNodeLocation(varDeclNode, la);
varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.MemStack;
Expect(1);
if (IsKeyWord(t.val, true))
{
errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
}
tNode = BuildImperativeIdentifier(t.val);
NodeUtils.SetNodeLocation(tNode, t);
varDeclNode.NameNode = tNode;
NodeUtils.CopyNodeLocation(varDeclNode, tNode);
ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = "var"; argtype.rank = 0; argtype.UID = 0;
if (la.kind == 47) {
Get();
Expect(1);
argtype.Name = t.val;
if (la.kind == 10) {
Get();
Expect(11);
argtype.rank = 1;
if (la.kind == 10 || la.kind == 24) {
if (la.kind == 24) {
Get();
Expect(10);
Expect(11);
argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
} else {
while (la.kind == 10) {
Get();
Expect(11);
argtype.rank++;
}
}
}
}
}
varDeclNode.ArgumentType = argtype;
node = varDeclNode;
if(!isGlobalScope) {
localVarCount++;
}
}
示例15: Associative_ClassReference
void Associative_ClassReference(out ProtoCore.Type type) {
type = new ProtoCore.Type();
string name;
Expect(1);
name = t.val;
type.Name = name;
type.UID = 0;
}