Exemple #1
0
        public void TestUnapplication()
        {
            var names = new List <string> {
                "a"
            };
            var functions      = new List <FunctionDeclaration>();
            var unapplications = new List <UnApplication>();

            foreach (var id in names)
            {
                var unapplication = new UnApplication(
                    new Range(new StringLocation(0), new StringLocation(1)),
                    "a");
                var body = new InstructionBlock(
                    new Range(new StringLocation(0), new StringLocation(1)),
                    new List <Expression> {
                    unapplication
                });
                var fun = new FunctionDeclaration(
                    new Range(new StringLocation(0), new StringLocation(1)),
                    id,
                    UnitType.Instance,
                    new List <VariableDeclaration>(),
                    body,
                    false);
                unapplications.Add(unapplication);
                functions.Add(fun);
            }

            var root = new Program(
                new Range(new StringLocation(0), new StringLocation(1)),
                new List <StructDeclaration>(),
                functions);
            var resolver = new NameResolver();

            resolver.Run(root, null);
            var aDeclaration = functions[0];
            var expected     = new List <FunctionDeclaration> {
                aDeclaration
            };

            CollectionAssert.AreEqual(expected, unapplications[0].Candidates.ToList());
        }
Exemple #2
0
            private void ProcessUnApplication(UnApplication unapplication, IDiagnostics diagnostics)
            {
                var identifier = unapplication.FunctionName;

                if (!this.functions.ContainsKey(identifier) || this.functions[identifier].Count == 0)
                {
                    var message    = $"No function of name '{identifier}'";
                    var diagnostic = new Diagnostic(
                        DiagnosticStatus.Error,
                        IdentifierNotFoundDiagnostic,
                        message,
                        new List <Range> {
                        unapplication.InputRange
                    });
                    diagnostics.Add(diagnostic);
                    this.exceptions.Add(new NameResolverInternalException(message));
                }
                else
                {
                    unapplication.Candidates = this.GetDeclarationCandidates(identifier);
                }
            }