/// <summary> /// Inserts the symbol associated to the declaration /// </summary> /// <param name="node">Declaration information.</param> /// <returns>The symbol inserted</returns> private Symbol declarationSymbol(IdDeclaration node) { string id = node.Identifier; TypeExpression te = this.searchType(node.FullName, node.Location.Line, node.Location.Column); if (node.IdentifierExp.IndexOfSSA != -1 && this.includeSSAVars) { id += node.IdentifierExp.IndexOfSSA; } //this.table.Insert(id, te,false); this.table.Insert(id, node); //TypeExpression te = this.searchType(node.FullName, node.Location.Line, node.Location.Column); //if (te != null) //{ // //node.TypeExpr = te; // string id = node.Identifier; // //if (node.IdentifierExp.IndexOfSSA != -1) // // id += node.IdentifierExp.IndexOfSSA; // if (node.IdentifierExp.IndexOfSSA != -1 && this.includeSSAVars) // id += node.IdentifierExp.IndexOfSSA; // //this.table.Insert(id, te,false); // this.table.Insert(id,node); //} //ErrorManager.Instance.NotifyError(new UnknownTypeError(node.FullName, new Location(this.currentFile, node.Location.Line, node.Location.Column))); return(null); }
/// <summary> /// Inserts the symbol associated to the declaration /// </summary> /// <param name="node">Declaration information.</param> /// <returns>The symbol inserted</returns> private Symbol declarationSymbol(IdDeclaration node) { TypeExpression te = this.searchType(node.FullName, node.Location.Line, node.Location.Column); if (te != null) { node.TypeExpr = te; string id = node.Identifier; if (node.IdentifierExp.IndexOfSSA != -1) { id += node.IdentifierExp.IndexOfSSA; } if (te is TypeVariable && te.IsDynamic) { setDynamic(node.Identifier); } Symbol symbol = this.table.Insert(id, te, searchDynInfo(node.Identifier)); if (symbol == null) { ErrorManager.Instance.NotifyError(new DeclarationFoundError(node.Identifier, new Location(this.currentFile, node.Location.Line, node.Location.Column))); } return(symbol); } ErrorManager.Instance.NotifyError(new UnknownTypeError(node.FullName, new Location(this.currentFile, node.Location.Line, node.Location.Column))); return(null); }
//Command event-handlers #region MakeVarStaticCommand /// <summary> /// Set static var reference at the cursor's location. /// Cause check parse and window repaint. /// </summary> /// <param name="sender">Not used</param> /// <param name="e">Not used</param> public void MakeVarStaticCommand(object sender, EventArgs e) { //MakeVarDynamicBeforeQueryStatus have found the current node if (foundNode == null) { return; } if (foundNode is Declaration) { //Declaration dec = foundNode as Declaration; IdDeclaration idDec = foundNode as IdDeclaration; //Must be a TypeVariable if (!(idDec.TypeExpr is TypeVariable)) { MessageBox.Show( "Variable \"" + idDec.Identifier + "\" its not TypeVariable", "Cannot make Static", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string varName = idDec.Identifier; int column = currentCaretPosition.Y; int line = currentCaretPosition.X; //Change the .dyn file StaDynDynamicHelper.Instance.makeVarStatic(varName, line, column, currentFile.Ast); this.parseAndRefreshHighlingting(); } }
// Expressions #region Visit(NewArrayExpression node, Object obj) public override Object Visit(NewArrayExpression node, Object obj) { string tmpName = auxiliarVar + CurrentAuxiliarSuffix++; SingleIdentifierExpression sId = new SingleIdentifierExpression(tmpName, node.Location); IdDeclaration id = new IdDeclaration(sId, -1, node.TypeInfo, node.Location); id.TypeExpr = node.ILTypeExpression; if (TemporalVariablesTable.Instance.SearchId(id.FullName) == null) // it's a new inserction { TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName); } node.Identifier = id.Identifier; //decls.Add(id); this.decls.Add(id); if (node.Size != null) { node.Size.Accept(this, obj); } if (node.Init != null) { node.Init.Accept(this, obj); } return(this.decls); }
private void parameterSymbol(MethodDefinition node) { var method = node as MethodDefinition; if (method == null || method.TypeExpr == null) { return; } for (int i = 0; i < ((MethodType)node.TypeExpr).ParameterListCount; i++) { string id = node.ParametersInfo[i].Identifier; var exp = new SingleIdentifierExpression(id, node.Location); var type = ((MethodType)node.TypeExpr).GetParameter(i); IdDeclaration dec = new IdDeclaration(exp, type.FullName, node.Location); dec.TypeExpr = type; this.table.Insert(id, dec); //this.table.Insert(id, ((MethodType)node.TypeExpr).GetParameter(i), false); //if (!(((MethodType)node.TypeExpr).GetParameter(i) is ArrayType)) // id += ": (parameter)"; ////if (this.table.Insert(id, ((MethodType)node.TypeExpr).GetParameter(i), searchDynInfo(node.ParametersInfo[i].Identifier)) == null) //if (this.table.Insert(id, ((MethodType)node.TypeExpr).GetParameter(i), false) == null) // ErrorManager.Instance.NotifyError(new DeclarationFoundError(node.ParametersInfo[i].Identifier, new Location(this.currentFile, node.Location.Line, node.Location.Column))); } }
private string getMemberIdentifier(IdDeclaration node) { StringBuilder aux = new StringBuilder(); aux.Append(getClassIdentifier()); aux.Append("."); aux.Append(node.Identifier); return(aux.ToString()); }
public override Object Visit(IdDeclaration node, Object obj) { SingleIdentifierExpression clonedIdentifierExp = (SingleIdentifierExpression)node.IdentifierExp.Accept(this, obj); IdDeclaration clonedIdDeclaration = new IdDeclaration(clonedIdentifierExp, clonedIdentifierExp.IndexOfSSA, node.TypeExpr.typeExpression, node.Location); clonedIdDeclaration.TypeExpr = node.TypeExpr.CloneType(this.typeVariableMappings, this.typeExpresionVariableMapping); Symbol originalSymbol = node.Symbol; Symbol symbol = new Symbol(originalSymbol.Name, originalSymbol.Scope, originalSymbol.SymbolType.CloneType(this.typeVariableMappings, this.typeExpresionVariableMapping), originalSymbol.IsDynamic); clonedIdDeclaration.Symbol = symbol; return(clonedIdDeclaration); }
/// <summary> /// Insert a new symbol in the current scope. /// </summary> /// <param name="id">Symbol identifier.</param> /// <param name="type">Symbol type.</param> /// <param name="isDynamic">True if the symbol is dynamic, false otherwise.</param> /// <returns>The symbol inserted, null otherwise.</returns> //public string Insert(string id, TypeExpression type, bool isDynamic) //{ // if (this.table[this.table.Count - 1].ContainsKey(id)) // return null; // //Symbol s = new Symbol(id, this.table.Count - 1, type, isDynamic); // this.table[this.table.Count - 1].Add(id, type); // //Console.WriteLine(s.ToString()); // return id; //} public string Insert(string id, IdDeclaration node) { if (this.table[this.table.Count - 1].ContainsKey(id)) { return(null); } //Symbol s = new Symbol(id, this.table.Count - 1, type, isDynamic); //this.table[this.table.Count - 1].Add(id, type); this.table[this.table.Count - 1].Add(id, node); //Console.WriteLine(s.ToString()); return(id); }
public override Object Visit(IdDeclaration node, Object obj) { if (!node.FullName.EndsWith("[]")) { this.map.AddNewVariable(node.Identifier, node.FullName, node.Location); } else { node.IdentifierExp.IndexOfSSA = -1; } return(null); }
public override Object Visit(IdDeclaration node, Object obj) { declarationSymbol(node); //if (node.Location == ((AstNode)obj).Location || found) //{ // found = true; // return this.table; //} //node.Symbol = declarationSymbol(node); return(this.table); }
//#region Visit(MethodDefinition node, Object obj) public override Object Visit(InvocationExpression node, Object obj) { node.Identifier.Accept(this, null); if (node.FrozenTypeExpression.IsValueType()) { SingleIdentifierExpression sid = new SingleIdentifierExpression(auxiliarValue + this.CurrentAuxiliarSuffix++, node.Location); IdDeclaration id = new IdDeclaration(sid, node.ILTypeExpression.ILType(), node.Location); id.TypeExpr = node.ExpressionType; if (TemporalVariablesTable.Instance.SearchId(id.FullName) == null) // it's a new inserction { TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName); decls.Add(id); } } node.Arguments.Accept(this, obj); return(null); }
public override Object Visit(FieldAccessExpression node, Object obj) { if (node.Expression.ExpressionType.IsValueType()) { SingleIdentifierExpression sId = new SingleIdentifierExpression(auxiliarValue + this.CurrentAuxiliarSuffix++, node.Location); IdDeclaration id = new IdDeclaration(sId, node.Expression.ExpressionType.ILType(), node.Location); id.TypeExpr = node.Expression.ExpressionType; // temporal variables of the same type are forbidden if (TemporalVariablesTable.Instance.SearchId(id.FullName) == null) // it's a new inserction { TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName); decls.Add(id); } } node.FieldName.Accept(this, obj); return(null); }
public override Object Visit(IdDeclaration node, Object obj) { int indent = Convert.ToInt32(obj); this.printIndentation(indent); if (node.IdentifierExp.IndexOfSSA != -1) { this.output.WriteLine("Declaration: {0}{1} [{2}:{3}]", node.Identifier, node.IdentifierExp.IndexOfSSA, node.Location.Line, node.Location.Column); } else { this.output.WriteLine("Declaration: {0} [{1}:{2}]", node.Identifier, node.Location.Line, node.Location.Column); } this.printIndentation(indent + 1); this.output.Write("Type: "); this.output.WriteLine(printType(node.TypeExpr)); return(null); }
//Other public methods #region DeclareExcplicit /// <summary> /// Modify var reference declaration changing from "var" to its actual type if possible. /// This method is public in order to be called by <see cref="CommandHandler.DeclareExplicitCommand"/> /// and <see cref="DeclareEverythingExplicitVisitor"/>. /// The operation will fail if the declaration has more than one type along its scope (counting as well /// types inside UnionType types). /// </summary> /// <param name="id">IdDeclaration node for the var reference declaration.</param> /// <param name="method">MethodDefinition node containing the var reference declaration.</param> /// <param name="buffer">IVsTextLines object containing document's content.</param> /// <param name="doc">TextDocument object for the document.</param> /// public void DeclareExplicit //public void DeclareExplicit(IdDeclaration id, MethodDefinition method, IVsTextLines buffer, TextDocument doc) //public void DeclareExplicit() //{ // int lineNumber = this.currentCaretPosition.X ; // int column = this.currentCaretPosition.Y; // var snapshot = FileUtilities.Instance.getCurrentTextSnapShot(); // int start = FileUtilities.Instance.getCurrentCaretPosition(); // StaDynVariablesInScopeTable infoVariablesInScope = StaDynIntellisenseHelper.Instance.getVariablesInCurrentScope(lineNumber +1, column, snapshot, start,true); // string varName = ((IdDeclaration)foundNode).Identifier; // var SSAVariablesList = new List<Declaration>(); // //Look for the same variable in the current scope // for (int i = 0; i < infoVariablesInScope.Table.Count; i++) // { // if (infoVariablesInScope.Table[i].Count > 0) // { // foreach (KeyValuePair<string, IdDeclaration> variable in infoVariablesInScope.Table[i]) // { // var type = variable.Value.TypeExpr; // if (variable.Key.StartsWith(varName) && type is TypeVariable && ((TypeVariable)type).Substitution !=null) // SSAVariablesList.Add(variable.Value); // } // } // } // if (SSAVariablesList.Count !=1) // { // string message; // if (SSAVariablesList.Count == 0) // message = "The var reference named '" + varName + // "' cannot be declared explicitly since it has no type yet\n"; // else // { // message = "The var reference named '" + varName + // "' cannot be declared explicitly since it has more than one type within its scope:\n"; // foreach (Declaration node in SSAVariablesList) // message += " - " + ((TypeVariable)node.TypeExpr).Substitution.FullName + "\n"; // message += "To be able to declare explicitly this reference, create a new type from which " // + "all this types will inherit"; // } // MessageBox.Show( // message, // "Cannot declare explicit", // MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // SourceHelper.replaceWord(snapshot, lineNumber, "var", ((TypeVariable)SSAVariablesList[0].TypeExpr).Substitution.FullName); //} #endregion #region GetAllTypes /// <summary> /// Get all types a reference has or may have along the method where it is declared. /// </summary> /// <param name="identifier">Name of the identifier.</param> /// <param name="method">Method where the identifier is declared.</param> /// <returns>Set of types assigned to the identifier. Types contained in /// UnionTypes are recursively inserted in the set.</returns> //public HashSet<TypeExpression> GetAllTypes(string identifier, MethodDefinition method) //{ // //Verify that the variable has only one type along the block // //(Making use of SSA duplicated IdDeclaration nodes for that) // //SearchInfo info = new SearchInfo(-1, -1, SearchReason.VarIdDeclarationSearch, StoreMode.StoreAll); // //if (method != null) // // method.Accept(new SearchVisitor(), info); // //HashSet<TypeExpression> types = new HashSet<TypeExpression>(); // //IdDeclaration id; // //foreach (AstNode node in info.NodeList) // //{ // // id = node as IdDeclaration; // // if (id == null | !id.Identifier.Equals(identifier)) // // continue; // // TypeVariable varType = id.TypeExpr as TypeVariable; // // TypeExpression substitutionType = varType != null ? varType.Substitution : null; // // if (substitutionType == null) // // continue; // // if (substitutionType is UnionType) // // { // // types.UnionWith(getTypesFromUnion(substitutionType as UnionType)); // // continue; // // } // // types.Add(substitutionType); // //} // //return types; //} #endregion // Private methods #region searchDynVarInfo //private SearchInfo searchDynVarInfo() //{ // TokenInfo token = null; // int line; // int column; // string tokenText = TextTools.GetCurrentTokenInfo(out token, out line, out column); // StaDynLanguage lang = Package.GetGlobalService(typeof(StaDynLanguage)) as StaDynLanguage; // DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)) as DTE; // StaDynScope scope = lang.GetParseResult(dte.ActiveDocument.FullName); // TextTools.VsToInference(ref line, ref column); // SearchInfo searchInfo = new SearchInfo(line, column, tokenText, SearchReason.AnyVarSearch, StoreMode.NamesAndNodes); // scope.Ast.Accept(new SearchVisitor(), searchInfo); // return searchInfo; //} #endregion #region beforeQueryStatusCommonTasks /// <summary> /// Performs several tasks useful for the commands' BeforeQueryStatus handlers. /// Stores in lastSearchInfo information retrieved by <see cref="CommandHandler.searchDynVarInfo"/>. /// </summary> /// <param name="isStaDynFile">Active document is a ".stadyn" file.</param> /// <param name="isVar">Token at cursor's location is a var reference.</param> /// <param name="isDynamic">Token at cursor's location is a dynamic var reference.</param> private void beforeQueryStatusCommonTasks(out bool isStaDynFile, out bool isVar, out bool isDynamic) { isStaDynFile = isVar = isDynamic = false; isStaDynFile = FileUtilities.Instance.checkCurrentFileExtension(".stadyn"); //Get the span of the current word (caret on) var currentWordTextSpan = SourceHelper.getCurrentTextSpan(); this.currentCaretPosition.X = currentWordTextSpan.iStartLine; this.currentCaretPosition.Y = currentWordTextSpan.iEndIndex; int line = currentWordTextSpan.iStartLine; int column = currentWordTextSpan.iEndIndex + 1; StaDynParser parser = new StaDynParser(); parser.parseAll(); currentFile = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (currentFile == null || currentFile.Ast == null) { return; } //string currentWord = SourceHelper.getCurrentWord(); //this.foundNode = (AstNode)currentFile.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(currentFile.FileName), line + 1, column)); this.foundNode = (AstNode)currentFile.Ast.Accept(new VisitorFindNode(), new Location(currentFile.FileName, line + 1, column)); if (foundNode is Declaration) { //Declaration dec = foundNode as Declaration; IdDeclaration idDec = foundNode as IdDeclaration; isVar = idDec.TypeExpr is TypeVariable; isDynamic = StaDynDynamicHelper.Instance.checkDynamicVar(idDec.Identifier, line, column, currentFile); //isDynamic = idDec.TypeExpr.IsDynamic; } }
public override Object Visit(ForeachStatement node, Object obj) { IdDeclaration clonedSingleIdentifierExpression = (IdDeclaration)node.ForEachDeclaration.Accept(this, obj); return(new ForeachStatement(clonedSingleIdentifierExpression.TypeExpr.typeExpression, clonedSingleIdentifierExpression.IdentifierExp, (Expression)node.ForeachExp.Accept(this, obj), (Statement)node.ForeachBlock.Accept(this, obj), node.Location)); }
public override Object Visit(IdDeclaration node, Object obj) { node.Symbol = declarationSymbol(node); return(null); }
//public override Object Visit(ConstantDefinition node, Object obj) { // Object obj = node.Init.Accept(this, obj); // if (cnode is node. // if ((((FieldType)node.TypeExpr).MemberInfo.ModifierMask & Modifier.Static) != 0) // this.fields[1].Add(node); //} #endregion // Local Variables #region Visit(IdDeclaration node, Object obj) public override Object Visit(IdDeclaration node, Object obj) { this.decls.Add(node); return(null); }
public abstract Object Visit(IdDeclaration node, Object obj);
public override Object Visit(IdDeclaration node, Object obj) { return(null); }