Ejemplo n.º 1
0
 internal Method(FunctionProtoNode node, ParsingContext context)
 {
     ForwardNode = node;
     DefNode     = null;
     Name        = Description = Description = Type = null;
     UoTypeToken = null;
     Parameters  = null;
     Load(node, context);
 }
Ejemplo n.º 2
0
        private void Load(FunctionProtoNode node, ParsingContext context)
        {
            if (node != null)
            {
                AddReference(node.DeclNode);
            }

            Name        = string.Intern(node.Name.ValueString);
            Description = string.Empty;
            if (node.UoTypeToken != null)
            {
                if (UoTypeToken != null)
                {
                    if (UoTypeToken != node.UoTypeToken)
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, new SourceSpan(context.CurrentToken.Location, context.CurrentToken.Length), "Re-Definition of {0} does not match prior declaration return type.", Name);
                    }
                }
                else
                {
                    UoTypeToken = node.UoTypeToken;
                    Type        = node.UoTypeToken.Value;
                }
            }
            else
            {
                Type        = null;
                UoTypeToken = null;
            }
            if (node.ChildNodes[1].ChildNodes.Count > 0) // has params
            {
                IList <Parameter> OldParameters = Parameters;

                Parameters = new List <Parameter>(node.ChildNodes[1].ChildNodes.Count);
                foreach (Irony.Ast.AstNode cnode in node.ChildNodes[1].ChildNodes)
                {
                    Parameters.Add(new Parameter((DeclarationNode)cnode));
                }

                if (OldParameters != null)
                {
                    if (OldParameters.Count != Parameters.Count)
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, (DefNode ?? ForwardNode).Span, "Re-Definition of {0} does not match prior declaration parameters.", Name);
                    }
                    else
                    {
                        for (int i = 0; i < Parameters.Count; i++)
                        {
                            if (Parameters[i].UoTypeToken != OldParameters[i].UoTypeToken)
                            {
                                context.AddParserMessage(ParserErrorLevel.Error, Parameters[i].DecNode.Span, "Re-Definition of {0} does not match prior declaration parameter type for {1}.", Name, Parameters[i].Name);
                            }
                        }
                    }
                }
                else if (ForwardNode != null && DefNode != null && (Parameters != null || Parameters.Count > 0))
                {
                    context.AddParserMessage(ParserErrorLevel.Error, DefNode.Location, "Re-Definition of {0} does not match prior declaration parameters.", Name);
                }
            }
            else if (Parameters != null && Parameters.Count > 0)
            {
                context.AddParserMessage(ParserErrorLevel.Error, DefNode.Location, "Re-Definition of {0} does not match prior declaration parameters.", Name);
            }
            else
            {
                Parameters = null;
            }
        }