示例#1
0
        /// <summary>
        /// Adds a new method to the table
        /// </summary>
        /// <param name="method">The method declaration</param>
        public void Add(MethodDeclarationSyntax method)
        {
            string str = GetMethodLookupName(method);
            string currentClassName = m_context.TypeConvert.CurrentClassNameFormatted;
            string className        = currentClassName;

            TypeDeclarationSyntax parent = method.Parent as TypeDeclarationSyntax;
            bool found = false;

            if (parent.BaseList != null)
            {
                IEnumerable <SyntaxNode> children = parent.BaseList.ChildNodes();

                foreach (SimpleBaseTypeSyntax child in children)
                {
                    IdentifierNameSyntax identifier = child.ChildNodes().First() as IdentifierNameSyntax;

                    ITypeSymbol typeSymbol = m_context.Model.GetTypeInfo(identifier).Type;

                    ImmutableArray <ISymbol> members = typeSymbol.GetMembers();
                    foreach (ISymbol member in members)
                    {
                        if (member.Name == method.Identifier.ToString())
                        {
                            className = string.Format("{0}_{1}", m_context.ConvertNameSpace(typeSymbol.ContainingNamespace), typeSymbol.Name);
                            found     = true;
                            break;
                        }
                    }
                }
            }

            if (!found)
            {
                return;
            }

            if (!m_methods.ContainsKey(className))
            {
                m_methods.Add(className, new List <string>());
            }

            if (!m_methodsPerClass.ContainsKey(currentClassName))
            {
                m_methodsPerClass.Add(currentClassName, new List <string>());
            }

            m_methods[className].Add(str);
            m_methodsPerClass[currentClassName].Add(str);
        }
示例#2
0
        /// <summary>
        /// Converts the C# type to a C type name
        /// </summary>
        /// <param name="type">The C# type</param>
        /// <returns>The C type name</returns>
        public string ConvertTypeName(ITypeSymbol type)
        {
            string typeNameConverted;

            bool   nameContainsType = (type.ContainingType == null);
            string containingType   = nameContainsType ? type.ToString().Replace('.', '_') : type.ContainingType.ToString().Replace('.', '_');
            string nameSpace        = (type.ContainingNamespace == null) ? "" : m_context.ConvertNameSpace(type.ContainingNamespace);

            if (type.TypeKind == TypeKind.Class)
            {
                if (nameContainsType)
                {
                    typeNameConverted = string.Format("struct class_{0}*", containingType);
                }
                else
                {
                    typeNameConverted = string.Format("struct class_{0}_{1}*", containingType, type.Name);
                }
            }
            else if (type.TypeKind == TypeKind.Enum)
            {
                typeNameConverted = "int32_t";
            }
            else if (type.TypeKind == TypeKind.Struct)
            {
                if (nameContainsType)
                {
                    typeNameConverted = string.Format("struct struct_{0}", containingType);
                }
                else
                {
                    typeNameConverted = string.Format("struct struct_{0}_{1}", containingType, type.Name);
                }
            }
            else if (type.TypeKind == TypeKind.Pointer)
            {
                IPointerTypeSymbol pointer = (IPointerTypeSymbol)type;
                typeNameConverted = m_context.ConvertTypeName(pointer.PointedAtType) + "*";
            }
            else if (type.TypeKind == TypeKind.Array)
            {
                IArrayTypeSymbol array = (IArrayTypeSymbol)type;
                typeNameConverted = m_context.ConvertTypeName(array.ElementType) + new string('*', array.Rank);
            }
            else if (type.TypeKind == TypeKind.Delegate)
            {
                typeNameConverted = string.Format("delegate_{0}", type.ToString().Replace('.', '_'));
            }
            else if (type.TypeKind == TypeKind.Class)
            {
                typeNameConverted = string.Format("struct class_{0}_{1}*", nameSpace, type.ToString());
            }
            else if (type.TypeKind == TypeKind.Enum)
            {
                typeNameConverted = "int32_t";
            }
            else if (type.TypeKind == TypeKind.Interface)
            {
                typeNameConverted = "struct base_class*";
            }
            else
            {
                throw new NotImplementedException("Could not convert type name: " + type.TypeKind + " is unimplemented");
            }

            return(typeNameConverted);
        }