public void Visit(ConstStatement node)
 {
     if (node != null)
     {
         DoesRequire = true;
     }
 }
Example #2
0
 public virtual void Visit(ConstStatement node)
 {
     if (node != null)
     {
         foreach (var childNode in node.Children)
         {
             childNode.Accept(this);
         }
     }
 }
Example #3
0
        private Executable ParseConst(TokenStream tokens, Executable owner)
        {
            Token          constToken     = tokens.PopExpected(this.parser.Keywords.CONST);
            Token          nameToken      = tokens.Pop();
            ConstStatement constStatement = new ConstStatement(constToken, nameToken, parser.CurrentNamespace, owner);

            this.parser.VerifyIdentifier(nameToken);
            tokens.PopExpected("=");
            constStatement.Expression = this.parser.ExpressionParser.Parse(tokens, constStatement);
            tokens.PopExpected(";");

            return(constStatement);
        }
 public virtual void Visit(ConstStatement node)
 {
     if (node != null)
     {
         foreach (var declaration in node.Children)
         {
             if (declaration != null)
             {
                 declaration.Accept(this);
             }
         }
     }
 }
Example #5
0
        private ConstStatement ParseConst(TokenStream tokens, TopLevelConstruct owner, FileScope fileScope)
        {
            Token          constToken     = tokens.PopExpected(this.parser.Keywords.CONST);
            Token          nameToken      = tokens.Pop();
            ConstStatement constStatement = new ConstStatement(constToken, nameToken, parser.CurrentNamespace, owner, parser.CurrentLibrary, fileScope);

            this.parser.VerifyIdentifier(nameToken);
            tokens.PopExpected("=");
            constStatement.Expression = this.parser.ExpressionParser.Parse(tokens, constStatement);
            tokens.PopExpected(";");

            return(constStatement);
        }
Example #6
0
 public void Visit(ConstStatement node)
 {
     // invalid! ignore
     IsValid = false;
 }
Example #7
0
 public void Visit(ConstStatement node)
 {
     // starts with a 'const', so we don't care
 }
Example #8
0
 public void VisitConstStatement(ConstStatement constStatement)
 {
     VisitVariableStatement(constStatement);
 }
Example #9
0
 public virtual void PostWalk(ConstStatement node)
 {
 }
Example #10
0
 public void Visit(ConstStatement node)
 {
     // add the names for each vardecl in the statement
     node.IfNotNull(n => n.Children.ForEach(v => v.Accept(this)));
 }
Example #11
0
        private Dictionary <string, Executable> CreateFullyQualifiedLookup(IList <Executable> code)
        {
            HashSet <string> namespaces = new HashSet <string>();

            Dictionary <string, Executable> lookup = new Dictionary <string, Executable>();
            bool mainFound = false;

            foreach (Executable item in code)
            {
                string ns;
                string memberName;
                if (item is FunctionDefinition)
                {
                    FunctionDefinition fd = (FunctionDefinition)item;
                    ns         = fd.Namespace;
                    memberName = fd.NameToken.Value;
                    if (memberName == "main")
                    {
                        if (mainFound)
                        {
                            throw new ParserException(item.FirstToken, "Multiple main methods found.");
                        }
                        mainFound   = true;
                        lookup["~"] = item;
                    }
                }
                else if (item is ClassDefinition)
                {
                    ClassDefinition cd = (ClassDefinition)item;
                    ns         = cd.Namespace;
                    memberName = cd.NameToken.Value;

                    // TODO: nested classes, constants, and enums.
                }
                else if (item is EnumDefinition)
                {
                    EnumDefinition ed = (EnumDefinition)item;
                    ns         = ed.Namespace;
                    memberName = ed.Name;
                }
                else if (item is ConstStatement)
                {
                    ConstStatement cs = (ConstStatement)item;
                    ns         = cs.Namespace;
                    memberName = cs.Name;
                }
                else
                {
                    string error = "This sort of expression cannot exist outside of function or field definitions.";
                    if (item is Assignment)
                    {
                        error += " Did you mean to mark this as a const expression?";
                    }
                    throw new ParserException(item.FirstToken, error);
                }

                if (ns.Length > 0)
                {
                    string accumulator = "";
                    foreach (string nsPart in ns.Split('.'))
                    {
                        if (accumulator.Length > 0)
                        {
                            accumulator += ".";
                        }
                        accumulator += nsPart;
                        namespaces.Add(accumulator);
                    }
                }

                string fullyQualifiedName = (ns.Length > 0 ? (ns + ".") : "") + memberName;

                lookup[fullyQualifiedName] = item;
            }

            foreach (string key in lookup.Keys)
            {
                if (namespaces.Contains(key))
                {
                    throw new ParserException(lookup[key].FirstToken, "This name collides with a namespace definition.");
                }
            }

            // Go through and fill in all the partially qualified namespace names.
            foreach (string ns in namespaces)
            {
                lookup[ns] = new Namespace(null, ns, null);
            }

            if (lookup.ContainsKey("~"))
            {
                FunctionDefinition mainFunc = (FunctionDefinition)lookup["~"];
                if (mainFunc.ArgNames.Length > 1)
                {
                    throw new ParserException(mainFunc.FirstToken, "The main function must accept 0 or 1 arguments.");
                }
            }
            else
            {
                throw new Exception("No main(args) function was defined.");
            }

            return(lookup);
        }
Example #12
0
 public override bool Walk(ConstStatement node)
 {
     AddNode(node); return(true);
 }
Example #13
0
 public void Visit(ConstStatement node)
 {
     Debug.Fail("shouldn't get here");
 }
Example #14
0
 public virtual bool Walk(ConstStatement node)
 {
     return(true);
 }
Example #15
0
 public virtual void PostWalk(ConstStatement node) { }
Example #16
0
 public virtual bool Walk(ConstStatement node) { return true; }
Example #17
0
        private Dictionary <string, TopLevelConstruct> CreateFullyQualifiedLookup(IList <TopLevelConstruct> code)
        {
            using (new PerformanceSection(""))
            {
                HashSet <string> namespaces = new HashSet <string>();

                Dictionary <string, TopLevelConstruct> lookup = new Dictionary <string, TopLevelConstruct>();
                bool mainFound = false;
                foreach (TopLevelConstruct item in code)
                {
                    string ns;
                    string memberName;
                    if (item is FunctionDefinition)
                    {
                        FunctionDefinition fd = (FunctionDefinition)item;
                        ns         = fd.Namespace;
                        memberName = fd.NameToken.Value;
                        if (memberName == "main")
                        {
                            if (mainFound)
                            {
                                throw new ParserException(item.FirstToken, "Multiple main methods found.");
                            }
                            mainFound   = true;
                            lookup["~"] = item;
                        }
                    }
                    else if (item is ClassDefinition)
                    {
                        ClassDefinition cd = (ClassDefinition)item;
                        ns         = cd.Namespace;
                        memberName = cd.NameToken.Value;

                        // TODO: nested classes, constants, and enums.
                    }
                    else if (item is EnumDefinition)
                    {
                        EnumDefinition ed = (EnumDefinition)item;
                        ns         = ed.Namespace;
                        memberName = ed.Name;
                    }
                    else if (item is ConstStatement)
                    {
                        ConstStatement cs = (ConstStatement)item;
                        ns         = cs.Namespace;
                        memberName = cs.Name;
                    }
                    else
                    {
                        string error = "This sort of expression cannot exist outside of function or field definitions.";
                        throw new ParserException(item.FirstToken, error);
                    }

                    if (ns.Length > 0)
                    {
                        string accumulator = "";
                        foreach (string nsPart in ns.Split('.'))
                        {
                            if (accumulator.Length > 0)
                            {
                                accumulator += ".";
                            }
                            accumulator += nsPart;
                            namespaces.Add(accumulator);
                        }
                    }

                    string fullyQualifiedName = (ns.Length > 0 ? (ns + ".") : "") + memberName;

                    if (lookup.ContainsKey(fullyQualifiedName))
                    {
                        // TODO: token information from two locations
                        throw new ParserException(item.FirstToken, "Two items have identical fully-qualified names: '" + fullyQualifiedName + "'");
                    }
                    lookup[fullyQualifiedName] = item;
                }

                foreach (string key in lookup.Keys)
                {
                    if (namespaces.Contains(key))
                    {
                        throw new ParserException(lookup[key].FirstToken, "This name collides with a namespace definition.");
                    }
                }

                // Go through and fill in all the partially qualified namespace names.
                foreach (string ns in namespaces)
                {
                    Namespace nsInstance          = new Namespace(null, ns, null, null, null);
                    string    possibleLibraryName = ns.Split('.')[0];

                    TODO.EnglishLocaleAssumed();
                    Library library = this.parser.LibraryManager.GetLibraryFromName(possibleLibraryName);
                    if (library != null)
                    {
                        // TODO: once you get rid of this line, make the Library setter protected
                        nsInstance.Library = library;
                    }
                    lookup[ns] = nsInstance;
                }

                if (lookup.ContainsKey("~"))
                {
                    FunctionDefinition mainFunc = (FunctionDefinition)lookup["~"];
                    if (mainFunc.ArgNames.Length > 1)
                    {
                        throw new ParserException(mainFunc.FirstToken, "The main function must accept 0 or 1 arguments.");
                    }
                }
                else
                {
                    throw new InvalidOperationException("No main(args) function was defined.");
                }

                return(lookup);
            }
        }
Example #18
0
 public void Visit(ConstStatement node)
 {
     // not applicable; terminate
 }
Example #19
0
 public virtual void Visit(ConstStatement node)
 {
     if (node != null)
     {
         foreach (var childNode in node.Children)
         {
             childNode.Accept(this);
         }
     }
 }