Function parsed item
Inheritance: ParsedFunction
Esempio n. 1
0
        public void Visit(ParsedPrototype pars)
        {
            // only visit IN prototypes
            if (pars.SimpleForward)
            {
                return;
            }

            // to code explorer
            _parsedExplorerItemsList.Add(new CodeExplorerItem {
                DisplayText   = pars.Name,
                Branch        = CodeExplorerBranch.Function,
                Flag          = AddExternalFlag(pars.IsPrivate ? CodeExplorerFlag.Private : 0),
                DocumentOwner = pars.FilePath,
                GoToLine      = pars.Line,
                GoToColumn    = pars.Column,
                SubString     = SetExternalInclude(null)
            });

            // to completion data
            pars.ReturnType = ConvertStringToParsedPrimitiveType(pars.ParsedReturnType, false);
            _parsedCompletionItemsList.Add(new CompletionItem {
                DisplayText = pars.Name,
                Type        = CompletionType.Function,
                SubString   = pars.ReturnType.ToString(),
                Flag        = AddExternalFlag((pars.IsPrivate ? ParseFlag.Private : 0) | (pars.IsExtended ? ParseFlag.Extent : 0)),
                Ranking     = AutoComplete.FindRankingOfParsedItem(pars.Name),
                ParsedItem  = pars,
                FromParser  = true
            });
        }
Esempio n. 2
0
        public void Visit(ParsedPrototype pars)
        {
            // only visit IN prototypes
            if (pars.SimpleForward)
            {
                return;
            }

            // to code explorer
            PushToCodeExplorer(
                GetExplorerListNode("Function prototypes", CodeExplorerIconType.Prototype),
                new PrototypeCodeItem {
                DisplayText   = pars.Name,
                Flags         = pars.Flags,
                SubText       = null,
                DocumentOwner = pars.FilePath,
                GoToLine      = pars.Line,
                GoToColumn    = pars.Column
            });

            // to completion data
            PushToAutoCompletion(new FunctionCompletionItem {
                DisplayText = pars.Name,
                Flags       = pars.Flags,
                SubText     = pars.ReturnType.ToString()
            }, pars);
        }
Esempio n. 3
0
        /// <summary>
        /// Matches a function definition (not the FORWARD prototype)
        /// </summary>
        private bool CreateParsedFunction(Token functionToken)
        {
            // info we will extract from the current statement :
            string name = null;
            string returnType = null;
            string extend = null;
            bool isExtent = false;
            _lastTokenWasSpace = true;
            StringBuilder parameters = new StringBuilder();
            bool isPrivate = false;
            var parametersList = new List<ParsedItem>();

            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)) break;
                        name = token.Value;
                        state++;
                        break;
                    case 1:
                        // matching return type
                        if (!(token is TokenWord)) break;
                        if (token.Value.EqualsCi("returns") || token.Value.EqualsCi("class"))
                            continue;

                        returnType = token.Value;

                        state++;
                        break;
                    case 2:
                        // matching parameters (start)
                        if (token is TokenWord) {
                            if (token.Value.EqualsCi("private"))
                                isPrivate = true;
                            if (token.Value.EqualsCi("extent"))
                                isExtent = true;

                            // we didn't match any opening (, but we found a forward
                            if (token.Value.EqualsCi("forward"))
                                state = 99;
                            else if (token.Value.EqualsCi("in"))
                                state = 100;

                        } else if (token is TokenSymbol && token.Value.Equals("("))
                            state = 3;
                        else if (isExtent && token is TokenNumber)
                            extend = token.Value;
                        break;
                    case 3:
                        // read parameters, define a ParsedDefineItem for each
                        parametersList = GetParsedParameters(functionToken, parameters);
                        state = 10;
                        break;
                    case 10:
                        // matching prototype, we dont want to create a ParsedItem for prototype
                        if (token is TokenWord) {
                            if (token.Value.EqualsCi("forward"))
                                state = 99;
                            else if (token.Value.EqualsCi("in"))
                                state = 100;
                        }
                        break;
                }
            } while (MoveNext());
            if (name == null || returnType == null)
                return false;

            // otherwise it needs to ends with : or .
            if (!(token is TokenEos))
                return false;

            // New prototype, we matched a forward or a IN
            if (state >= 99) {

                ParsedPrototype createdProto = new ParsedPrototype(name, functionToken, returnType) {
                    Scope = _context.Scope,
                    FilePath = _filePathBeingParsed,
                    SimpleForward = state == 99, // allows us to know if we expect an implementation in this .p or not
                    EndPosition = token.EndPosition,
                    EndBlockLine = token.Line,
                    EndBlockPosition = token.EndPosition,
                    IsPrivate = isPrivate,
                    IsExtended = isExtent,
                    Extend = extend ?? string.Empty,
                    Parameters = parameters.ToString()
                };
                if (!_functionPrototype.ContainsKey(name))
                    _functionPrototype.Add(name, createdProto);

                // case of a IN, we add it to the list of item
                if (!createdProto.SimpleForward) {

                    AddParsedItem(createdProto);

                    // modify context
                    _context.Scope = createdProto;

                    // add the parameters to the list
                    if (parametersList.Count > 0) {
                        foreach (var parsedItem in parametersList) {
                            AddParsedItem(parsedItem);
                        }
                    }

                    // reset context
                    _context.Scope = _rootScope;
                }

                return false;

            }

            // New function
            ParsedImplementation createdImp = new ParsedImplementation(name, functionToken, returnType) {
                EndPosition = token.EndPosition,
                IsPrivate = isPrivate,
                IsExtended = isExtent,
                Extend = extend ?? string.Empty,
                Parameters = parameters.ToString()
            };

            // it has a prototype?
            if (_functionPrototype.ContainsKey(name)) {
                // make sure it was a prototype!
                var proto = _functionPrototype[name] as ParsedPrototype;
                if (proto != null && proto.SimpleForward) {

                    createdImp.HasPrototype = true;
                    createdImp.PrototypeLine = proto.Line;
                    createdImp.PrototypeColumn = proto.Column;
                    createdImp.PrototypePosition = proto.Position;
                    createdImp.PrototypeEndPosition = proto.EndPosition;

                    // boolean to know if the implementation matches the prototype
                    createdImp.PrototypeUpdated = (
                        createdImp.IsExtended == proto.IsExtended &&
                        createdImp.IsPrivate == proto.IsPrivate &&
                        createdImp.Extend.Equals(proto.Extend) &&
                        createdImp.ParsedReturnType.Equals(proto.ParsedReturnType) &&
                        createdImp.Parameters.Equals(proto.Parameters));
                }
            } else {
                _functionPrototype.Add(name, createdImp);
            }

            AddParsedItem(createdImp);

            // modify context
            _context.Scope = createdImp;

            // add the parameters to the list
            if (parametersList.Count > 0) {
                foreach (var parsedItem in parametersList) {
                    AddParsedItem(parsedItem);
                }
            }

            return true;
        }