Beispiel #1
0
        protected override void VisitVariable(VariableNode nodes)
        {
            IScope scope = nodes.FindFirstScope();

            TypeInformation[] decl = scope.FindSymbol(nodes.Name);
            if (decl == null || decl.Length == 0)
            {
                //TODO: Edit lenght on everything...
                _messages.Add(CompilationMessage.Create(_data.TokenStream, nodes.Interval, MessageCode.NoSuchSymbol,
                                                        _data.Filename, null));
            }
            else if (decl.Length == 1)
            {
                //TODO: If TypeInformation needs a ScopeType that contains MethodLine and ClassLike. Supress for classLike
                if (decl[0].DeclarationLocation > nodes.Interval.a &&
                    decl[0].DeclaringScope == DeclaringScope.MethodLike)
                {
                    //TODO: Make CompilationMessage.Create take an IntervalSet of intresting locations instead of one location...
                    _messages.Add(CompilationMessage.Create(_data.TokenStream, nodes.Interval,
                                                            MessageCode.UseBeforeDecleration, _data.Filename, null));
                }
            }
            else //if(decl.Length > 1)
            {
                _messages.Add(CompilationMessage.Create(_data.TokenStream, nodes.Interval,
                                                        MessageCode.InternalCompilerError, _data.Filename, "Not allowed due technical (lazy) reasons",
                                                        MessageSeverity.Fatal));
            }



            base.VisitVariable(nodes);
        }
        public void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
        {
            AnyErrors = true;
            CrawlParser parser = (CrawlParser)recognizer;

            IntervalSet set = parser.GetExpectedTokens();

            string help =
                $"Symbolet {CrawlLexer.ruleNames[offendingSymbol.Type]} er ikke tilladt på dette punkt. En af de følgende var forventet:\n\t" +
                string.Join("\n\t", set.ToArray().Select(x => parser.Vocabulary.GetDisplayName(x)));

            int intrestinglocation = offendingSymbol.TokenIndex;

            //for (int i = intrestinglocation; i < offendingSymbol.TokenIndex + 20; i++)
            //{
            //    if (parser.TokenStream.Get(i).Channel == Lexer.DefaultTokenChannel)
            //    {
            //        intrestinglocation = i;
            //        break;
            //    }
            //}


            Errors.Add(CompilationMessage.Create(
                           parser.TokenStream,
                           Interval.Of(intrestinglocation, intrestinglocation),
                           MessageCode.UnexpectedSymbol,
                           $"{_file}:{line},{charPositionInLine}",
                           help,
                           MessageSeverity.Error));
        }
        protected override CrawlSyntaxNode VisitType(TypeNode type)
        {
            IScope scope = type.FindFirstScope();

            try
            {
                CrawlType actualType = CrawlType.ParseDecleration(scope, type.TypeName);

                var v = type.WithActualType(actualType);
                return(v);
            }
            catch (TypeNotFoundException tnfe)
            {
                _messages.Add(CompilationMessage.Create(_tokens, type.Interval, MessageCode.TypeNotFound, _file));
                return(type);
            }
        }
            public AstData AddExport(AstData arg, SideeffectHelper helper)
            {
                var tu = ((TranslationUnitNode)arg.Tree.RootNode);

                try
                {
                    return(new AstData(
                               arg.TokenStream,
                               arg.Filename,
                               tu
                               .WithImportedNamespaces(
                                   Namespace.Merge(tu.Imports.Select(TryGetNamespace).ToArray())
                                   )
                               .OwningTree
                               ));
                }
                catch (NamespaceNotFoundException nsnfe)
                {
                    throw helper.FailWith(CompilationMessage.Create(arg.TokenStream, nsnfe.FaultyNode.Interval,
                                                                    MessageCode.NamespaceNotFound, arg.Filename));
                }
            }
Beispiel #5
0
        void CheckHides(CrawlSyntaxNode aScope)
        {
            //TODO: This should be optimized by adding and removing from mapping with a stack
            //Would go from O(n^2) -> O(1)
            //This checks if something gets redefined.
            Dictionary <string, CrawlSyntaxNode> mapping = new Dictionary <string, CrawlSyntaxNode>();

            while (aScope != null)
            {
                IScope scope = aScope as IScope;
                if (scope != null)
                {
                    var local = scope.LocalSymbols();

                    //TODO: REMOVE. Just to stop it crashing
                    if (local == null)
                    {
                        local = new List <string>();
                    }

                    foreach (string symbol in local)
                    {
                        if (mapping.ContainsKey(symbol))
                        {
                            Interval first = mapping[symbol].Interval;
                            _messages.Add(CompilationMessage.Create(_data.TokenStream, first,
                                                                    MessageCode.HidesOtherSymbol, _data.Filename,
                                                                    $"Unable to declare {symbol} as it hides {symbol} from {aScope}"));
                        }
                        else
                        {
                            mapping.Add(symbol, aScope);
                        }
                    }
                }

                aScope = aScope.Parent;
            }
        }