public void MergeGlbFiles() { var testPath = "../../../models/MergeGlTF/Ours.glb"; var ours = Interface.LoadModel(testPath); var buffers = ours.Buffers.ToList(); var buffViews = ours.BufferViews.ToList(); var accessors = ours.Accessors.ToList(); var meshes = ours.Meshes.ToList(); var materials = ours.Materials.ToList(); var images = ours.Images != null?ours.Images.ToList() : new List <Image>(); var textures = ours.Textures != null?ours.Textures.ToList() : new List <Texture>(); var samplers = ours.Samplers != null?ours.Samplers.ToList() : new List <Sampler>(); using (var testStream = GltfExtensions.GetGlbStreamFromPath(testPath)) { var bufferByteArrays = ours.GetAllBufferByteArrays(testStream); using (var avocadoStream = GltfExtensions.GetGlbStreamFromPath("../../../models/MergeGlTF/Avocado.glb")) { GltfMergingUtils.AddAllMeshesFromFromGlb(avocadoStream, buffers, bufferByteArrays, buffViews, accessors, meshes, materials, textures, images, samplers, true ); } ours.Buffers = buffers.ToArray(); ours.BufferViews = buffViews.ToArray(); ours.Accessors = accessors.ToArray(); ours.Meshes = meshes.ToArray(); ours.Materials = materials.ToArray(); ours.Images = images.ToArray(); ours.Textures = textures.ToArray(); if (samplers.Count > 0) { ours.Samplers = samplers.ToArray(); } var nodeList = ours.Nodes.ToList(); var transform = new Transform(new Vector3(1, 1, 0), Vector3.XAxis, Vector3.YAxis.Negate()).Scaled(20); NodeUtilities.CreateNodeForMesh(ours.Meshes.Length - 1, nodeList, transform); ours.Nodes = nodeList.ToArray(); var savepath = "../../../GltfTestResult.gltf"; ours.SaveBuffersAndAddUris(savepath, bufferByteArrays); ours.SaveModel(savepath); var mergedBuffer = ours.CombineBufferAndFixRefs(bufferByteArrays.ToArray()); ours.SaveBinaryModel(mergedBuffer, "../../../GltfTestMerged.glb"); } }
/// <summary> /// Gets a function signature from the given symbol /// </summary> /// <param name="symbol">Function's symbol</param> /// <returns>The symbol broken down into a friendlier representation</returns> public static DScriptFunctionSignature FromSymbol(ISymbol symbol) { var declaration = symbol.GetFirstDeclarationOrDefault(); if (declaration == null) { return(null); } var functionLikeDeclaration = NodeUtilities.IsFunctionLike(declaration); if (functionLikeDeclaration != null) { return(GetSymbolFromFunction(symbol.Name, functionLikeDeclaration.Parameters)); } // check to see if this is a property that's really just a function reference - if so treat it like a function // instead of a property IPropertySignature propertySignature = declaration.As <IPropertySignature>(); if (propertySignature == null) { return(null); } IFunctionOrConstructorTypeNode functionTypeNode = propertySignature?.Type.As <IFunctionOrConstructorTypeNode>(); if (functionTypeNode == null) { return(null); } return(GetSymbolFromFunction(symbol.Name, functionTypeNode.Parameters)); }
/// <summary> /// Populates current scope with a given <paramref name="symbolTable"/>. /// </summary> internal void PopulateFromSymbolTable([CanBeNull] ISymbolTable symbolTable) { // The binder in some cases optimizes the local table block and does not create a symbol table at all if (symbolTable == null) { return; } foreach (var kvp in symbolTable) { var symbol = kvp.Value; var declaration = symbol.DeclarationList.First(); if (declaration.Kind != TypeScript.Net.Types.SyntaxKind.VariableDeclaration && declaration.Kind != TypeScript.Net.Types.SyntaxKind.Parameter) { // Need to register only variable declarations! continue; } // TODO: next statment will fail even for valid names. // For instance, $ is not a valid character for SymbolAtom but it is a valid identifier. // This logic needs to be revisit. var atom = SymbolAtom.Create(m_stringTable, declaration.Name.Text); var location = declaration.Location(m_sourceFile, m_sourceFilePath, m_pathTable); bool isConstant = NodeUtilities.IsConst(declaration); var index = AddVariable(atom, location, isConstant); Contract.Assume( index != null, I($"Found duplicate variable '{declaration.Name.Text}' in a source file. This should never happen because binder should fail on it!")); } }
private void OnGUI() { GUILayout.Space(20); GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); EditorGUILayout.LabelField("Create a new Dialogue Container:", EditorStyles.boldLabel); containerName = EditorGUILayout.TextField("Enter name: ", containerName); GUILayout.Space(5); EditorGUI.BeginChangeCheck(); _prefab = (GameObject)EditorGUILayout.ObjectField("Container Prefab", _prefab, typeof(GameObject), true); _canvas = (GameObject)EditorGUILayout.ObjectField("Canvas:", _canvas, typeof(GameObject), true); if (EditorGUI.EndChangeCheck()) { Repaint(); } GUILayout.Space(10); if (_prefab != null && _canvas != null) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Create Dialogue Container", GUILayout.Height(40))) { if (!string.IsNullOrEmpty(containerName) && containerName != "Enter a name...") { NodeUtilities.CreateContainer(_prefab, _canvas, containerName); containerPopup.Close(); } else { EditorUtility.DisplayDialog("Container Message", "Por favor, ingrese un nombre válido.", "OK"); } } if (GUILayout.Button("Cancel", GUILayout.Height(40))) { containerPopup.Close(); } GUILayout.EndHorizontal(); } else if (_canvas == null) { EditorGUILayout.HelpBox("The canvas can't be null.", MessageType.Error); } else { EditorGUILayout.HelpBox("The Container prefab can't be null.", MessageType.Error); } GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.EndHorizontal(); GUILayout.Space(20); }
public void VarBindingIsNotConstant() { string code = @"var x = 42"; var node = ParsingHelper.ParseFirstStatementFrom <IVariableStatement>(code); Assert.False(NodeUtilities.IsConst(node)); }
public void ConstBindingIsConstant() { string code = @"const x = 42"; var node = ParsingHelper.ParseFirstStatementFrom <IVariableStatement>(code); Assert.True(NodeUtilities.IsConst(node)); }
private static void AnalyzeVariableStatement(INode node, DiagnosticContext context) { var statement = node.Cast <IVariableStatement>(); if (statement.IsTopLevelOrNamespaceLevelDeclaration() && !NodeUtilities.IsConst(statement)) { context.Logger.ReportOnlyConstBindingOnNamespaceLevel( context.LoggingContext, statement.LocationForLogging(context.SourceFile)); } }
void ContextCallBack(object obj) { switch (obj.ToString()) { case "0": NodePopupWindow.InitNodePopup(); break; case "1": NodeUtilities.LoadGraph(); break; case "2": NodeUtilities.UnloadGraph(); break; case "3": NodeUtilities.CreateNode(currentGraph, NodeType.Dialogue, mousePos); break; case "4": NodeUtilities.CreateNode(currentGraph, NodeType.Question, mousePos); break; case "5": NodeUtilities.CreateNode(currentGraph, NodeType.Condicional, mousePos); break; case "6": NodeUtilities.DeleteNode(currentGraph, overNodeID); break; case "7": NodeUtilities.CreateNode(currentGraph, NodeType.Answer, mousePos); break; case "8": NodeUtilities.DisconnectInput(currentGraph, overNodeID); break; case "9": NodeUtilities.DisconnectOutput(currentGraph, overNodeID); break; case "10": NodeUtilities.CreateNode(currentGraph, NodeType.Delay, mousePos); break; default: break; } }
/// <nodoc /> public static ITextSpan GetErrorSpanForNode(ISourceFile sourceFile, INode node) { INode errorNode = node; switch (node.Kind) { case SyntaxKind.SourceFile: { var pos = Scanner.SkipTrivia(sourceFile.Text, 0, /*stopAfterLineBreak*/ false); if (pos == sourceFile.Text.Length) { // file is empty - return span for the beginning of the file return(TextUtilities.CreateTextSpan(0, 0)); } return(GetSpanOfTokenAtPosition(sourceFile, pos)); } // This list is a work in progress. Add missing node kinds to improve their error // spans. case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: case SyntaxKind.ClassDeclaration: case SyntaxKind.ClassExpression: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.MethodDeclaration: { errorNode = node.Cast <IDeclaration>().Name; break; } } if (errorNode == null) { // If we don't have a better node, then just set the error on the first token of // construct. return(GetSpanOfTokenAtPosition(sourceFile, node.Pos)); } var pos1 = NodeUtilities.NodeIsMissing(errorNode) ? errorNode.Pos : errorNode.GetNodeStartPositionWithoutTrivia(sourceFile); return(TextUtilities.CreateTextSpanFromBounds(pos1, errorNode.End)); }
private void OnGUI() { GUILayout.Space(20); GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); EditorGUILayout.LabelField("Create a new Graph:", EditorStyles.boldLabel); graphName = EditorGUILayout.TextField("Enter name: ", graphName); GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Create Graph", GUILayout.Height(40))) { if (!string.IsNullOrEmpty(graphName) && graphName != "Enter a name...") { NodeUtilities.CreateNewGraph(graphName); currentPopup.Close(); } else { EditorUtility.DisplayDialog("Graph Message", "Por favor, ingrese un nombre válido.", "OK"); } } if (GUILayout.Button("Cancel", GUILayout.Height(40))) { currentPopup.Close(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.EndHorizontal(); GUILayout.Space(20); }
public override void UpdateView(Rect editorRect, Rect precentageRect, Event e, NodeGraph currentGraph) { base.UpdateView(editorRect, precentageRect, e, currentGraph); GUI.Box(viewRect, viewTitle, viewSkin.GetStyle("ViewBG")); //Rect rect = currentGraph != null ? new Rect(new Vector2(-(float)Mathf.Infinity, -(float)Mathf.Infinity), new Vector2((float)Mathf.Infinity, (float)Mathf.Infinity)) : viewRect; //Debug.Log("position "+ rect.position+", size " + rect.size); NodeUtilities.DrawGrid(viewRect, 80f, 0.15f, Color.white, currentGraph); NodeUtilities.DrawGrid(viewRect, 40f, 0.10f, Color.white, currentGraph); NodeUtilities.DrawGrid(viewRect, 20f, 0.05f, Color.white, currentGraph); GUILayout.BeginArea(viewRect); if (currentGraph != null) { currentGraph.UpdateGraphGUI(e, viewRect, viewSkin); } GUILayout.EndArea(); ProcessEvents(e); }
private static bool TryAddConstructSignature( ISymbol symbol, INode location, string symbolKind, string symbolName, string containerName, List <SymbolLocation> result) { // Applicable only if we are in a new expression, or we are on a constructor declaration // and in either case the symbol has a construct signature definition, i.e. class if (Utilities.IsNewExpressionTarget(location) || location.Kind == SyntaxKind.ConstructorKeyword) { if ((symbol.Flags & SymbolFlags.Class) != SymbolFlags.None) { // Find the first class-like declaration and try to get the construct signature. foreach (var declaration in symbol.GetDeclarations()) { var classLikeDeclaration = NodeUtilities.IsClassLike(declaration); if (classLikeDeclaration != null) { return(TryAddSignature( symbol, classLikeDeclaration.Members.Elements, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result)); } } Debug.Fail("Expected declaration to have at least one class-like declaration"); } } return(false); }
/// <summary> /// Returns true if <paramref name="node"/> is a const enum declaration. /// </summary> public static bool IsConstEnumDeclaration(this INode node) { return(node.Kind == SyntaxKind.EnumDeclaration && NodeUtilities.IsConst(node)); }
public override void UpdateView(Rect editorRect, Rect precentageRect, Event e, NodeGraph currentGraph) { base.UpdateView(editorRect, precentageRect, e, currentGraph); GUILayout.BeginHorizontal("box"); if (GUILayout.Button("Create Graph")) { NodePopupWindow.InitNodePopup(); } if (GUILayout.Button("Load Graph")) { NodeUtilities.LoadGraph(); } if (currentGraph != null) { addNode = EditorGUILayout.Popup(addNode, new string[] { "Add Node", "Add Dialogue", "Add Question", "Add Condition", "Add Answer", "Add Delay" }, "Dropdown"); switch (addNode) { case 1: NodeUtilities.CreateNode(currentGraph, NodeType.Dialogue, new Vector2(50, 50)); addNode = 0; break; case 2: NodeUtilities.CreateNode(currentGraph, NodeType.Question, new Vector2(50, 50)); addNode = 0; break; case 3: NodeUtilities.CreateNode(currentGraph, NodeType.Condicional, new Vector2(50, 50)); addNode = 0; break; case 4: NodeUtilities.CreateNode(currentGraph, NodeType.Answer, new Vector2(50, 50)); addNode = 0; break; case 5: NodeUtilities.CreateNode(currentGraph, NodeType.Delay, new Vector2(50, 50)); addNode = 0; break; } if (currentGraph.selectedNode != null) { if (currentGraph.selectedNode.nodeType != NodeType.Start && currentGraph.selectedNode.nodeType != NodeType.End) { editNode = EditorGUILayout.Popup(editNode, new string[] { "Edit Node", "Disconect input", "Disconect output", "Delete node" }, "Dropdown"); } if (currentGraph.selectedNode.nodeType == NodeType.End) { editNode = EditorGUILayout.Popup(editNode, new string[] { "Edit Node", "Disconect input" }, "Dropdown"); } if (currentGraph.selectedNode.nodeType == NodeType.Start) { editNode = EditorGUILayout.Popup(editNode, new string[] { "Edit Node", "Disconect output" }, "Dropdown"); } switch (editNode) { case 1: if (currentGraph.selectedNode.nodeType != NodeType.Start) { NodeUtilities.DisconnectInput(currentGraph, currentGraph.nodes.IndexOf(currentGraph.selectedNode)); } if (currentGraph.selectedNode.nodeType == NodeType.Start) { NodeUtilities.DisconnectOutput(currentGraph, currentGraph.nodes.IndexOf(currentGraph.selectedNode)); } editNode = 0; break; case 2: NodeUtilities.DisconnectOutput(currentGraph, currentGraph.nodes.IndexOf(currentGraph.selectedNode)); editNode = 0; break; case 3: NodeUtilities.DeleteNode(currentGraph, currentGraph.nodes.IndexOf(currentGraph.selectedNode)); editNode = 0; break; } } if (GUILayout.Button("Unload Graph")) { NodeUtilities.UnloadGraph(); } } GUILayout.EndHorizontal(); }
private static bool TryCreateImportStatementCommand( Workspace workspace, PathTable pathTable, CodeActionParams actionParams, out dynamic[] commandArguments) { commandArguments = default(dynamic[]); var typeChecker = workspace.GetSemanticModel().TypeChecker; if (!actionParams.TextDocument.Uri.TryGetSourceFile(workspace, pathTable, out var sourceUri)) { return(false); } Contract.Assert(actionParams.Range?.Start != null); if (!DScriptNodeUtilities.TryGetNodeAtPosition(sourceUri, actionParams.Range.Start.ToLineAndColumn(), out var node)) { return(false); } var nodeFlags = NodeUtilities.GetCombinedNodeFlags(node); if ((nodeFlags & NodeFlags.ScriptPublic) == NodeFlags.None) { return(false); } var symbol = typeChecker.GetSymbolAtLocation(node) ?? node.Symbol ?? node.ResolvedSymbol; if (symbol == null) { return(false); } var symbolFullName = typeChecker.GetFullyQualifiedName(symbol); // The import statement can only contain a single identifier, so if the symbol's full name // is Namespace.Subnamespace.value, we care about just 'Namespace' var identifier = GetFirstIdentifier(symbolFullName); var module = workspace.TryGetModuleBySpecFileName(sourceUri.GetAbsolutePath(pathTable)); if (module == null) { return(false); } var importString = string.Format( CultureInfo.InvariantCulture, "import {{{0}}} from \"{1}\";", identifier, module.Definition.Descriptor.Name); var bannerString = FormattableStringEx.I($"Import string for '{symbolFullName}' placed on clipboard"); commandArguments = new dynamic[] { importString, bannerString, }; return(true); }
private ParseAction <SYMBOL_ENUM, TREE_NODE> computeAction(Node <SYMBOL_ENUM, TREE_NODE> node, SymbolChunk <SYMBOL_ENUM> inputChunk) { List <SingleState <SYMBOL_ENUM, TREE_NODE> > shift_items, reduce_items; NodeUtilities.FilterItems(node, inputChunk, out shift_items, out reduce_items); var rr_actions = reduce_items.Select(it => ReductionActionFactory.Create(it, coverSets, horizonSets)).ToArray(); ISymbolPrecedence <SYMBOL_ENUM> rr_precedence = null; if (reduce_items.Count > 1) { if (!disambiguateReduceReduceConflictOnShortHorizon(rr_actions)) { rr_precedence = precedenceTable.GetReduceReduce(reduce_items.Select(it => it.LhsSymbol), inputChunk); if (rr_precedence == null) { report.AddError(reduce_items.Select(it => it.IndexStr), "REDUCE/REDUCE conflict for input: " + inputChunk.ToString(symbolsRep)); rr_actions = null; } } } // this is what will be the result of the function, it is crucial, that resolving RR conflict // should not collide with resolving RS conflict ParseAction <SYMBOL_ENUM, TREE_NODE> result_action = null; if (shift_items.Count == 0) { if (reduce_items.Count == 0) { throw new Exception("Internal parser error -- wrong input for node " + node.State.Index + " for input: " + inputChunk.ToString(symbolsRep)); } else if (reduce_items.Count == 1) { result_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(false, rr_actions.Single().DisableHorizon()); } else { result_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(false, rr_actions); } } else if (reduce_items.Count == 0) { result_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(true); } else { if (rr_actions != null && disambiguateShiftReduceConflictOnHorizon(shift_items, rr_actions)) { result_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(true, rr_actions); } else { // here we have not only some shift rules active, but also at least one reduce rule // so it can be shift-reduce conflict or shift-reduce-reduce conflict // we loop over reduce items, however this is becase we try to report ALL conflicts in one go // in situation of no reduce/reduce conflict this would be a single or no item foreach (SingleState <SYMBOL_ENUM, TREE_NODE> r_item in reduce_items) { // don't cache it because of usage registration ISymbolPrecedence <SYMBOL_ENUM> shift_precedence = precedenceTable.GetShiftOperator(inputChunk); // it picks up basic operator or entire pattern ISymbolPrecedence <SYMBOL_ENUM> reduce_precedence = precedenceTable.GetShiftReduce( shift_items.Select(s_item => s_item.LhsSymbol), r_item.LhsSymbol, r_item.RhsSeenSymbols, inputChunk, (s) => report.AddError(s) ); // in operator mode we can copy from shift to reduce if (reduce_precedence == null && shift_precedence != null && shift_precedence.Mode == SymbolPrecedence.ModeEnum.BasicOperatorSearch) { reduce_precedence = shift_precedence; } // if priority permits in shift-reduce mode we can copy from reduce to shift if (reduce_precedence != null && reduce_precedence.Mode == SymbolPrecedence.ModeEnum.ShiftReduceConflict && (shift_precedence == null || reduce_precedence.Priority > shift_precedence.Priority)) { precedenceTable.UnregisterUse(shift_precedence); shift_precedence = reduce_precedence; } // we have to check if this is not killed by reduce-reduce priority meaning // it would be reduce anyway if (rr_precedence != null && (shift_precedence != null && rr_precedence.Priority > shift_precedence.Priority && shift_precedence.Mode == SymbolPrecedence.ModeEnum.ShiftReduceConflict) && (reduce_precedence == null || rr_precedence.Priority > reduce_precedence.Priority)) { precedenceTable.UnregisterUse(shift_precedence); precedenceTable.UnregisterUse(reduce_precedence); continue; } ParseAction <SYMBOL_ENUM, TREE_NODE> local_action = null; if (shift_precedence != null && reduce_precedence != null) { if (shift_precedence.Mode != reduce_precedence.Mode) { // the modes have to match } else if (reduce_precedence.Priority > shift_precedence.Priority) { local_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(false, Parser.ReductionAction.Create(r_item.CreateCell())); } else if (reduce_precedence.Priority < shift_precedence.Priority) { local_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(true); } else if (reduce_precedence.Associativity == AssociativityEnum.Reduce && shift_precedence.Associativity == AssociativityEnum.Reduce) { local_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(false, Parser.ReductionAction.Create(r_item.CreateCell())); } else if (reduce_precedence.Associativity == AssociativityEnum.Shift && shift_precedence.Associativity == AssociativityEnum.Shift) { local_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(true); } else if (reduce_precedence.Associativity == AssociativityEnum.Try && shift_precedence.Associativity == AssociativityEnum.Try && shift_precedence.Symbols.Equals(reduce_precedence.Symbols)) { local_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(true, Parser.ReductionAction.Create(r_item.CreateCell())); } else if (reduce_precedence.Associativity == AssociativityEnum.None && shift_precedence.Associativity == AssociativityEnum.None) { // it should trigger syntax error while parsing, it is not grammar error, // so don't report it, but don't add to table either local_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(false); report.AddInformation("None precedence on (" + inputChunk.ToString(symbolsRep) + ") nulled out: " + String.Join(" ; ", shift_items.Select(it => it.Production.ToString())) + " vs. " + r_item.Production.ToString()); } } // those cases should be solved at the grammar design stage if (local_action == null // we didn't get any action // we got some action but the current pack is different from the last one || (result_action != null && (result_action.Shift != local_action.Shift || result_action.HasAnyReduction != local_action.HasAnyReduction))) { report.AddError(shift_items.Select(it => it.IndexStr).Concat(r_item.IndexStr), "Reduce/shift conflict on symbol " + inputChunk.ToString(symbolsRep) + (local_action == null ? "" : " because of previous reduce/shift resolution") + "."); precedenceTable.UnregisterUse(shift_precedence); precedenceTable.UnregisterUse(reduce_precedence); local_action = null; } if (local_action != null) { if (result_action == null) { result_action = local_action; } else { result_action = new ParseAction <SYMBOL_ENUM, TREE_NODE>(result_action.Shift && local_action.Shift, result_action.Reductions.Concat(local_action.Reductions).ToArray()); } } } // end of iterating over reduce items // we have rule for RR conflict and yet at the same time we have rule for RS conflict // which overrides the first one -- so the RR rule should not exist in the first place if (rr_actions != null && rr_actions.Length > 1 && result_action != null && !result_action.HasAnyReduction) { report.AddError(shift_items.Select(it => it.IndexStr), "Reduce/shift conflict resolution on symbol " + inputChunk.ToString(symbolsRep) + " overrides previous reduce/reduce resolution."); precedenceTable.UnregisterUse(rr_precedence); result_action = null; } } } return(result_action); }