Пример #1
0
        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);
        }
Пример #2
0
        public static void MakeMethods
            (string FileName,
            string Buffer,
            string Line,
            int Column,
            AdaMethods Methods)
        {
            string adaFileName    = FileName.ToLower();
            int    nameFirst      = 0;
            int    nameLast       = Line.Length - 1;
            int    noDotNameFirst = 0;
            bool   haveOne        = false;

            mcc.gnat_tools.xref.xref_file_list_package.node xrefs = null;
            int    useLocation    = 0;
            int    newUseLocation = 0;
            string thisUse;
            string strUseClause = GetUseClause(Buffer);
            string possibleDot;

            rememberMethods = Methods;
            for (int j = nameLast; j >= nameFirst; j--)
            {
                if (Char.IsLetterOrDigit(Line[j]) || Line[j] == '.' || Line[j] == '_')
                {
                    if (!haveOne)
                    {
                        haveOne  = true;
                        nameLast = j;
                    }
                    if (Line[j] == '.')
                    {
                        noDotNameFirst = noDotNameFirst > j + 1 ? noDotNameFirst : j + 1;
                    }
                }
                else if (Char.IsControl(Line[j]) || Line[j] == ' ')
                {
                    if (haveOne)
                    {
                        nameFirst      = j + 1;
                        noDotNameFirst = noDotNameFirst > nameFirst ? noDotNameFirst : nameFirst;
                        break;
                    }
                }
                else
                {
                    nameFirst      = j + 1;
                    noDotNameFirst = noDotNameFirst > nameFirst ? noDotNameFirst : nameFirst;
                }
            }
            if (!haveOne)
            {
                return;
            }

            displayProcedureName = Line.Substring(noDotNameFirst, nameLast - noDotNameFirst + 1);
            procedureName        = displayProcedureName.ToLower();
            packageName          = Line.Substring(nameFirst, noDotNameFirst - 2 - nameFirst + 1).ToLower();

            while (newUseLocation != -1)
            {
                newUseLocation = strUseClause.IndexOf(';', useLocation);
                if (newUseLocation != -1)
                {
                    thisUse     = strUseClause.Substring(useLocation, newUseLocation - 1 - useLocation + 1);
                    useLocation = newUseLocation + 1;
                    if ((thisUse.Length == 0) && (packageName.Length == 0))
                    {
                        goto EndMainLoop;
                    }
                }
                else
                {
                    thisUse = "";
                }
                if ((thisUse.Length != 0) && (packageName.Length != 0))
                {
                    possibleDot = ".";
                }
                else
                {
                    possibleDot = "";
                }

                {
                    string filename = Dashify(thisUse + possibleDot + packageName).ToLower();
                    string fullPath = DefaultLocation.Find_File(filename, "", System.IO.Directory.GetParent(adaFileName).FullName, true);
                    string foundFilename;
                    if (fullPath.Length == 0)
                    {
                        filename = Krunch(filename);
                        fullPath = DefaultLocation.Find_File(filename, "", System.IO.Directory.GetParent(adaFileName).FullName, true);
                        if (fullPath.Length == 0)
                        {
                            goto EndMainLoop;
                        }
                    }
                    foundFilename = filename + ".ads";
                    byte[]           fullPathByte = new byte[fullPath.Length];
                    char[]           tmp          = fullPath.ToCharArray();
                    mgnat.adalib.Acc xrefs_ptr    = new mgnat.adalib.Acc();
                    for (int j = 0; j < tmp.Length; j++)
                    {
                        fullPathByte[j] = (byte)tmp[j];
                    }
                    mcc.gnat_tools.xref_pkg.read_ali(fullPathByte, 0, fullPath.Length - 1, xrefs_ptr);
                    if (xrefs_ptr.all != null)
                    {
                        xrefs        = (mcc.gnat_tools.xref.xref_file_list_package.node)xrefs_ptr.all;
                        lastInserted = "";
                        byte[] foundFilenameByte = new byte[foundFilename.Length];
                        for (int j = 0; j < foundFilename.Length; j++)
                        {
                            foundFilenameByte[j] = (byte)foundFilename[j];
                        }
                        mcc.gnat_tools.xref_pkg.enumerate_public_entities
                            (foundFilenameByte, 1, foundFilename.Length, xrefs, new mcc.gnat_tools.xref.public_callback_type(Lb_Parameter_Insert));
                        xrefs = null;
                    }
                }

EndMainLoop:
                xrefs = null;
            }
        }