Esempio n. 1
0
        private static MemberDoc ParseMemberDoc(XElement m)
        {
            var newMember = new MemberDoc
            {
                Id          = m.Attribute("id").Value,
                Name        = m.Element("name").Value,
                ReturnType  = m.Element("type").Value,
                Description = m.Element("briefdescription").Value,
                MemberType  = m.Attribute("kind").Value == "function" ? MemberType.Function : MemberType.Field,
                Const       = m.Attribute("const") != null && m.Attribute("const").Value == "yes",
                Args        = new List <FunctionArg>()
            };

            if (!string.IsNullOrEmpty(newMember.Description))
            {
                newMember.Description = newMember.Description.Capitalize();
            }
            if (m.Element("type").Element("ref") != null)
            {
                newMember.ReturnTypeRefId = m.Element("type").Element("ref").Attribute("refid").Value;
            }
            var returnDesc = m.Descendants("simplesect").Where(s => s.Attribute("kind").Value == "return").SingleOrDefault();

            if (returnDesc != null)
            {
                newMember.ReturnDescription = returnDesc.Value.Capitalize();
            }

            if (newMember.MemberType == MemberType.Function)
            {
                foreach (var a in m.Elements("param"))
                {
                    if (a.Element("type").Value == "void")
                    {
                        continue;
                    }
                    var newArg = new FunctionArg()
                    {
                        Name        = a.Element("declname").Value,
                        Type        = a.Element("type").Value,
                        Description = string.Empty
                    };
                    if (a.Element("type").Element("ref") != null)
                    {
                        newArg.TypeRefId = a.Element("type").Element("ref").Attribute("refid").Value;
                    }

                    var parameterItem = m.Descendants("parameteritem").SingleOrDefault(p => p.Descendants("parametername").First().Value == newArg.Name);
                    if (parameterItem != null)
                    {
                        newArg.Description = parameterItem
                                             .Element("parameterdescription")
                                             .Element("para")
                                             .Value.Capitalize();
                    }
                    newMember.Args.Add(newArg);
                }
            }
            return(newMember);
        }
Esempio n. 2
0
        private void CheckDefinition(FunctionToken def)
        {
            if (def.Name != "Def")
            {
                throw new ParseException("Function definitions must start with a call named Def, like this: " + example)
                      {
                          FunctionToken = def
                      }
            }
            ;

            if (def.TopArguments.Length == 0)
            {
                throw new ParseException("Function definitions must have at leat one argument- the name: " + example)
                      {
                          FunctionToken = def
                      }
            }
            ;

            foreach (Argument arg in def.TopArguments.Concat(def.BottomArguments))
            {
                if (!(arg is FunctionArg))
                {
                    throw new ParseException("Incorrect formal parameter declaration {0}. All parameters must have alphabetic names and no quotes.", arg)
                          {
                              FunctionToken = def
                          }
                }
                ;
            }

            TopArguments    = def.TopArguments.Skip(1).Cast <FunctionArg>().ToArray();
            BottomArguments = def.BottomArguments.Cast <FunctionArg>().ToArray();

            string functionName = def.TopArguments[0].GetAs <string>();

            if (functionName == "...")
            {
                throw new ParseException("... cannot be the name of a function. Function names consist of letters only.")
                      {
                          FunctionToken = def
                      };
            }
            else
            {
                Name = functionName;
            }

            // if Main doesn't have any arguments
            if (Name == "Main" && TopArguments.Length == 0)
            {
                TopArguments = new FunctionArg[] { FunctionArg.TryParseArg("...") };
            }
        }
    }
}
Esempio n. 3
0
 public void CanParseFunctionsWithTypenames(string toparse, FluencyType expectedType, string expectedName)
 {
     if (Argument.TryParse(toparse, out var argument))
     {
         Assert.IsInstanceOfType(argument, typeof(FunctionArg));
         Assert.AreEqual(FluencyType.Function, argument.Type);
         Assert.AreEqual(expectedName, argument.GetAs <string>());
         FunctionArg arg = (FunctionArg)argument;
         Assert.AreEqual(expectedType, arg.DeclaredType);
     }
     else
     {
         Assert.Fail("Could not parse {0}.", toparse);
     }
 }
            /// <summary>
            /// Creates all the Function data members
            /// </summary>
            /// <param name="s"></param>
            public Function(IO.XmlStream s)
            {
                s.ReadAttribute("opcode", 16, ref Opcode);

                {
                    string temp = null;
                    s.ReadAttribute("returnType", ref temp);
                    ReturnType = ((XmlInterface)s.Owner).GetValueType(temp).Opcode;
                }

                if (!s.ReadAttributeOpt("name", ref Name))
                {
                    Name = string.Format("function_{0:X}", Opcode);
                }
                if (!s.ReadAttributeOpt("argc", 10, ref Argc))
                {
                    Argc = 0;
                }
                if (!s.ReadAttributeOpt("opArgc", 10, ref OpArgc))
                {
                    OpArgc = 0;
                }

                {
                    uint temp = 0;
                    s.ReadAttributeOpt("flags", 16, ref temp);
                    Flags = new Util.Flags(temp);
                }

                if (!s.ReadAttributeOpt <FunctionGroup>("group", ref Group))
                {
                    Group = FunctionGroup.Macro;
                }

                #region Args
                if (Argc > 0)
                {
                    int x = 0;
                    Args = new FunctionArg[Argc];
                    foreach (XmlNode n in s.Cursor.ChildNodes)
                    {
                        if (n.Name != "arg")
                        {
                            continue;
                        }

                        s.SaveCursor(n);
                        Args[x] = new FunctionArg(this, x++, s);
                        s.RestoreCursor();
                    }
                }
                else
                {
                    Args = null;
                }
                #endregion

                if (!s.ReadAttributeOpt("help", ref Help))
                {
                    Help = string.Empty;
                }
                if (!s.ReadAttributeOpt("helpArg", ref HelpArg))
                {
                    HelpArg = string.Empty;
                }

                if (!s.ReadAttributeOpt("null", ref IsNull))
                {
                    IsNull = false;
                }
            }