private void ProcessClassItem(ClassMirror classMirror, LibraryItem classItem) { classItem.Assembly = classMirror.GetAssembly().LibraryName; foreach (MethodMirror constructorMirror in classMirror.GetConstructors()) { LibraryItem constructorItem = new LibraryItem(NodeType.Function, constructorMirror.MethodName, constructorMirror); constructorItem.ArgumentTypes = GetArgumentTypes(constructorMirror.GetArgumentTypes()); constructorItem.Assembly = classMirror.GetAssembly().LibraryName; constructorItem.Type = LibraryItem.MemberType.Constructor; classItem.AddChildItem(constructorItem); } foreach (MethodMirror methodMirror in classMirror.GetFunctions()) { if (!methodMirror.IsStatic) continue; LibraryItem staticMethodItem = new LibraryItem(NodeType.Function, methodMirror.MethodName, methodMirror); staticMethodItem.ArgumentTypes = GetArgumentTypes(methodMirror.GetArgumentTypes()); staticMethodItem.Assembly = classMirror.GetAssembly().LibraryName; staticMethodItem.Type = LibraryItem.MemberType.StaticMethod; classItem.AddChildItem(staticMethodItem); } GroupOverloadedItem(classItem); foreach (PropertyMirror propertyMirror in classMirror.GetProperties()) { if (!propertyMirror.IsStatic) continue; LibraryItem staticPropertyItem = new LibraryItem(NodeType.Function, propertyMirror.PropertyName, propertyMirror); staticPropertyItem.ArgumentTypes = string.Empty;//GetArgumentTypes(propertyMirror. staticPropertyItem.Type = LibraryItem.MemberType.StaticProperty; if (propertyMirror.IsSetter) staticPropertyItem.DisplayText += UiStrings.OverloadDisplayTextSetter; else staticPropertyItem.DisplayText += UiStrings.OverloadDisplayTextGetter; classItem.AddChildItem(staticPropertyItem); } }
private void ProcessImportAssembly(string assembly, LibraryItem rootItem) { LibraryItem assemblyItem = new LibraryItem(NodeType.None, Path.GetFileName(assembly), null); LibraryMirror assemblyMirror = GraphToDSCompiler.GraphUtilities.GetLibraryMirror(assembly); // Global Functions in DS file if (Path.GetExtension(assembly) == ".ds") { List<MethodMirror> globalFunctions = assemblyMirror.GetGlobalMethods(); foreach (MethodMirror globalFunctionMirror in globalFunctions) { LibraryItem globalFunctionItem = new LibraryItem(NodeType.Function, globalFunctionMirror.MethodName, globalFunctionMirror); globalFunctionItem.ArgumentTypes = GetArgumentTypes(globalFunctionMirror.GetArgumentTypes()); globalFunctionItem.Assembly = assemblyMirror.LibraryName; globalFunctionItem.Type = LibraryItem.MemberType.GlobalFunction; assemblyItem.AddChildItem(globalFunctionItem); } GroupOverloadedItem(assemblyItem); } foreach (ClassMirror classMirror in assemblyMirror.GetClasses()) { LibraryItem classItem = new LibraryItem(NodeType.None, classMirror.ClassName, null); ProcessClassItem(classMirror, classItem); if (classItem != null && classItem.Children != null && classItem.Children.Count > 0) assemblyItem.AddChildItem(classItem); } }
private void LoadExternalLibraries(LibraryItem rootItem, LibraryItem rootItemMethodProperty) { if (coreComponent.studioSettings.LoadedAssemblies != null && coreComponent.studioSettings.LoadedAssemblies.Count > 0) { foreach (string externalLibrary in coreComponent.studioSettings.LoadedAssemblies) { LibraryItem assemblyItem, assemblyItemMethodProperty; ProcessImportAssembly(externalLibrary, out assemblyItem, out assemblyItemMethodProperty); if (assemblyItem != null && assemblyItem.Children != null && assemblyItem.Children.Count > 0) { assemblyItem.IsExternal = true; rootItem.AddChildItem(assemblyItem); } if (assemblyItemMethodProperty != null && assemblyItemMethodProperty.Children != null && assemblyItemMethodProperty.Children.Count > 0) { assemblyItemMethodProperty.IsExternal = true; rootItemMethodProperty.AddChildItem(assemblyItemMethodProperty); } } } }
private void GroupOverloadedItem(LibraryItem parentItem) { int i = 0; while (i < parentItem.Children.Count) { // find items that should be grouped together (from i to j) int j = i + 1; while (j < parentItem.Children.Count && parentItem.Children[i].DisplayText == parentItem.Children[j].DisplayText) j++; j--; // grouping if (i < j && parentItem.Children[i].DisplayText == parentItem.Children[j].DisplayText) { // create group folder LibraryItem groupItem = new LibraryItem(NodeType.None, parentItem.Children[i].QualifiedName, null); groupItem.Assembly = parentItem.Children[i].Assembly; groupItem.Type = parentItem.Children[i].Type; // group i to j to the folder for (int k = i; k <= j; k++) { parentItem.Children[i].IsOverloaded = true; if (parentItem.Children[i].ArgumentNames == "") parentItem.Children[i].DisplayText = UiStrings.OverloadDisplayTextNoParameter; else { List<string> argumentNames = ((MethodMirror)parentItem.Children[i].DataMirror).GetArgumentNames(); parentItem.Children[i].DisplayText = GetArgumentNames(argumentNames); } groupItem.AddChildItem(parentItem.Children[i]); parentItem.Children.RemoveAt(i); } parentItem.AddChildItem(groupItem); } i++; } }
private void ProcessImportClassTable(ProtoCore.DSASM.ClassTable classTable, LibraryItem parentItem, LibraryItem parentItemMethodProperty) { if (classTable == null && classTable.ClassNodes.Count <= (int)ProtoCore.PrimitiveType.kMaxPrimitives) return; for (int i = (int)ProtoCore.PrimitiveType.kMaxPrimitives; i < classTable.ClassNodes.Count; i++) { if (this.filteredClasses != string.Empty) { string className = classTable.ClassNodes[i].ExternLib + ';' + classTable.ClassNodes[i].name + ';'; if (filteredClasses.Contains(className.ToLower())) continue; } LibraryItem classItem = new LibraryItem(NodeType.None, classTable.ClassNodes[i].name); LibraryItem classItemMethodProperty = new LibraryItem(NodeType.None, classTable.ClassNodes[i].name); ProcessClassNode(classTable.ClassNodes[i], classTable, classItem, classItemMethodProperty); // add the libraryItem to respect assembly libraryItem, // if there is no such assembly, create one LibraryItem assemblyItem = null; LibraryItem assemblyItemMethodProperty = null; // Only include the class if it has at least one method listed. if (null != classItem.Children && (classItem.Children.Count > 0)) { if (!string.IsNullOrEmpty(classTable.ClassNodes[i].ExternLib) && parentItem.Children != null && parentItem.Children.Count > 0) { foreach (LibraryItem item in parentItem.Children) { if (item.Assembly == classTable.ClassNodes[i].ExternLib) { assemblyItem = item; break; } } } if (assemblyItem == null) { if (string.IsNullOrEmpty(classTable.ClassNodes[i].ExternLib)) // Custom Class { } assemblyItem = new LibraryItem(NodeType.None, Path.GetFileName(classTable.ClassNodes[i].ExternLib)); assemblyItem.Assembly = classTable.ClassNodes[i].ExternLib; assemblyItem.IsExternal = false; parentItem.AddChildItem(assemblyItem); } assemblyItem.AddChildItem(classItem); } if (null != classItemMethodProperty.Children && (classItemMethodProperty.Children.Count > 0)) { if (!string.IsNullOrEmpty(classTable.ClassNodes[i].ExternLib) && parentItemMethodProperty.Children != null && parentItemMethodProperty.Children.Count > 0) { foreach (LibraryItem itemMethodProperty in parentItemMethodProperty.Children) { if (itemMethodProperty.Assembly == classTable.ClassNodes[i].ExternLib) { assemblyItemMethodProperty = itemMethodProperty; break; } } } if (assemblyItemMethodProperty == null) { if (string.IsNullOrEmpty(classTable.ClassNodes[i].ExternLib)) // Custom Class { } assemblyItemMethodProperty = new LibraryItem(NodeType.None, Path.GetFileName(classTable.ClassNodes[i].ExternLib)); assemblyItemMethodProperty.Assembly = classTable.ClassNodes[i].ExternLib; assemblyItemMethodProperty.IsExternal = false; parentItemMethodProperty.AddChildItem(assemblyItemMethodProperty); } assemblyItemMethodProperty.AddChildItem(classItemMethodProperty); } } }
private void LoadBuiltInItems(LibraryItem rootItem) { XmlSerializer serializer = new XmlSerializer(typeof(LibraryItem)); TextReader stringReader = new StringReader(Properties.Resources.BuiltInLibrary); LibraryItem libraryItem = serializer.Deserialize(stringReader) as LibraryItem; stringReader.Close(); foreach (LibraryItem item in libraryItem.Children) rootItem.AddChildItem(item); }
private void ProcessImportBuiltInFunctions(List<ProtoCore.DSASM.ProcedureNode> functionList, LibraryItem rootItem) { LibraryItem assemblyItem = new LibraryItem(NodeType.None, "Built-in Functions"); foreach (ProtoCore.DSASM.ProcedureNode procedureNode in functionList) { if (this.filteredClasses != string.Empty) { string procedureName = "Built-in Functions;" + procedureNode.name + ';'; if (filteredClasses.Contains(procedureName.ToLower())) continue; } LibraryItem item = ProcessProcedureNode(procedureNode, GraphToDSCompiler.GraphUtilities.ClassTable); if (item != null) { item.Type = LibraryItem.MemberType.GlobalFunction; item.Assembly = assemblyItem.DisplayText; item.QualifiedName = item.DisplayText; assemblyItem.AddChildItem(item); } } if (assemblyItem.Children != null || assemblyItem.Children.Count > 0) rootItem.AddChildItem(assemblyItem); }
private int ProcessImportAssembly(string assemblyFilePath, out LibraryItem assemblyItem, out LibraryItem assemblyItemMethodProperty) { int importedNodes = -1; assemblyItem = null; assemblyItemMethodProperty = null; DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); IList<ProtoCore.DSASM.ClassNode> classNodes = GraphToDSCompiler.GraphUtilities.GetClassesForAssembly(assemblyFilePath); importedNodes = classNodes.Count(); ProtoCore.BuildStatus buildStatus = GraphToDSCompiler.GraphUtilities.BuildStatus; if (buildStatus.ErrorCount > 0) return -1; assemblyItem = new LibraryItem(NodeType.None, Path.GetFileName(assemblyFilePath)); assemblyItemMethodProperty = new LibraryItem(NodeType.None, Path.GetFileName(assemblyFilePath)); foreach (ProtoCore.DSASM.ClassNode classNode in classNodes) { LibraryItem classItem = new LibraryItem(NodeType.None, classNode.name); LibraryItem classItemMethodProperty = new LibraryItem(NodeType.None, classNode.name); ProcessClassNode(classNode, GraphToDSCompiler.GraphUtilities.ClassTable, classItem, classItemMethodProperty); if (classItem != null && classItem.Children != null && classItem.Children.Count > 0) assemblyItem.AddChildItem(classItem); if (classItemMethodProperty != null && classItemMethodProperty.Children != null && classItemMethodProperty.Children.Count > 0) assemblyItemMethodProperty.AddChildItem(classItemMethodProperty); } // Global Functions in DS file if (Path.GetExtension(assemblyFilePath) == ".ds") { List<ProtoCore.DSASM.ProcedureNode> procNodes = GraphToDSCompiler.GraphUtilities.GetGlobalMethods(assemblyFilePath); importedNodes += procNodes.Count(); foreach (ProtoCore.DSASM.ProcedureNode procedureNode in procNodes) { LibraryItem item = ProcessProcedureNode(procedureNode, GraphToDSCompiler.GraphUtilities.ClassTable); if (item != null) { item.Type = LibraryItem.MemberType.GlobalFunction; item.Assembly = Path.GetFileName(assemblyFilePath); item.QualifiedName = item.DisplayText; assemblyItem.AddChildItem(item); } } } return importedNodes; }
private void ProcessClassNode(ProtoCore.DSASM.ClassNode classNode, ProtoCore.DSASM.ClassTable classTable, LibraryItem classItem, LibraryItem classItemMethodProperty) { //TODO: Victor // Temperarily fix for multiple setter LibraryItem setterItem = null; string friendlyName = GetFriendlyName(classNode.ExternLib); if (UiStrings.ProtoGeometryFriendlyName == friendlyName) { // Fix: IDE-1604 Usage of text crashes the IDE. The OpenGL renderer // does not have a way of accepting text inputs, therefore we don't // have a way to render text on the preview, filter it out for now. if (classNode.name == "Text") return; } classItem.Assembly = classNode.ExternLib; classItemMethodProperty.Assembly = classNode.ExternLib; foreach (ProtoCore.DSASM.ProcedureNode procedureNode in classNode.vtable.procList) { if (procedureNode.isAutoGeneratedThisProc) // Temporary functions to be excluded. continue; LibraryItem item = ProcessProcedureNode(procedureNode, classTable); if (item != null) { //TODO: Victor // Temperarily fix for multiple setter if (procedureNode.name.StartsWith(ProtoCore.DSASM.Constants.kSetterPrefix)) { if (setterItem != null && item.DisplayText == setterItem.DisplayText) continue; else setterItem = item; } if (classNode.ExternLib != null) item.Assembly = classNode.ExternLib; else item.Assembly = string.Empty; item.QualifiedName = string.Format("{0}.{1}", classNode.name, item.DisplayText); if (item.Type == LibraryItem.MemberType.InstanceMethod || // add the "this" input to instance method and property(setter only) (item.Type == LibraryItem.MemberType.InstanceProperty && procedureNode.name.StartsWith(ProtoCore.DSASM.Constants.kSetterPrefix))) { if (string.IsNullOrEmpty(item.ArgumentNames)) { item.ArgumentNames = "this"; item.ArgumentTypes = "this"; } else { item.ArgumentNames = "this," + item.ArgumentNames; item.ArgumentTypes = "this," + item.ArgumentTypes; } } if (procedureNode.isStatic || procedureNode.isConstructor) classItem.AddChildItem(item); else classItemMethodProperty.AddChildItem(item); } } }
private void GroupOverloadProcedure(LibraryItem parentItem) { int i = 0; while (i < parentItem.Children.Count) { // it's a folder, no grouping needed, process to group its children if (parentItem.Children[i].ItemType == NodeType.None) { if (parentItem.Children[i].Children.Count > 1) GroupOverloadProcedure(parentItem.Children[i]); } else { // find items that should be grouped together (from i to j) int j = i + 1; while (j < parentItem.Children.Count && parentItem.Children[i].DisplayText == parentItem.Children[j].DisplayText) j++; j--; // grouping if (i < j && parentItem.Children[i].DisplayText == parentItem.Children[j].DisplayText) { // create group folder LibraryItem groupItem = new LibraryItem(NodeType.None, parentItem.Children[i].QualifiedName); groupItem.Assembly = parentItem.Children[i].Assembly; groupItem.Type = parentItem.Children[i].Type; // group i to j to the folder for (int k = i; k <= j; k++) { parentItem.Children[i].IsOverloaded = true; // Update the display text if (parentItem.Children[i].Type == LibraryItem.MemberType.StaticProperty || parentItem.Children[i].Type == LibraryItem.MemberType.InstanceProperty) { if (parentItem.Children[i].ArgumentNames == "" || parentItem.Children[i].ItemType == NodeType.Property) parentItem.Children[i].DisplayText += UiStrings.OverloadDisplayTextGetter; else parentItem.Children[i].DisplayText += UiStrings.OverloadDisplayTextSetter; } else { if (parentItem.Children[i].ArgumentNames == "") parentItem.Children[i].DisplayText = UiStrings.OverloadDisplayTextNoParameter; else parentItem.Children[i].DisplayText = parentItem.Children[i].ArgumentNames; } groupItem.AddChildItem(parentItem.Children[i]); parentItem.Children.RemoveAt(i); } parentItem.AddChildItem(groupItem); } } i++; } }
private void ProcessImportBuiltInFunctions(List<MethodMirror> builtinFunctions, LibraryItem rootItem) { LibraryItem assemblyItem = new LibraryItem(NodeType.None, "Built-in Functions", null); foreach (MethodMirror builtinFunction in builtinFunctions) { if (this.filteredClasses != string.Empty) { string procedureName = "Built-in Functions;" + builtinFunction.MethodName + ';'; if (filteredClasses.Contains(procedureName.ToLower())) continue; } LibraryItem builtinFunctionItem = new LibraryItem(NodeType.Function, builtinFunction.MethodName, builtinFunction); builtinFunctionItem.ArgumentTypes = GetArgumentTypes(builtinFunction.GetArgumentTypes()); builtinFunctionItem.Assembly = assemblyItem.DisplayText; builtinFunctionItem.Type = LibraryItem.MemberType.GlobalFunction; assemblyItem.AddChildItem(builtinFunctionItem); } GroupOverloadedItem(assemblyItem); if (assemblyItem.Children != null || assemblyItem.Children.Count > 0) rootItem.AddChildItem(assemblyItem); }