Beispiel #1
0
        /// <summary>
        /// Procedures
        /// </summary>
        public void Visit(ParsedProcedure pars)
        {
            // to code explorer
            var parentNode = pars.Flags.HasFlag(ParseFlag.External) ? GetExplorerListNode("External procedures", CodeExplorerIconType.ExternalProcedure) : GetExplorerListNode("Procedures", CodeExplorerIconType.Procedure);
            var newNode    = CodeItem.Factory.New(pars.Flags.HasFlag(ParseFlag.External) ? CodeExplorerIconType.ExternalProcedure : CodeExplorerIconType.Procedure);

            newNode.DisplayText   = pars.Name;
            newNode.Flags         = pars.Flags;
            newNode.SubText       = pars.Flags.HasFlag(ParseFlag.External) ? pars.ExternalDllName : null;
            newNode.DocumentOwner = pars.FilePath;
            newNode.GoToLine      = pars.Line;
            newNode.GoToColumn    = pars.Column;
            PushToCodeExplorer(parentNode, newNode);

            // to completion data
            var proc = CompletionItem.Factory.New(pars.Flags.HasFlag(ParseFlag.External) ? CompletionType.ExternalProcedure : CompletionType.Procedure);

            proc.DisplayText    = pars.Name;
            proc.ParsedBaseItem = pars;
            proc.FromParser     = true;
            proc.SubText        = pars.Flags.HasFlag(ParseFlag.External) ? pars.ExternalDllName : null;
            proc.Ranking        = AutoCompletion.FindRankingOfParsedItem(pars.Name);
            proc.Flags          = pars.Flags;
            PushToAutoCompletion(proc, pars);
        }
        private void ProcessObj(ParserRuleContext context)
        {
            ParserRuleContext child = context.GetChild(0) as ParserRuleContext;

            if (child is PlSqlParser.Procedure_bodyContext ||
                child is PlSqlParser.Procedure_specContext ||
                child is PlSqlParser.Function_bodyContext ||
                child is PlSqlParser.Function_specContext)
            {
                var procedure = _procedureVisitor.Visit(child).SetPositionExt(child);
                _Result.Objects.Add(procedure);
            }
            else if (child is PlSqlParser.Variable_declarationContext variableContext)
            {
                var name   = variableContext.GetChild(0).GetText();
                var pltype = variableContext.GetChild(1).GetText();

                if (name == "PROCEDURE")
                {
                    var procedure = new ParsedProcedure(pltype);
                    procedure.SetPosition(variableContext);
                    _Result.Objects.Add(procedure);
                }
                else
                {
                    var variable = new ParsedVariable(name, pltype);
                    variable.SetPosition(variableContext);

                    var codePosition = new PieceOfCode();
                    codePosition.SetPosition(variableContext.GetChild(0) as ParserRuleContext);
                    variable.NameIdentifierPart = codePosition;

                    _Result.Objects.Add(variable);
                }
            }
            else if (child is PlSqlParser.Type_declarationContext typeContext)
            {
                var NameContext = typeContext.GetChild(1);
                var name        = NameContext.GetText();
                var type        = new ParsedType(name);
                type.SetPosition(typeContext);
                type.NameIdentifierPart.SetPosition(NameContext as ParserRuleContext);

                _Result.Objects.Add(type);
            }
            else if (child is PlSqlParser.Cursor_declarationContext cursorContext)
            {
                var NameContext = cursorContext.GetChild(1);
                var name        = NameContext.GetText();
                var type        = new ParsedCursor(name);
                type.SetPosition(cursorContext);
                type.NameIdentifierPart.SetPosition(NameContext as ParserRuleContext);

                _Result.Objects.Add(type);
            }
        }
Beispiel #3
0
 public void Visit(ParsedProcedure pars)
 {
     AppendEverything(pars);
 }
Beispiel #4
0
        /// <summary>
        /// Matches a procedure definition
        /// </summary>
        private ParsedProcedure CreateParsedProcedure(Token procToken)
        {
            /*
             * PROCEDURE proc-name[ PRIVATE ] :
             *  [procedure-body]
             *
             * PROCEDURE proc-name
             *  {   EXTERNAL "dllname" [ CDECL | PASCAL | STDCALL ]
             *          [ ORDINAL n ][ PERSISTENT ][ THREAD-SAFE ] | IN SUPER } :
             *  [ procedure-body ]
             */

            // info we will extract from the current statement :
            string    name            = "";
            ParseFlag flags           = 0;
            string    externalDllName = null;

            _lastTokenWasSpace = true;
            StringBuilder leftStr = new StringBuilder();

            Token token;
            int   state = 0;

            do
            {
                token = PeekAt(1); // next token
                if (token is TokenEos)
                {
                    break;
                }
                if (token is TokenComment)
                {
                    continue;
                }
                switch (state)
                {
                case 0:
                    // matching name
                    if (token is TokenWord || token is TokenString)
                    {
                        name = token is TokenWord ? token.Value : GetTokenStrippedValue(token);
                        state++;
                    }
                    continue;

                case 1:
                    // matching external
                    if (!(token is TokenWord))
                    {
                        continue;
                    }
                    switch (token.Value.ToLower())
                    {
                    case "external":
                        flags |= ParseFlag.External;
                        state++;
                        break;

                    case "private":
                        flags |= ParseFlag.Private;
                        break;
                    }
                    break;

                case 2:
                    // matching the name of the external dll
                    if (!(token is TokenString))
                    {
                        continue;
                    }
                    externalDllName = GetTokenStrippedValue(token);
                    state--;
                    break;
                }
                AddTokenToStringBuilder(leftStr, token);
            } while (MoveNext());

            if (state < 1)
            {
                return(null);
            }

            var newProc = new ParsedProcedure(name, procToken, leftStr.ToString(), externalDllName)
            {
                // = end position of the EOS of the statement
                EndPosition = token.EndPosition,
                Flags       = flags
            };

            AddParsedItem(newProc, procToken.OwnerNumber);

            return(newProc);
        }