本文整理汇总了C#中ProtoCore.DSASM.ClassNode类的典型用法代码示例。如果您正苦于以下问题:C# ClassNode类的具体用法?C# ClassNode怎么用?C# ClassNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassNode类属于ProtoCore.DSASM命名空间,在下文中一共展示了ClassNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassNode
public ClassNode(ClassNode rhs)
{
IsImportedClass = rhs.IsImportedClass;
name = rhs.name;
size = rhs.size;
hasCachedDisposeMethod = rhs.hasCachedDisposeMethod;
disposeMethod = rhs.disposeMethod;
rank = rhs.rank;
symbols = new SymbolTable("classscope", 0);
if (rhs.symbols != null)
{
symbols = new SymbolTable(rhs.symbols.ScopeName, rhs.symbols.RuntimeIndex);
}
defaultArgExprList = new List<AST.AssociativeAST.AssociativeNode>();
classId = rhs.classId;
int classRuntimProc = ProtoCore.DSASM.Constants.kInvalidIndex;
vtable = new ProcedureTable(classRuntimProc);
if (rhs.vtable != null)
{
vtable = new ProcedureTable(rhs.vtable);
}
baseList = new List<int>(rhs.baseList);
ExternLib = rhs.ExternLib;
typeSystem = rhs.typeSystem;
coerceTypes = new Dictionary<int, int>(rhs.coerceTypes);
}
示例2: ClassNode
public ClassNode(ClassNode rhs)
{
IsImportedClass = rhs.IsImportedClass;
Name = rhs.Name;
Size = rhs.Size;
hasCachedDisposeMethod = rhs.hasCachedDisposeMethod;
disposeMethod = rhs.disposeMethod;
Rank = rhs.Rank;
Symbols = new SymbolTable("classscope", 0);
if (rhs.Symbols != null)
{
Symbols = new SymbolTable(rhs.Symbols.ScopeName, rhs.Symbols.RuntimeIndex);
}
DefaultArgExprList = new List<AST.AssociativeAST.AssociativeNode>();
ID = rhs.ID;
int classRuntimProc = ProtoCore.DSASM.Constants.kInvalidIndex;
ProcTable = new ProcedureTable(classRuntimProc);
if (rhs.ProcTable != null)
{
ProcTable = new ProcedureTable(rhs.ProcTable);
}
Bases = new List<int>(rhs.Bases);
ExternLib = rhs.ExternLib;
TypeSystem = rhs.TypeSystem;
CoerceTypes = new Dictionary<int, int>(rhs.CoerceTypes);
}
示例3: BuildInteralAttributes
private void BuildInteralAttributes()
{
Validity.Assert(ClassTable != null);
ClassNode cnode = null;
cnode = new ClassNode { Name = kInternalClassName + kAttributeSuffix };
ClassTable.Append(cnode);
}
示例4: GetUpcastCountTo
/// <summary>
/// Returns the number of upcasts that need to be performed to turn a class into another class in its upcast chain
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="core"></param>
/// <returns></returns>
public static int GetUpcastCountTo(ClassNode from, ClassNode to, RuntimeCore runtimeCore)
{
int toID = runtimeCore.DSExecutable.classTable.ClassNodes.IndexOf(to);
List<int> upcastChain = GetClassUpcastChain(from, runtimeCore);
if (!upcastChain.Contains(toID))
return int.MaxValue;
return upcastChain.IndexOf(toID);
}
示例5: GetUpcastCountTo
/// <summary>
/// Get the number of upcasts that need to be performed to turn a class into another class in its upcast chain
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="core"></param>
/// <returns></returns>
public static int GetUpcastCountTo(ClassNode from, ClassNode to, Core core)
{
int fromID = core.ClassTable.ClassNodes.IndexOf(from);
int toID = core.ClassTable.ClassNodes.IndexOf(to);
List<int> upcastChain = GetClassUpcastChain(from, core);
//Validity.Assert(upcastChain.Contains(toID), "Asked to upcast a class to a class that wasn't in its upcast chain");
if (!upcastChain.Contains(toID))
return int.MaxValue;
return upcastChain.IndexOf(toID);
}
示例6: GetClassUpcastChain
/// <summary>
/// Returns the list of classes that this can be upcast to
/// It includes the class itself
/// </summary>
/// <param name="cn"></param>
/// <param name="core"></param>
/// <returns></returns>
public static List<int> GetClassUpcastChain(ClassNode cn, RuntimeCore runtimeCore)
{
List<int> ret = new List<int>();
//@TODO: Replace this with an ID
ret.Add(runtimeCore.DSExecutable.classTable.ClassNodes.IndexOf(cn));
ClassNode target = cn;
while (target.Base != Constants.kInvalidIndex)
{
ret.Add(target.Base);
target = runtimeCore.DSExecutable.classTable.ClassNodes[target.Base];
}
if (!ret.Contains((int)(PrimitiveType.Var)))
ret.Add((int)PrimitiveType.Var);
return ret;
}
示例7: GetClassUpcastChain
/// <summary>
/// Get the list of classes that this can be upcast to
/// It includes the class itself
/// </summary>
/// <param name="cn"></param>
/// <param name="core"></param>
/// <returns></returns>
public static List<int> GetClassUpcastChain(ClassNode cn, Core core)
{
List<int> ret = new List<int>();
//@TODO: Replace this with an ID
ret.Add(core.ClassTable.ClassNodes.IndexOf(cn));
ClassNode target = cn;
while (target.baseList.Count > 0)
{
Validity.Assert(target.baseList.Count == 1, "Multiple Inheritence not yet supported, {F5DDC58D-F721-4319-854A-622175AC43F8}");
ret.Add(target.baseList[0]);
target = core.ClassTable.ClassNodes[target.baseList[0]];
}
if (!ret.Contains((int)(PrimitiveType.kTypeVar)))
ret.Add((int)PrimitiveType.kTypeVar);
return ret;
}
示例8: SetClassNodeAt
public void SetClassNodeAt(ClassNode node, int index)
{
classNodes[index] = node;
Namespace.Symbol symbol = null;
if (!symbolTable.TryGetExactSymbol(node.Name, out symbol))
symbol = symbolTable.AddSymbol(node.Name);
symbol.Id = index;
}
示例9: Append
public int Append(ClassNode node)
{
Namespace.Symbol symbol = symbolTable.AddSymbol(node.Name);
if (null == symbol)
{
return ProtoCore.DSASM.Constants.kInvalidIndex;
}
classNodes.Add(node);
node.ID = classNodes.Count - 1;
symbol.Id = node.ID;
return node.ID;
}
示例10: SetTypeSystem
public void SetTypeSystem()
{
Debug.Assert(null == classTable);
if (null != classTable)
{
return;
}
classTable = new DSASM.ClassTable();
classTable.Reserve((int)PrimitiveType.kMaxPrimitives);
ProtoCore.DSASM.ClassNode cnode;
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Array, size = 0, rank = 5, symbols = null, vtable = null, typeSystem = this };
/*cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
*/
cnode.classId = (int)PrimitiveType.kTypeArray;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeArray);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Double, size = 0, rank = 4, symbols = null, vtable = null, typeSystem = this };
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceDoubleToIntScore);
cnode.classId = (int)PrimitiveType.kTypeDouble;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeDouble);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Int, size = 0, rank = 3, symbols = null, vtable = null, typeSystem = this };
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceIntToDoubleScore);
cnode.classId = (int)PrimitiveType.kTypeInt;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeInt);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Bool, size = 0, rank = 2, symbols = null, vtable = null, typeSystem = this };
// if convert operator to method call, without the following statement
// a = true + 1 will fail, because _add expects two integers
//cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.classId = (int)PrimitiveType.kTypeBool;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeBool);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Char, size = 0, rank = 1, symbols = null, vtable = null, typeSystem = this };
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.classId = (int)PrimitiveType.kTypeChar;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeChar);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.String, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.classId = (int)PrimitiveType.kTypeString;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeString);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Var, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
/*cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);*/
cnode.classId = (int)PrimitiveType.kTypeVar;
classTable.SetClassNodeAt(cnode,(int)PrimitiveType.kTypeVar);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Null, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
cnode.classId = (int)PrimitiveType.kTypeNull;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeNull);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Void, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
cnode.classId = (int)PrimitiveType.kTypeVoid;
classTable.SetClassNodeAt(cnode,(int)PrimitiveType.kTypeVoid);
//
//
cnode = new ProtoCore.DSASM.ClassNode { name = "hostentityid", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
cnode.classId = (int)PrimitiveType.kTypeHostEntityID;
classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeHostEntityID);
//
//
//.........这里部分代码省略.........
示例11: ClassMirror
/// <summary>
/// Constructor to construct ClassMirror from runtime data i.e. StackValue
/// </summary>
/// <param name="svData">StackValue</param>
/// <param name="core">ProtoCore.Core</param>
internal ClassMirror(StackValue svData, ProtoCore.Core core)
: base(core)
{
Validity.Assert(svData.IsPointer);
Validity.Assert(null != core.DSExecutable.classTable);
IList<ClassNode> classNodes = core.DSExecutable.classTable.ClassNodes;
Validity.Assert(classNodes != null && classNodes.Count > 0);
this.classNode = classNodes[svData.metaData.type];
this.ClassName = this.classNode.Name;
this.Name = this.ClassName;
libraryMirror = new LibraryMirror(classNode.ExternLib, core);
}
示例12: EmitClassDeclNode
private void EmitClassDeclNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.DSASM.AssociativeSubCompilePass subPass = ProtoCore.DSASM.AssociativeSubCompilePass.kNone)
{
ClassDeclNode classDecl = node as ClassDeclNode;
// Handling n-pass on class declaration
if (ProtoCore.DSASM.AssociativeCompilePass.kClassName == compilePass)
{
// Class name pass
// Populating the class tables with the class names
if (null != codeBlock.parent)
{
buildStatus.LogSemanticError("A class cannot be defined inside a language block.\n", compileStateTracker.CurrentDSFileName, classDecl.line, classDecl.col);
}
if (ProtoCore.DSASM.Constants.kInvalidIndex != compileStateTracker.ClassTable.IndexOf(classDecl.className))
{
string message = string.Format("Class redefinition '{0}' (BE1C3285).\n", classDecl.className);
buildStatus.LogSemanticError(message, compileStateTracker.CurrentDSFileName, classDecl.line, classDecl.col);
throw new BuildHaltException(message);
}
ProtoCore.DSASM.ClassNode thisClass = new ProtoCore.DSASM.ClassNode();
thisClass.name = classDecl.className;
thisClass.size = classDecl.varlist.Count;
thisClass.IsImportedClass = classDecl.IsImportedClass;
thisClass.typeSystem = compileStateTracker.TypeSystem;
if (classDecl.ExternLibName != null)
thisClass.ExternLib = classDecl.ExternLibName;
else
thisClass.ExternLib = Path.GetFileName(compileStateTracker.CurrentDSFileName);
globalClassIndex = compileStateTracker.ClassTable.Append(thisClass);
unPopulatedClasses.Add(globalClassIndex, classDecl);
//Always allow us to convert a class to a bool
thisClass.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
}
else if (ProtoCore.DSASM.AssociativeCompilePass.kClassHeirarchy == compilePass)
{
// Class heirarchy pass
// Populating each class entry with their respective base classes
globalClassIndex = compileStateTracker.ClassTable.IndexOf(classDecl.className);
ProtoCore.DSASM.ClassNode thisClass = compileStateTracker.ClassTable.ClassNodes[globalClassIndex];
// Verify and store the list of classes it inherits from
if (null != classDecl.superClass)
{
for (int n = 0; n < classDecl.superClass.Count; ++n)
{
int baseClass = compileStateTracker.ClassTable.IndexOf(classDecl.superClass[n]);
if (baseClass == globalClassIndex)
{
string message = string.Format("Class '{0}' cannot derive from itself (DED0A61F).\n", classDecl.className);
buildStatus.LogSemanticError(message, compileStateTracker.CurrentDSFileName, classDecl.line, classDecl.col);
throw new BuildHaltException(message);
}
if (ProtoCore.DSASM.Constants.kInvalidIndex != baseClass)
{
if (compileStateTracker.ClassTable.ClassNodes[baseClass].IsImportedClass && !thisClass.IsImportedClass)
{
string message = string.Format("Cannot derive from FFI class {0} (DA87AC4D).\n",
compileStateTracker.ClassTable.ClassNodes[baseClass].name);
buildStatus.LogSemanticError(message, compileStateTracker.CurrentDSFileName, classDecl.line, classDecl.col);
throw new BuildHaltException(message);
}
thisClass.baseList.Add(baseClass);
thisClass.coerceTypes.Add(baseClass, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceBaseClass);
// Iterate through all the base classes until the the root class
// For every base class, add the coercion score
// TODO Jun: -Integrate this with multiple inheritace when supported
// -Cleansify
ProtoCore.DSASM.ClassNode tmpCNode = compileStateTracker.ClassTable.ClassNodes[baseClass];
if (tmpCNode.baseList.Count > 0)
{
baseClass = tmpCNode.baseList[0];
while (ProtoCore.DSASM.Constants.kInvalidIndex != baseClass)
{
thisClass.coerceTypes.Add(baseClass, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceBaseClass);
tmpCNode = compileStateTracker.ClassTable.ClassNodes[baseClass];
baseClass = ProtoCore.DSASM.Constants.kInvalidIndex;
if (tmpCNode.baseList.Count > 0)
{
baseClass = tmpCNode.baseList[0];
}
}
}
}
else
{
string message = string.Format("Unknown base class '{0}' (9E44FFB3).\n", classDecl.superClass[n]);
buildStatus.LogSemanticError(message, compileStateTracker.CurrentDSFileName, classDecl.line, classDecl.col);
throw new BuildHaltException(message);
//.........这里部分代码省略.........
示例13: Append
public int Append(ClassNode node)
{
if (IndexOf(node.name) != ProtoCore.DSASM.Constants.kInvalidIndex)
{
return ProtoCore.DSASM.Constants.kInvalidIndex;
}
classNodes.Add(node);
node.classId = classNodes.Count - 1;
classIndexMap[node.name] = node.classId;
return node.classId;
}
示例14: SetClassNodeAt
public void SetClassNodeAt(ClassNode node, int index)
{
classNodes[index] = node;
classIndexMap[node.name] = index;
}
示例15: ProcessClassNode
private void ProcessClassNode(ClassNode classNode)
{
if (null == classNode)
return;
// Define class inheritance relationships.
foreach (int baseClassId in classNode.baseList)
DefineHierarchy(baseClassId, classNode.classId, true);
string[] fields =
{
"ClassScope",
"Name",
"IsImported",
"Rank",
"Size"
};
string[] values =
{
classNode.classId.ToString(),
GetDatabaseType(classNode.name),
GetDatabaseType(classNode.IsImportedClass),
classNode.rank.ToString(),
classNode.size.ToString()
};
try
{
string statement = InsertIntoStatement(TableNames.Classes, fields, values);
SQLiteCommand command = new SQLiteCommand(statement, connection);
command.ExecuteNonQuery();
}
catch (Exception exception)
{
HandleException(exception);
}
// Now process all the class procedures (class methods), excluding
// all those that are auto-generated (or temporary). Excluded
// procedure IDs are placed in 'excludedProcId' list for use later
// when symbol nodes are processed.
//
List<int> excludedProcId = new List<int>();
if (null != classNode.vtable && (null != classNode.vtable.procList))
{
foreach (ProcedureNode procedure in classNode.vtable.procList)
{
// Place generated procedures in a list.
if (ProcedureToBeExcluded(procedure))
{
excludedProcId.Add(procedure.procId);
continue;
}
// Constructors have classScope set to "-1",
// so we must be careful not to exclude them.
if (procedure.isConstructor && (-1 == procedure.classScope))
{
procedure.classScope = classNode.classId;
ProcessProcedureNode(procedure);
procedure.classScope = -1;
continue;
}
// Adding a regular class method.
ProcessProcedureNode(procedure);
}
}
// Go through each of the symbol nodes defined in this class node,
// they can either be class data members or locals defined in class
// methods. Symbol nodes defined locally in those procedures that
// were excluded in the previous pass are also present here,
// therefore it is crucial that they are properly filtered here.
//
if (null != classNode.symbols && (null != classNode.symbols.symbolList))
{
int verifiedProcId = -1000;
bool procedureIncluded = false;
foreach (var symbol in classNode.symbols.symbolList)
{
SymbolNode symbolNode = symbol.Value;
if (symbolNode.classScope != classNode.classId)
continue; // Data member of base class (processed).
// New function index, verify if it needs to be included.
if (symbolNode.functionIndex != verifiedProcId)
{
procedureIncluded = false;
verifiedProcId = symbolNode.functionIndex;
if (excludedProcId.IndexOf(verifiedProcId) == -1)
procedureIncluded = true; // Procedure was included.
}
if (false != procedureIncluded)
ProcessSymbolNode(symbolNode);
}
}
}