Esempio n. 1
0
        /// <summary>
        /// Parses the given <paramref name="aliasElement"/> and creates an ImportStatement or AliasStatement from it.
        /// </summary>
        /// <param name="aliasElement">The alias element to parse.</param>
        /// <param name="context">The parser context to use.</param>
        /// <returns>An ImportStatement if the element is an import, or an AliasStatement if it is an alias.</returns>
        protected override Statement ParseAliasElement(XElement aliasElement, ParserContext context)
        {
            if (aliasElement == null)
            {
                throw new ArgumentNullException("aliasElement");
            }
            if (aliasElement.Name != AliasElementName)
            {
                throw new ArgumentException(string.Format("Must be a SRC.{0} element", AliasElementName.LocalName), "aliasElement");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var isNamespaceImport = aliasElement.Descendants(SRC.Name).Any(n => n.Value.Contains("*"));
            //Elements("name").Any(n => n.Value.Contains("*")); //).Any(n => n.Value.Contains("*"));

            Statement stmt = null;

            if (isNamespaceImport)
            {
                //namespace import
                var import = new ImportStatement()
                {
                    ProgrammingLanguage = ParserLanguage
                };
                import.AddLocation(context.CreateLocation(aliasElement));
                var nameElement = aliasElement.Element(SRC.Name);
                if (nameElement != null)
                {
                    //we have an import that ends with .*. We remove the . and *.
                    nameElement.LastNode.Remove(); //remove *
                    nameElement.LastNode.Remove(); //remove .
                    import.ImportedNamespace = ParseNameUseElement <NamespaceUse>(nameElement, context);
                    //TODO: fix to handle the trailing operator tag
                }
                stmt = import;
            }
            else
            {
                //importing a single member, i.e. an alias
                var alias = new AliasStatement()
                {
                    ProgrammingLanguage = ParserLanguage
                };
                alias.AddLocation(context.CreateLocation(aliasElement));
                var nameElement = aliasElement.Element(SRC.Name);
                if (nameElement != null)
                {
                    alias.Target    = ParseExpression(nameElement, context);
                    alias.AliasName = NameHelper.GetLastName(nameElement);
                }
                stmt = alias;
            }

            return(stmt);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the name for a method. This is the unqualified name, not any class names that might
        /// be prepended to it.
        /// </summary>
        /// <param name="methodElement">The method typeUseElement</param>
        /// <returns>a string with the method name</returns>
        protected override string GetNameForMethod(XElement methodElement)
        {
            var nameElement = methodElement.Element(SRC.Name);

            if (null == nameElement)
            {
                return(string.Empty);
            }
            return(NameHelper.GetLastName(nameElement));
        }
Esempio n. 3
0
        /// <summary>
        /// Parses the given <paramref name="aliasElement"/> and creates an ImportStatement or AliasStatement from it.
        /// </summary>
        /// <param name="aliasElement">The alias element to parse.</param>
        /// <param name="context">The parser context to use.</param>
        /// <returns>An ImportStatement if the element is an import, or an AliasStatement if it is an alias.</returns>
        protected override Statement ParseAliasElement(XElement aliasElement, ParserContext context)
        {
            if (null == aliasElement)
            {
                throw new ArgumentNullException("aliasElement");
            }
            if (aliasElement.Name != AliasElementName)
            {
                throw new ArgumentException(string.Format("Must be a SRC.{0} element", AliasElementName.LocalName), "aliasElement");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Statement stmt             = null;
            var       namespaceElement = aliasElement.Element(SRC.Namespace);

            if (namespaceElement != null)
            {
                //import statement
                var import = new ImportStatement()
                {
                    ProgrammingLanguage = ParserLanguage
                };
                import.AddLocation(context.CreateLocation(aliasElement));

                var nameElement = namespaceElement.Element(SRC.Name);
                if (nameElement != null)
                {
                    import.ImportedNamespace = ParseNameUseElement <NamespaceUse>(nameElement, context);
                }

                stmt = import;
            }
            else
            {
                //alias statement
                var alias = new AliasStatement()
                {
                    ProgrammingLanguage = ParserLanguage
                };
                alias.AddLocation(context.CreateLocation(aliasElement));

                //TODO: Make sure that using descendant is correct for nameElement
                var nameElement = aliasElement.Element(SRC.Name);
                var initElement = aliasElement.Element(SRC.Init);
                if (initElement != null)
                {
                    //example: using foo = std::bar;
                    if (nameElement != null)
                    {
                        alias.AliasName = nameElement.Value;
                    }
                    //TODO check this once srcml is updated to see if it's accurate
                    alias.Target = ParseExpression(GetFirstChildExpression(initElement), context);
                }
                else
                {
                    //example: using std::cout;
                    if (nameElement != null)
                    {
                        alias.Target    = ParseTypeUseElement(nameElement, context);
                        alias.AliasName = NameHelper.GetLastName(nameElement);
                    }
                }

                stmt = alias;
            }

            return(stmt);
        }