/// <summary> /// Returns the list of functions of the class only /// </summary> /// <returns> function nodes </returns> public IEnumerable <MethodMirror> GetFunctions() { List <MethodMirror> methods = new List <MethodMirror>(); ProcedureTable procedureTable = ClassNode.vtable; List <ProcedureNode> procList = procedureTable.procList; foreach (ProcedureNode pNode in procList) { bool hidden = pNode.MethodAttribute == null ? false : pNode.MethodAttribute.HiddenInLibrary; if (!pNode.isAssocOperator && !pNode.isAutoGenerated && !pNode.isAutoGeneratedThisProc && !pNode.isConstructor && !hidden && !CoreUtils.IsGetter(pNode.name) && !CoreUtils.IsSetter(pNode.name) && !CoreUtils.StartsWithDoubleUnderscores(pNode.name) && !CoreUtils.IsGetTypeMethod(pNode.name)) { methods.Add(new MethodMirror(pNode)); } } return(methods); }
public MethodMirror GetDeclaredMethod(string methodName, List <ProtoCore.Type> argumentTypes) { ProcedureTable procedureTable = ClassNode.vtable; List <ProcedureNode> procList = procedureTable.procList; return(StaticMirror.FindMethod(methodName, argumentTypes, procList)); }
public List <MethodMirror> GetOverloads(string methodName) { List <MethodMirror> methods = new List <MethodMirror>(); string name = string.Empty; if (classNode == null) { Validity.Assert(staticCore != null); ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable; int ci = classTable.IndexOf(ClassName); if (ci != ProtoCore.DSASM.Constants.kInvalidIndex) { classNode = classTable.ClassNodes[ci]; } } ProcedureTable procedureTable = classNode.vtable; List <ProcedureNode> procList = procedureTable.procList; foreach (ProcedureNode pNode in procList) { name = pNode.name; if (name == methodName) { methods.Add(new MethodMirror(pNode)); } } return(methods); }
/// <summary> /// Returns the list of constructors defined for the given class /// </summary> /// <returns></returns> public List <MethodMirror> GetConstructors() { List <MethodMirror> constructors = new List <MethodMirror>(); if (classNode == null) { Validity.Assert(staticCore != null); ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable; int ci = classTable.IndexOf(ClassName); if (ci != ProtoCore.DSASM.Constants.kInvalidIndex) { classNode = classTable.ClassNodes[ci]; } } ProcedureTable procedureTable = classNode.vtable; List <ProcedureNode> procList = procedureTable.procList; foreach (ProcedureNode pNode in procList) { if (pNode.isConstructor == true) { constructors.Add(new MethodMirror(pNode)); } } return(constructors); }
/// <summary> /// Returns the list of function properties of the class only /// </summary> /// <returns> function nodes </returns> public List <MethodMirror> GetFunctions() { List <MethodMirror> methods = new List <MethodMirror>(); string name = string.Empty; if (classNode == null) { Validity.Assert(staticCore != null); ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable; int ci = classTable.IndexOf(ClassName); if (ci != ProtoCore.DSASM.Constants.kInvalidIndex) { classNode = classTable.ClassNodes[ci]; } } ProcedureTable procedureTable = classNode.vtable; List <ProcedureNode> procList = procedureTable.procList; foreach (ProcedureNode pNode in procList) { name = pNode.name; if (!pNode.isAssocOperator && !pNode.isAutoGenerated && !pNode.isAutoGeneratedThisProc && !pNode.isConstructor) { methods.Add(new MethodMirror(pNode)); } } return(methods); }
/// <summary> /// Returns the list of class properties of this class /// </summary> /// <returns> symbol nodes</returns> public IEnumerable <PropertyMirror> GetProperties() { List <PropertyMirror> properties = new List <PropertyMirror>(); string name = string.Empty; ProcedureTable procedureTable = ClassNode.ProcTable; List <ProcedureNode> procList = procedureTable.Procedures; string getterPrefix = Constants.kGetterPrefix; int prefixLength = getterPrefix.Length; foreach (ProcedureNode pNode in procList) { name = pNode.Name; bool hidden = pNode.MethodAttribute == null ? false : pNode.MethodAttribute.HiddenInLibrary; if (!hidden && name.Contains(getterPrefix)) { // Auto-generated static property that takes the instance as the only input parameter. var isAutoGeneratedThisProperty = pNode.IsAutoGeneratedThisProc && pNode.ArgumentInfos.Count == 1 && pNode.ArgumentTypes[0].UID == pNode.ClassID; if (pNode.ArgumentInfos.Count == 0 || isAutoGeneratedThisProperty) { properties.Add(new PropertyMirror(pNode)); } } } return(properties); }
/// <summary> /// Returns the list of class properties of this class /// </summary> /// <returns> symbol nodes</returns> public List <PropertyMirror> GetProperties() { List <PropertyMirror> properties = new List <PropertyMirror>(); Dictionary <string, ProcedureNode> setterMap = new Dictionary <string, ProcedureNode>(); string name = string.Empty; if (classNode == null) { Validity.Assert(staticCore != null); ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable; int ci = classTable.IndexOf(ClassName); if (ci != ProtoCore.DSASM.Constants.kInvalidIndex) { classNode = classTable.ClassNodes[ci]; } } ProcedureTable procedureTable = classNode.vtable; List <ProcedureNode> procList = procedureTable.procList; string getterPrefix = ProtoCore.DSASM.Constants.kGetterPrefix; string setterPrefix = ProtoCore.DSASM.Constants.kSetterPrefix; foreach (ProcedureNode pNode in procList) { name = pNode.name; if (name.Contains(getterPrefix) && pNode.argInfoList.Count == 0) { properties.Add(new PropertyMirror(pNode)); } else if (name.Contains(setterPrefix) && pNode.argInfoList.Count == 1 && !pNode.isAutoGeneratedThisProc) { if (setterMap.ContainsKey(name)) { ProcedureNode proc = setterMap[name]; if (proc.argTypeList[0].UID == (int)ProtoCore.PrimitiveType.kTypeVar && pNode.argTypeList[0].UID != (int)ProtoCore.PrimitiveType.kTypeVar) { setterMap.Remove(name); setterMap.Add(name, pNode); } } else { setterMap.Add(name, pNode); } } } foreach (var kvp in setterMap) { properties.Add(new PropertyMirror(kvp.Value, true)); } return(properties); }
public MethodMirror GetDeclaredMethod(string className, string methodName, List <ProtoCore.Type> argumentTypes) { // Check global methods if classname is empty or null if (string.IsNullOrEmpty(className)) { List <MethodMirror> methods = null; methods = GetGlobalMethods(); foreach (var method in methods) { if (method.MethodName == methodName) { List <ProtoCore.Type> argTypes = method.GetArgumentTypes(); if (argTypes.Count == argumentTypes.Count) { bool isEqual = true; for (int i = 0; i < argumentTypes.Count; ++i) { if (!argumentTypes[i].Equals(argTypes[i])) { isEqual = false; break; } } if (isEqual) { return(method); } } } } } else // find method in Class { Validity.Assert(staticCore != null); ClassNode classNode = null; ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable; int ci = classTable.IndexOf(className); if (ci != ProtoCore.DSASM.Constants.kInvalidIndex) { classNode = classTable.ClassNodes[ci]; } ProcedureTable procedureTable = classNode.vtable; List <ProcedureNode> procList = procedureTable.procList; return(StaticMirror.FindMethod(methodName, argumentTypes, procList)); } return(null); }
/// <summary> /// Returns the list of class properties of this class /// </summary> /// <returns> symbol nodes</returns> public IEnumerable <PropertyMirror> GetProperties() { List <PropertyMirror> properties = new List <PropertyMirror>(); Dictionary <string, ProcedureNode> setterMap = new Dictionary <string, ProcedureNode>(); string name = string.Empty; ProcedureTable procedureTable = ClassNode.vtable; List <ProcedureNode> procList = procedureTable.procList; string getterPrefix = ProtoCore.DSASM.Constants.kGetterPrefix; string setterPrefix = ProtoCore.DSASM.Constants.kSetterPrefix; int prefixLength = getterPrefix.Length; foreach (ProcedureNode pNode in procList) { name = pNode.name; bool hidden = pNode.MethodAttribute == null ? false : pNode.MethodAttribute.HiddenInLibrary; if (!hidden && name.Contains(getterPrefix) && pNode.argInfoList.Count == 0) { properties.Add(new PropertyMirror(pNode)); } // TODO: Remove reflection on property setters: Property setters are filtered out by Dynamo and should not be imported else if (name.Contains(setterPrefix) && pNode.argInfoList.Count == 1 && !pNode.isAutoGeneratedThisProc) { if (setterMap.ContainsKey(name)) { ProcedureNode proc = setterMap[name]; if (proc.argTypeList[0].UID == (int)ProtoCore.PrimitiveType.kTypeVar && pNode.argTypeList[0].UID != (int)ProtoCore.PrimitiveType.kTypeVar) { setterMap.Remove(name); setterMap.Add(name, pNode); } } else { setterMap.Add(name, pNode); } } } foreach (var kvp in setterMap) { properties.Add(new PropertyMirror(kvp.Value, true)); } return(properties); }
public MethodMirror GetDeclaredMethod(string methodName, List <ProtoCore.Type> argumentTypes) { if (classNode == null) { Validity.Assert(staticCore != null); ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable; int ci = classTable.IndexOf(ClassName); if (ci != ProtoCore.DSASM.Constants.kInvalidIndex) { classNode = classTable.ClassNodes[ci]; } } ProcedureTable procedureTable = classNode.vtable; List <ProcedureNode> procList = procedureTable.procList; return(StaticMirror.FindMethod(methodName, argumentTypes, procList)); }
/// <summary> /// Returns the list of class properties of this class /// </summary> /// <returns> symbol nodes</returns> public IEnumerable <PropertyMirror> GetProperties() { List <PropertyMirror> properties = new List <PropertyMirror>(); string name = string.Empty; ProcedureTable procedureTable = ClassNode.vtable; List <ProcedureNode> procList = procedureTable.procList; string getterPrefix = ProtoCore.DSASM.Constants.kGetterPrefix; int prefixLength = getterPrefix.Length; foreach (ProcedureNode pNode in procList) { name = pNode.name; bool hidden = pNode.MethodAttribute == null ? false : pNode.MethodAttribute.HiddenInLibrary; if (!hidden && name.Contains(getterPrefix) && pNode.argInfoList.Count == 0) { properties.Add(new PropertyMirror(pNode)); } } return(properties); }
private void ResetAll(Options options) { Heap = new Heap(); //Rmem = new RuntimeMemory(Heap); Configurations = new Dictionary <string, object>(); DllTypesToLoad = new List <System.Type>(); Options = options; Compilers = new Dictionary <Language, Compiler>(); ClassIndex = Constants.kInvalidIndex; FunctionTable = new FunctionTable(); watchFunctionScope = Constants.kInvalidIndex; watchSymbolList = new List <SymbolNode>(); watchBaseOffset = 0; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List <CodeBlock>(); CompleteCodeBlockList = new List <CodeBlock>(); CallsiteGuidMap = new Dictionary <Guid, int>(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new ProcedureTable(Constants.kGlobalScope); // Initialize internal attributes internalAttributes = new InternalAttributes(ClassTable); //Initialize the function pointer table FunctionPointerTable = new FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DynamicVariableTable(); DynamicFunctionTable = new DynamicFunctionTable(); watchStartPC = Constants.kInvalidIndex; deltaCompileStartPC = Constants.kInvalidIndex; BuildStatus = new BuildStatus(this, null, Options.BuildOptErrorAsWarning); SSAExpressionUID = 0; SSASubscript = 0; SSASubscript_GUID = Guid.NewGuid(); SSAExprUID = 0; ExpressionUID = 0; ExprInterpreterExe = null; Options.RunMode = InterpreterMode.Normal; assocCodegen = null; // Default execution log is Console.Out. ExecutionLog = Console.Out; DebuggerProperties = new DebugProperties(); ParsingMode = ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; ForLoopBlockIndex = Constants.kInvalidIndex; GraphNodeCallList = new List <GraphNode>(); InlineConditionalBodyGraphNodes = new Stack <List <GraphNode> >(); newEntryPoint = Constants.kInvalidIndex; }
private void ResetAll(Options options) { Heap = new Heap(); //Rmem = new RuntimeMemory(Heap); Configurations = new Dictionary <string, object>(); ResetRuntimeCore(); Validity.AssertExpiry(); Options = options; Compilers = new Dictionary <Language, Compiler>(); ClassIndex = Constants.kInvalidIndex; FunctionTable = new FunctionTable(); Langverify = new LangVerify(); watchFunctionScope = Constants.kInvalidIndex; watchSymbolList = new List <SymbolNode>(); watchBaseOffset = 0; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List <CodeBlock>(); CompleteCodeBlockList = new List <CodeBlock>(); DSExecutable = new Executable(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new ProcedureTable(Constants.kGlobalScope); //Initialize the function pointer table FunctionPointerTable = new FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DynamicVariableTable(); DynamicFunctionTable = new DynamicFunctionTable(); startPC = Constants.kInvalidIndex; deltaCompileStartPC = Constants.kInvalidIndex; if (options.SuppressBuildOutput) { // don't log any of the build related messages // just accumulate them in relevant containers with // BuildStatus object // BuildStatus = new BuildStatus(this, false, false, false); } else { BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning); } SSASubscript = 0; SSASubscript_GUID = Guid.NewGuid(); ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; Options.RunMode = InterpreterMode.kNormal; assocCodegen = null; // Default execution log is Console.Out. ExecutionLog = Console.Out; DebuggerProperties = new DebugProperties(); ParsingMode = ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; ForLoopBlockIndex = Constants.kInvalidIndex; GraphNodeCallList = new List <GraphNode>(); newEntryPoint = Constants.kInvalidIndex; }
/// <summary> /// Import a library (if it hasn't been imported yet). /// </summary> /// <param name="library">The library to be loaded</param> /// <param name="isExplicitlyImportedLib">Indicates if the library has been imported using the "File | ImportLibrary" command</param> internal bool LoadNodeLibrary(string library, bool isExplicitlyImportedLib) { if (null == library) { throw new ArgumentNullException(); } if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) && !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase)) { string errorMessage = Properties.Resources.InvalidLibraryFormat; OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage)); return(false); } if (importedFunctionGroups.ContainsKey(library)) { string errorMessage = string.Format(Properties.Resources.LibraryHasBeenLoaded, library); OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage)); return(false); } // Copy the library path so that the path can be reported in the case of a failure // to resolve the library path. If there is a failure "library" is set to null. string path = library; if (!pathManager.ResolveLibraryPath(ref library)) { string errorMessage = string.Format(Properties.Resources.LibraryPathCannotBeFound, path); // In the case that a library was explicitly imported using the "File|Import Library" command // set the load failed args to not throw an exception if the load fails. This can happen after using // File|Import Library and then moving or deleting the library. OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(path, errorMessage, throwOnFailure: !isExplicitlyImportedLib)); return(false); } OnLibraryLoading(new LibraryLoadingEventArgs(library)); try { DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); ProcedureTable functionTable = null; int functionNumber = 0; if (LibraryManagementCore.CodeBlockList.Any()) { functionTable = LibraryManagementCore.CodeBlockList[0].procedureTable; functionNumber = functionTable.Procedures.Count; } var classTable = LibraryManagementCore.ClassTable; int classNumber = classTable.ClassNodes.Count; CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library); if (functionTable == null) { functionTable = LibraryManagementCore.CodeBlockList[0].procedureTable; functionNumber = functionTable.Procedures.Count; } if (LibraryManagementCore.BuildStatus.ErrorCount > 0) { string errorMessage = string.Format(Properties.Resources.LibraryBuildError, library); Log(errorMessage, WarningLevel.Moderate); foreach (ErrorEntry error in LibraryManagementCore.BuildStatus.Errors) { Log(error.Message, WarningLevel.Moderate); errorMessage += Environment.NewLine + error.Message; } throw new Exception(errorMessage); } LoadLibraryMigrations(library); var loadedClasses = classTable.ClassNodes.Skip(classNumber); foreach (var classNode in loadedClasses) { ImportClass(library, classNode); } var loadedFunctions = functionTable.Procedures.Skip(functionNumber); foreach (var globalFunction in loadedFunctions) { ImportProcedure(library, globalFunction); } } catch (Exception e) { OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message, throwOnFailure: !isExplicitlyImportedLib)); return(false); } if (!importedLibraries.Contains(library)) { importedLibraries.Add(library); } return(true); }
public void SetUp() { testCore = thisTest.SetupTestCore(); testRuntimeCore = new RuntimeCore(testCore.Heap, testCore.Options); testExecutive = new TestExecutive(testRuntimeCore); procedureTable = new ProcedureTable(-1); var procNodes = new List <ProcedureNode>() { new ProcedureNode() { ID = 0, ClassID = 20, Name = "Test0", ArgumentTypes = new List <ProtoCore.Type>() { new ProtoCore.Type() { Name = "int", UID = 10 }, new ProtoCore.Type() { Name = "int", UID = 11 }, new ProtoCore.Type() { Name = "double", UID = 12 } }, ArgumentInfos = new List <ArgumentInfo>() { new ArgumentInfo() { Name = "example0" }, new ArgumentInfo() { Name = "example1" }, new ArgumentInfo() { Name = "example1", DefaultExpression = new IdentifierNode() { } } }, IsConstructor = false, IsStatic = false, IsAutoGeneratedThisProc = false }, new ProcedureNode() { ID = 1, ClassID = 20, Name = "Test0", ArgumentTypes = new List <ProtoCore.Type>() { new ProtoCore.Type() { Name = "int", UID = 10 }, new ProtoCore.Type() { Name = "int", UID = 11 }, new ProtoCore.Type() { Name = "int", UID = 13 }, new ProtoCore.Type() { Name = "int", UID = 13 } }, ArgumentInfos = new List <ArgumentInfo>() { new ArgumentInfo() { Name = "example0" }, new ArgumentInfo() { Name = "example1", DefaultExpression = new IdentifierNode() { } }, new ArgumentInfo() { Name = "example2", DefaultExpression = new IdentifierNode() { } }, new ArgumentInfo() { Name = "example2", DefaultExpression = new IdentifierNode() { } } }, IsConstructor = false, IsStatic = false, IsAutoGeneratedThisProc = false }, new ProcedureNode() { ID = 2, ClassID = 20, Name = "Test1", ArgumentTypes = new List <ProtoCore.Type>() { }, ArgumentInfos = new List <ArgumentInfo>() { }, IsConstructor = false, IsStatic = false, IsAutoGeneratedThisProc = false }, new ProcedureNode() { ID = 3, ClassID = 20, Name = "Test2", ArgumentTypes = new List <ProtoCore.Type>() { new ProtoCore.Type() { Name = "int", UID = 10 } }, ArgumentInfos = new List <ArgumentInfo>() { new ArgumentInfo() { Name = "example0" } }, IsConstructor = false, IsStatic = false, IsAutoGeneratedThisProc = true }, new ProcedureNode() { ID = 4, ClassID = 20, Name = "Test2", ArgumentTypes = new List <ProtoCore.Type>() { }, ArgumentInfos = new List <ArgumentInfo>() { }, IsConstructor = false, IsStatic = false, IsAutoGeneratedThisProc = false }, new ProcedureNode() { ID = 5, ClassID = 20, Name = "Test4", ArgumentTypes = new List <ProtoCore.Type>() { }, ArgumentInfos = new List <ArgumentInfo>() { }, IsConstructor = false, IsStatic = true, IsAutoGeneratedThisProc = true } }; foreach (var proc in procNodes) { procedureTable.Append(proc); } Assert.AreEqual(procedureTable.Procedures.Count, procNodes.Count); }