Ejemplo n.º 1
0
        public static void AddStatementList(ScopedNode aststatementsroot, ParseTreeNode parsestatementsroot, ParsingContext context, bool adderrors = true)
        {
            foreach (ParseTreeNode node in parsestatementsroot.ChildNodes)
            {
                ParseTreeNode cnode = null;

                if (node.AstNode is DeclarationNode) // member
                {
                    cnode = node;
                }
                else if (node.ChildNodes.Count > 0)
                {
                    if (node.FirstChild.AstNode is DeclarationNode)
                    {
                        cnode = node.FirstChild;
                    }
                    else if (node.FirstChild.ChildNodes.Count > 0 && node.FirstChild.FirstChild.AstNode is DeclarationNode)
                    {
                        cnode = node.FirstChild.FirstChild;
                    }
                }

                if (cnode != null)
                {
                    if (cnode.AstNode is MemberDeclarationNode)
                    {
                        UOSLBase.AddMember(new Field((MemberDeclarationNode)cnode.AstNode, context), context);
                    }
                    //else if this is a regular variable declaration within a function, the function will add the var to scope when the function node is created
                }

                ScopedNode newnode = GetStatement(node, context, adderrors);
                if (newnode != null)
                {
                    aststatementsroot.ChildNodes.Add(newnode);
                    newnode.Parent = aststatementsroot;
                }
            }
        }
Ejemplo n.º 2
0
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            LanguageOption Options = context.GetOptions();

            field = new Field(this, context, true);
            if (!Options.HasOption(LanguageOption.Constants))
            {
                context.AddParserMessage(ParserErrorLevel.Error, this.Span, "Constants are not valid for this source.");
            }
            else if (Assign == null || Assign.Expression.UoToken == null || !Assign.Expression.UoToken.IsLiteral)
            {
                if (Assign != null && Assign.Expression.AsString == "ExpressionList")
                {
                    foreach (ExpressionNode node in Assign.Expression.ChildNodes)
                    {
                        if (node.UoToken == null || !node.UoToken.IsLiteral)
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, node.Span, "Constant list elements must be compile time constants.");
                        }
                    }

                    field.Value = Assign.Expression.ChildNodes.Select(node => new ConstantListElement(((ExpressionNode)node).UoToken, ((ExpressionNode)node).UoTypeToken));
                }
                else
                {
                    context.AddParserMessage(ParserErrorLevel.Error, Span, "Constants must be assigned a compile time constant value when declared.");
                    field.Value = "0";
                }
            }
            else
            {
                field.Value = Assign.Expression.UoToken.Value;
            }

            UOSLBase.AddMember(field, context);
        }
Ejemplo n.º 3
0
        public override void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            base.Init(context, parseNode);

            List <Method> ScopeFuncs = UOSLBase.GetFuncs(context);

            CoreCommands.LoadCoreCommands(context);

            LanguageOption Options = context.GetOptions();

            bool canLoadInherit = true;

            foreach (ParseTreeNode cnode in parseNode.ChildNodes)
            {
                ScopedNode toAdd = null;

                if (cnode.AstNode is InheritsNode)
                {
                    if (canLoadInherit)
                    {
                        toAdd = (ScopedNode)cnode.AstNode;
                        InheritsNode iNode = (InheritsNode)cnode.AstNode;
                        if (Depends.ContainsKey(iNode.Filename))
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, cnode.Span, "File {0} is already loaded in this inheritance chain, cannot reload.", iNode.Filename);
                        }
                        else
                        {
                            m_grammar.LoadFile(iNode.Filename, this, context, Depends);
                        }
                    }
                    else
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, cnode.Span, "Inherits declaration(s) must appear first in the file, may not be made after other declarations.");
                    }
                }
                else
                {
                    canLoadInherit = false;

                    if (cnode.AstNode is EventDefNode)
                    {
                        toAdd = (EventDefNode)cnode.AstNode;
                    }
                    else if (cnode.AstNode is UoCoreFunctionNode)
                    {
                        CoreCommands.Funcs.Add(new Method((FunctionProtoNode)cnode.AstNode, context));
                    }
                    else if (cnode.AstNode is FunctionDefNode)
                    {
                        toAdd = (FunctionDefNode)cnode.AstNode;

                        Method found;
                        string name = ((FunctionDefNode)toAdd).NameString;

                        if (ScopeFuncs != null && (found = ScopeFuncs.FirstOrDefault(func => func.Name == name)) != null && found.DefNode == null)
                        {
                            found.Define((FunctionDefNode)toAdd, context);
                        }
                        else
                        {
                            UOSLBase.AddFunc(new Method((FunctionDefNode)toAdd, context), context);
                        }
                    }
                    else if (cnode.AstNode is FunctionProtoNode)
                    {
                        toAdd = (FunctionProtoNode)cnode.AstNode;
                        UOSLBase.AddFunc(new Method((FunctionProtoNode)toAdd, context), context);
                    }
                    else if (cnode.AstNode is ConstantDeclarationNode)
                    {
                        ConstantDeclarationNode constnode = (ConstantDeclarationNode)cnode.AstNode;
                        toAdd = constnode;
                    }
                    else if (cnode.AstNode is MemberDeclarationNode)
                    {
                        toAdd = (ScopedNode)cnode.AstNode;
                        if (((MemberDeclarationNode)cnode.AstNode).Assign != null)
                        {
                            context.AddParserMessage(ParserErrorLevel.Warning, ((MemberDeclarationNode)cnode.AstNode).Assign.Span, "Member assignments in Declarations are not respected.", ((MemberDeclarationNode)cnode.AstNode).Declaration.Term.Name);
                        }
                        UOSLBase.AddMember(new Field((MemberDeclarationNode)cnode.AstNode, context), context); // global scope?
                    }
                    else if (cnode.AstNode is DeclarationNode)
                    {
                        toAdd = (DeclarationNode)cnode.AstNode;
                        AddVar(new Field((DeclarationNode)toAdd, context), context);
                    }
                }

                if (toAdd != null)
                {
                    ChildNodes.Add(toAdd);
                    toAdd.Parent = this;
                }
            }
        }