Beispiel #1
0
        public static string GenerateMetaComponentJson(string cppContent, out string status)
        {
            MetaComponent meta = GenerateMetaComponent(cppContent, out status);

            return(meta == null ? null : Newtonsoft.Json.JsonConvert.SerializeObject(meta, Newtonsoft.Json.Formatting.Indented));
        }
Beispiel #2
0
        private static MetaComponent SearchDownForMetaComponent(ParseNode node)
        {
            if (node == null)
            {
                return(null);
            }

            MetaComponent meta;

            if (node.RuleName == RULE_NAME_CLASS_DECL && node.Count >= 2 && node[0].RuleName == RULE_NAME_CLASS)
            {
                ParseNode className = SearchDownFor(node[1], RULE_NAME_IDENTIFIER);
                if (className != null)
                {
                    ParseNode parent = SearchUpForDeclarationContent(node);
                    if (parent != null)
                    {
                        int i = 0;
                        while (i < parent.Count && !HasRuleWithValue(parent[i], RULE_NAME_IDENTIFIER, META_COMPONENT))
                        {
                            ++i;
                        }
                        ++i;
                        if (i < parent.Count)
                        {
                            meta = new MetaComponent(className.Value);
                            Dictionary <string, string> attr = SearchDownForAttributes(parent[i]);
                            if (attr != null)
                            {
                                foreach (string key in attr.Keys)
                                {
                                    if (key == META_ATTR_NAME)
                                    {
                                        meta.Name = attr[key];
                                    }
                                    else if (key == META_ATTR_DESCRIPTION)
                                    {
                                        meta.Description = attr[key];
                                    }
                                    else if (key == META_ATTR_FUNCTIONALITY_TRIGGERS)
                                    {
                                        string[] triggers = string.IsNullOrEmpty(attr[key]) ? null : attr[key].Split('|');
                                        if (triggers != null && triggers.Length > 0)
                                        {
                                            meta.FunctionalityTriggers.AddRange(triggers);
                                        }
                                    }
                                }
                            }
                            meta.Properties = SearchDownForProperties(parent);
                            i += 2;
                            if (i < parent.Count - 1 && HasRuleWithValue(parent[i], RULE_NAME_UNNAMED, ":", RULE_TYPE_CHARSET))
                            {
                                List <string> baseClasses = new List <string>();
                                ParseNode     fragment;
                                while (i + 1 < parent.Count - 1)
                                {
                                    ++i;
                                    fragment = SearchDownFor(parent[i], RULE_NAME_IDENTIFIER);
                                    if (fragment != null &&
                                        fragment.Value != "public" &&
                                        fragment.Value != "private" &&
                                        fragment.Value != "protected" &&
                                        fragment.Value != "virtual"
                                        )
                                    {
                                        baseClasses.Add(fragment.Value);
                                    }
                                }
                                meta.BaseClasses = baseClasses;
                            }
                            return(meta);
                        }
                    }
                }
            }

            foreach (ParseNode child in node)
            {
                meta = SearchDownForMetaComponent(child);
                if (meta != null)
                {
                    return(meta);
                }
            }

            return(null);
        }