public static void MakeReservedNames (AdaDeclarations Declarations) { for (int j = 0; j < vs_lexer_pkg.tokensN.Length; j++) { string tName = TokenName(j).ToLower(); Declarations.addDeclaration(tName.Substring(0, tName.Length - 2)); if (tName == "xor_t") { break; // xor_t is the last reserved keyword } } }
public static void MakeNames (string Buffer, int Buffer_Last, AdaDeclarations Declarations) { int CurrentLoc = 0; vs_lexer.token_record Token; string Previous_Type = "DOT_T"; while (CurrentLoc < Buffer_Last) { Token = vs_lexer_pkg.get_token(Buffer.ToCharArray(), 0, Buffer_Last, CurrentLoc); if ((TokenName(Token.kind) == "NAME_T") && (Previous_Type != "DOT_T")) { string bob = Buffer.Substring(Token.start_index, Token.end_index - Token.start_index + 1); Declarations.addDeclaration(bob); } Previous_Type = TokenName(Token.kind); CurrentLoc = Token.end_index + 1; } }
public override AuthoringScope ParseSource(ParseRequest req) { bool match_braces = false; //System.Diagnostics.Trace.WriteLine("parsesource:" + req.Reason); if (req.Reason == ParseReason.Check || req.Reason == ParseReason.None) { // Parse entire source as given in req.Text. // Store results in the MyAuthoringScope object. } else if (req.Reason == ParseReason.MemberSelect || req.Reason == ParseReason.CompleteWord) { // Parse the line specified in req.Line for the two // tokens just before req.Col to obtain the identifier // and the member connector symbol. // Examine existing parse tree for members of the identifer // and return a list of members in your version of the // Declarations class as stored in the MyAuthoringScope // object. AdaDeclarations decls = new AdaDeclarations(); IVsTextLines lines; string line; req.View.GetBuffer(out lines); lines.GetLineText(req.Line, 0, req.Line + 1, 0, out line); if (HasDot(line, req.Col - 1)) { AdaSuggestions.MakeDeclarations(req.FileName, req.Text, line, req.Col - 1, decls); } // ??? Should look for ' in order to build an attribute list. else { int pos2; lines.GetPositionOfLineIndex(req.Line, req.Col - 1, out pos2); AdaSuggestions.MakeReservedNames(decls); // ??? also add basic types (integer, string, etc) AdaSuggestions.MakeNames(req.Text, pos2, decls); System.Diagnostics.Trace.WriteLine("filename:" + req.FileName); System.Diagnostics.Trace.WriteLine(System.IO.Path.GetExtension(req.FileName)); if (System.IO.Path.GetExtension(req.FileName).ToLower() == ".adb") { string spec = System.IO.Path.ChangeExtension(req.FileName, ".ads"); System.Diagnostics.Trace.WriteLine(spec); if (System.IO.File.Exists(spec)) { System.Diagnostics.Trace.WriteLine("opened"); System.IO.StreamReader sr = new System.IO.StreamReader(spec); string contents = sr.ReadToEnd(); AdaSuggestions.MakeNames(contents, contents.Length - 1, decls); } } } return(new AdaAuthoringScope(decls)); } else if (req.Reason == ParseReason.MethodTip) { AdaMethods methods; // Parse the line specified in req.Line for the token // just before req.Col to obtain the name of the method // being entered. // Examine the existing parse tree for all method signatures // with the same name and return a list of those signatures // in your version of the Methods class as stored in the // MyAuthoringScope object. if ((req.TokenInfo.Trigger & TokenTriggers.ParameterStart) != 0) { methods = new AdaMethods(); IVsTextLines lines; req.View.GetBuffer(out lines); string line; lines.GetLineText(req.Line, 0, req.Line + 1, 0, out line); string lineChars = line.Substring(0, req.Col - 1); string linesChars = req.Text; AdaSuggestions.MakeMethods(req.FileName, linesChars, lineChars, req.Col - 1, methods); // suggestions_pkg.makemethods(req.FileName, linesChars, 0, linesChars.Length - 1, // lineChars, 0, lineChars.Length - 1, // req.Col - 1, methods, 0); TextSpan ts = new TextSpan(); ts.iStartLine = ts.iEndLine = req.Line; ts.iStartIndex = req.Col - 1; ts.iEndIndex = req.Col; method_start_location = ts; if (methods.GetCount() != 0) { req.Sink.StartName(ts, "bob"); req.Sink.StartParameters(ts); } param_count = 0; remember_methods = methods; } else if ((req.TokenInfo.Trigger & TokenTriggers.ParameterEnd) != 0) { methods = new AdaMethods(); req.Sink.EndParameters(method_start_location); } else { IVsTextLines lines; int pos, pos2; int quote_count = 0; int paren_count = 0; req.View.GetBuffer(out lines); Char[] linesChars = req.Text.ToCharArray(); req.Sink.StartName(method_start_location, "bob"); req.Sink.StartParameters(method_start_location); lines.GetPositionOfLineIndex(method_start_location.iStartLine, method_start_location.iEndIndex, out pos); lines.GetPositionOfLineIndex(req.Line, req.Col, out pos2); for (int i = pos; i < pos2; i++) { if (linesChars[i] == '(' && quote_count == 0) { paren_count++; } else if (linesChars[i] == '"') { quote_count = (1 - quote_count); } else if (linesChars[i] == ')' && quote_count == 0) { paren_count--; } else if (linesChars[i] == ',' && quote_count == 0 && paren_count == 0) { TextSpan ts2 = new TextSpan(); int line, col; lines.GetLineIndexOfPosition(i, out line, out col); ts2.iStartLine = line; ts2.iEndLine = line; ts2.iStartIndex = col - 1; ts2.iEndIndex = col; req.Sink.NextParameter(ts2); param_count++; } } methods = remember_methods; } return(new AdaAuthoringScope(methods)); } if (req.Sink.BraceMatching || match_braces) { TextSpan span1 = new TextSpan(); TextSpan span2 = new TextSpan(); int parensFound = 1; int charIndex; int piVirtualSpaces; int direction = vs_lexer_pkg.match_direction(req.TokenInfo.Token); req.View.GetNearestPosition(req.Line, req.Col, out charIndex, out piVirtualSpaces); if (direction == -1) { charIndex -= 2; } span1.iStartLine = req.Line; span1.iStartIndex = req.Col - 1; span1.iEndLine = req.Line; span1.iEndIndex = req.Col; if (my_authoring_scope == null) { my_authoring_scope = new AdaAuthoringScope(); } if (direction == 1) { while (charIndex < req.Text.Length) { if (req.Text[charIndex] == ')') { parensFound--; if (parensFound == 0) { req.View.GetLineAndColumn(charIndex, out span2.iStartLine, out span2.iStartIndex); span2.iEndLine = span2.iStartLine; span2.iEndIndex = span2.iStartIndex + 1; req.Sink.MatchPair(span1, span2, 1); return(my_authoring_scope); } } else if (req.Text[charIndex] == '(') { parensFound++; } charIndex++; } } else if (direction == -1) { while (charIndex >= 0) { if (req.Text[charIndex] == '(') { parensFound--; if (parensFound == 0) { req.View.GetLineAndColumn(charIndex, out span2.iStartLine, out span2.iStartIndex); span2.iEndLine = span2.iStartLine; span2.iEndIndex = span2.iStartIndex + 1; req.Sink.MatchPair(span1, span2, 1); return(my_authoring_scope); } } else if (req.Text[charIndex] == ')') { parensFound++; } charIndex--; } } } return(my_authoring_scope); }
private static bool IsBasicName(string Name, AdaDeclarations Declarations) { if (Name.ToLower() == "ada") { Declarations.addDeclaration("Calendar"); Declarations.addDeclaration("Characters"); Declarations.addDeclaration("Command_Line"); Declarations.addDeclaration("Complex_Text_IO"); Declarations.addDeclaration("Containers"); Declarations.addDeclaration("Decimal"); Declarations.addDeclaration("Direct_IO"); Declarations.addDeclaration("Directories"); Declarations.addDeclaration("Environment_Variables"); Declarations.addDeclaration("Exceptions"); Declarations.addDeclaration("Finalization"); Declarations.addDeclaration("Float_Text_IO"); Declarations.addDeclaration("Float_Wide_Text_IO"); Declarations.addDeclaration("Integer_Text_IO"); Declarations.addDeclaration("Integer_Wide_Text_IO"); Declarations.addDeclaration("Long_Float_Text_IO"); Declarations.addDeclaration("Long_Float_Wide_Text_IO"); Declarations.addDeclaration("Real_Time"); Declarations.addDeclaration("Sequential_IO"); Declarations.addDeclaration("Strings"); Declarations.addDeclaration("Tags"); Declarations.addDeclaration("Text_IO"); Declarations.addDeclaration("Unchecked_Conversion"); Declarations.addDeclaration("Unchecked_Deallocation"); Declarations.addDeclaration("Wide_Text_IO"); Declarations.addDeclaration("Wide_Characters"); return(true); } else if (Name.ToLower() == "ada.characters") { Declarations.addDeclaration("Conversions"); Declarations.addDeclaration("Handling"); Declarations.addDeclaration("Latin_1"); Declarations.addDeclaration("Wide_Latin_1"); return(true); } else if (Name.ToLower() == "ada.containers") { Declarations.addDeclaration("Doubly_Linked_Lists"); Declarations.addDeclaration("Hashed_Maps"); Declarations.addDeclaration("Hashed_Sets"); Declarations.addDeclaration("Hash_Tables"); Declarations.addDeclaration("Indefinite_Doubly_Linked_Lists"); Declarations.addDeclaration("Indefinite_Hashed_Maps"); Declarations.addDeclaration("Indefinite_Hashed_Sets"); Declarations.addDeclaration("Indefinite_Ordered_Maps"); Declarations.addDeclaration("Indefinite_Ordered_Multisets"); Declarations.addDeclaration("Indefinite_Ordered_Sets"); Declarations.addDeclaration("Ordered_Maps"); Declarations.addDeclaration("Ordered_Multisets"); Declarations.addDeclaration("Ordered_Sets"); Declarations.addDeclaration("Red_Black_Trees"); Declarations.addDeclaration("Prime_Numbers"); Declarations.addDeclaration("Vectors"); return(true); } else if (Name.ToLower() == "ada.numerics") { Declarations.addDeclaration("Complex_Elementary_Functions"); Declarations.addDeclaration("Complex_Types"); Declarations.addDeclaration("Discrete_Random"); Declarations.addDeclaration("Elementary_Functions"); Declarations.addDeclaration("Float_Random"); Declarations.addDeclaration("Long_Complex_Elementary_Functions"); Declarations.addDeclaration("Long_Complex_Types"); Declarations.addDeclaration("Long_Elementary_Functions"); return(true); } else if (Name.ToLower() == "ada.strings") { Declarations.addDeclaration("Bounded"); Declarations.addDeclaration("Fixed"); Declarations.addDeclaration("Maps"); Declarations.addDeclaration("Superbounded"); Declarations.addDeclaration("Unbounded"); Declarations.addDeclaration("Wide_Bounded"); Declarations.addDeclaration("Wide_Fixed"); Declarations.addDeclaration("Wide_Maps"); Declarations.addDeclaration("Wide_Superbounded"); Declarations.addDeclaration("Wide_Unbsounded"); return(true); } else if (Name.ToLower() == "ada.strings.unbounded") { Declarations.addDeclaration("Text_IO"); Declarations.addDeclaration("Unbounded_String"); return(true); } else if (Name.ToLower() == "ada.text_io") { Declarations.addDeclaration("Create"); Declarations.addDeclaration("Enumeration_IO"); Declarations.addDeclaration("Get"); Declarations.addDeclaration("Get_Line"); Declarations.addDeclaration("Open"); Declarations.addDeclaration("Put"); Declarations.addDeclaration("Put_Line"); Declarations.addDeclaration("Skip_Line"); return(true); } else if (Name.ToLower() == "ada.wide_characters") { Declarations.addDeclaration("Unicode"); return(true); } return(false); }
public static void MakeDeclarations (string TheFileName, string Buffer, string Line, int Column, AdaDeclarations Declarations) { int Start = 0; int End = Column; string FileName = TheFileName.ToLower(); for (int j = Column; j >= 0; j--) { if (!Char.IsLetterOrDigit(Line[j]) && Line[j] != '.' && Line[j] != '_') { Start = j + 1; break; } } for (int j = Column; j > Start; j--) { if (Line[j] == '.') { End = j - 1; break; } } // maybe we've got something like 3 . if (Start > End) { return; } string Prefix; string FoundFilename; string FoundDirectory; char[] tmp = new char[End - Start + 1]; for (int j = Start; j <= End; j++) { tmp[j - Start] = (char)Line[j]; } Prefix = new String(tmp).ToLower(); mcc.gnat_tools.xref.xref_file_list_package.node Xrefs = new mcc.gnat_tools.xref.xref_file_list_package.node(); if (IsBasicName(Prefix, Declarations)) { return; } { string tmpFilename = Dashify(Prefix); string FullPath = DefaultLocation.Find_File(tmpFilename, "", System.IO.Directory.GetParent(FileName).FullName, true); if (FullPath.Length == 0) { tmpFilename = Krunch(tmpFilename); FullPath = DefaultLocation.Find_File(tmpFilename, "", System.IO.Directory.GetParent(FileName).FullName, true); } if (FullPath.Length == 0) { return; } FoundFilename = tmpFilename + ".ads"; FoundDirectory = DefaultLocation.Find_File(tmpFilename, "", System.IO.Directory.GetParent(FileName).FullName, false); FoundDirectory = System.IO.Directory.GetParent(FoundDirectory).FullName; mgnat.adalib.Acc Xrefs_Acc = new mgnat.adalib.Acc(); byte[] bFileName = new byte[FullPath.Length]; for (int j = 0; j < FullPath.Length; j++) { bFileName[j] = (byte)FullPath[j]; } Xrefs_Acc.all = null; mcc.gnat_tools.xref_pkg.read_ali(bFileName, 0, bFileName.GetUpperBound(0), Xrefs_Acc); if (Xrefs_Acc.all != null) { bFileName = new byte[FoundFilename.Length]; for (int j = 0; j < FoundFilename.Length; j++) { bFileName[j] = (byte)FoundFilename[j]; } Xrefs = (mcc.gnat_tools.xref.xref_file_list_package.node)Xrefs_Acc.all; lastInserted = ""; Remember_Declarations = Declarations; mcc.gnat_tools.xref_pkg.enumerate_public_entities (bFileName, 0, bFileName.Length - 1, Xrefs, new mcc.gnat_tools.xref.public_callback_type(Lb_Insert)); } } if (FoundDirectory.Length != 0) { string[] results = System.IO.Directory.GetFiles(FoundDirectory, Dashify(Prefix) + "-" + "*.ad*"); for (int j = 0; j < results.Length; j++) { string thisOne = System.IO.Path.GetFileNameWithoutExtension(results[j]); string answer = thisOne.Substring(Prefix.Length, thisOne.Length - Prefix.Length); if (answer.IndexOf('-') == -1) { Declarations.addDeclaration(answer); } } } }