예제 #1
0
        public virtual AbstractTypeDefinition FindStandardType(TypedefDefinition typedef)
        {
            AbstractTypeDefinition expl = null;

            if (typedef.BaseTypeName.Contains("<") || typedef.BaseTypeName.Contains("std::") || Mogre17.IsCollection(typedef.BaseTypeName))
            {
                if (typedef.BaseTypeName == "std::vector" || typedef.BaseTypeName == "std::list")
                {
                    expl = CreateTemplateOneTypeParamType(typedef);
                }
                else
                {
                    switch (typedef.TypeParamNames.Length)
                    {
                    case 1:
                        expl = CreateTemplateOneTypeParamType(typedef);
                        break;

                    case 2:
                        expl = CreateTemplateTwoTypeParamsType(typedef);
                        break;

                    default:
                        throw new Exception("Unexpected");
                    }
                }
            }

            if (expl == null)
            {
                throw new ArgumentException("Unsupported or unknown standard type: " + typedef.BaseTypeName);
            }

            return(expl);
        }
예제 #2
0
        /// <summary>
        /// Resolves this type definition to its actual type. This has two applications:
        ///
        /// 1. For a type that is replaced by another type the other type will be returned.
        /// 2. For a <c>typedef</c> this returns the actual underlying type of the typedef.
        /// </summary>
        public override AbstractTypeDefinition ResolveType()
        {
            if (ReplaceByType != null)
            {
                return(ReplaceByType);
            }

            AbstractTypeDefinition expl = null;

            if (BaseTypeName.Contains("<") || BaseTypeName.Contains("std::") || Mogre17.IsCollection(BaseTypeName))
            {
                // Standard types
                expl = MetaDef.Factory.StandardTypesFactory.FindStandardType(this);
            }
            else if (Name == "String")
            {
                // Typdef "String", which is (obviously) a string.
                expl = new DefStringTypeDef(Namespace, SurroundingClass, DefiningXmlElement);
            }

            if (expl == null)
            {
                return(this);
            }

            expl.LinkAttributes(this);
            return(expl);
        }
예제 #3
0
        public override void ProduceDefaultParamValueConversionCode(ParamDefinition param, out string preConversion,
                                                                    out string conversion, out string postConversion,
                                                                    out AbstractTypeDefinition dependancyType)
        {
            preConversion  = postConversion = "";
            dependancyType = null;

            switch (param.PassedByType)
            {
            case PassedByType.Reference:
            case PassedByType.Value:
                conversion = param.DefaultValue.Trim();
                if (!conversion.StartsWith("\"") && conversion.Contains("::"))
                {
                    //It's a static string of a class

                    if (conversion == "StringUtil::BLANK")
                    {
                        //Manually translate "StringUtil::BLANK" so that there's no need to wrap the StringUtil class
                        conversion = "String::Empty";
                        return;
                    }

                    string name = conversion.Substring(0, conversion.LastIndexOf("::"));
                    dependancyType = DetermineType <AbstractTypeDefinition>(name);
                }
                break;

            default:
                throw new Exception("Unexpected");
            }
        }
예제 #4
0
        /// <summary>
        /// Finds a type (e.g. a class) within this namespace. This namespace and all parent namespaces
        /// will be searched (where this namespace will be searched first). Child namespace won't be searched.
        /// The type is searched for as if it would be used directly within a <c>namespace</c> block (or within a nested
        /// class directly inside a <c>namespace</c> block).
        /// </summary>
        /// <typeparam name="T">the type of the definition to be returned (e.g. <see cref="ClassDefinition"/>).</typeparam>
        /// <param name="name">the name of the type. The name must be specified without namespace. </param>
        /// <param name="raiseException">indicates whether an exception is to be thrown when the type can't
        /// be found. If this is <c>false</c>, an instance of <see cref="DefInternal"/> will be returned when
        /// the type couldn't be found.</param>
        /// <returns></returns>
        /// <seealso cref="AbstractTypeDefinition.DetermineType"/>
        public virtual T DetermineType <T>(string name, bool raiseException = true) where T : AbstractTypeDefinition
        {
            // Search this namespace
            AbstractTypeDefinition type = FindTypeInList <T>(name, _containedTypes);

            // Search parent namespace for the type.
            if (type == null)
            {
                if (ParentNamespace != null)
                {
                    return(ParentNamespace.DetermineType <T>(name, raiseException));
                }

                if (raiseException)
                {
                    throw new Exception("Could not find type");
                }

                return((T)(object)new DefInternal(this, name));
            }

            if (type is AbstractTypeDefinition && type.IsIgnored)
            {
                // Short circuit out to handle OGRE 1.6 memory allocator types
                // TODO by manski: ??? Document this more clearly.
                return((T)type);
            }

            return((T)type.ResolveType());
        }
예제 #5
0
        public ClassDefinition(NamespaceDefinition nsDef, ClassDefinition surroundingClass, XmlElement elem)
            : base(nsDef, surroundingClass, elem)
        {
            if (GetType() == typeof(ClassDefinition) && elem.Name != "class")
            {
                throw new Exception("Not class element");
            }

            foreach (XmlElement child in elem.ChildNodes)
            {
                switch (child.Name)
                {
                case "function":
                    MemberMethodDefinition func = new MemberMethodDefinition(child, this);
                    if (func.NativeName != "DECLARE_INIT_CLROBJECT_METHOD_OVERRIDE" && func.NativeName != "_Init_CLRObject" && !func.NativeName.StartsWith("OGRE_"))
                    {
                        AddNewFunction(func);
                    }
                    break;

                case "variable":
                    MemberFieldDefinition field = new MemberFieldDefinition(child, this);
                    if (field.NativeName != Name && field.NativeName != "DECLARE_CLRHANDLE" && field.NativeName != "_CLRHandle" && !field.NativeName.StartsWith("OGRE_"))
                    {
                        Members.Add(field);
                    }
                    break;

                case "inherits":
                    List <string> ilist = new List <string>();
                    foreach (XmlElement sub in child.ChildNodes)
                    {
                        if (sub.Name != "baseClass")
                        {
                            throw new Exception("Unknown element; expected 'baseClass'");
                        }
                        if (sub.InnerText != "")
                        {
                            if (sub.InnerText == "CLRObject")
                            {
                                this.AddAttribute(new CLRObjectAttribute());
                                this._isDirectSubclassOfCLRObject = true;
                            }
                            else
                            {
                                ilist.Add(sub.InnerText);
                            }
                        }
                    }
                    BaseClassesNames = ilist.ToArray();
                    break;

                default:
                    AbstractTypeDefinition type = MetaDef.Factory.CreateType(Namespace, this, child);
                    NestedTypes.Add(type);
                    break;
                }
            }
        }
        public static string GetProtectedTypesProxyName(AbstractTypeDefinition type)
        {
            string name = type.FullyQualifiedNativeName;

            name = name.Substring(name.IndexOf("::") + 2);
            name = name.Replace("::", "_");
            name = "Mogre::" + name + "_ProtectedTypesProxy";
            return(name);
        }
예제 #7
0
 public ParamDefinition(MetaDefinition metaDef, ITypeMember m, string name)
     : base(metaDef)
 {
     _name        = name;
     _type        = m.MemberType;
     _typename    = m.MemberTypeName;
     PassedByType = m.PassedByType;
     _isConst     = m.IsConst;
 }
예제 #8
0
        protected override void GenerateCodeNestedType(AbstractTypeDefinition nested)
        {
            if (nested.HasWrapType(WrapTypes.NativeDirector))
            {
                //Interface and native director are already declared before the declaration of this class.
                return;
            }

            base.GenerateCodeNestedType(nested);
            _wrapper.CppAddType(nested, _codeBuilder);
        }
 protected override void GenerateCodeNestedType(AbstractTypeDefinition nested)
 {
     if (nested.IsSTLContainer)
     {
         _codeBuilder.AppendLine("typedef " + _classDefinition.FullyQualifiedNativeName + "::" + nested.Name + " " + nested.CLRName + ";");
     }
     else
     {
         throw new Exception("Unexpected");
     }
 }
예제 #10
0
        protected override void GenerateCodeNestedType(AbstractTypeDefinition nested)
        {
            if (nested.HasWrapType(WrapTypes.NativeDirector))
            {
                //Interface and native director are already declared before the declaration of this class.
                //Just declare the method handlers of the class.
                NativeDirectorClassInclProducer.AddMethodHandlersClass((ClassDefinition)nested, _codeBuilder);
                return;
            }

            base.GenerateCodeNestedType(nested);
            _wrapper.IncAddType(nested, _codeBuilder);
        }
예제 #11
0
        private void AddAttributesForType(AbstractTypeDefinition type, XmlElement elem, List <KeyValuePair <AttributeSet, AutoWrapAttribute> > unprocessedAttributes)
        {
            // Add
            foreach (XmlAttribute attr in elem.Attributes)
            {
                if (attr.Name != "name")
                {
                    AddAttributeToSet(type, CreateAttributeFromXmlAttribute(attr), unprocessedAttributes);
                }
            }

            foreach (XmlNode childNode in elem.ChildNodes)
            {
                XmlElement childElement = childNode as XmlElement;

                if (childElement == null)
                {
                    // Not an XML element
                    continue;
                }

                // Attached Attribute
                if (IsAttachedProperty(childElement))
                {
                    AddAttributeToSet(type, CreateAttributeFromAttachedAttribute(childElement), unprocessedAttributes);
                    continue;
                }

                // Not an attached attribute
                switch (childElement.Name)
                {
                case "class":
                case "struct":
                case "enumeration":
                case "typedef":
                    AddAttributesForType(((ClassDefinition)type).GetNestedType(childElement.GetAttribute("name")), childElement, unprocessedAttributes);
                    break;

                case "function":
                case "variable":
                    foreach (MemberDefinitionBase m in ((ClassDefinition)type).GetMembers(childElement.GetAttribute("name")))
                    {
                        AddAttributesInMember(m, childElement, unprocessedAttributes);
                    }
                    break;

                default:
                    throw new Exception("Unexpected");
                }
            }
        }
예제 #12
0
        public NamespaceDefinition(MetaDefinition metaDef, XmlElement elem)
        {
            MetaDef = metaDef;

            // The child namespace names are stored in the attributes "second" and "third". Thus
            // we can only support up to three namespace levels (like "Level1::Level2::Level3").
            string second = elem.GetAttribute("second");
            string third  = elem.GetAttribute("third");

            NativeName = elem.GetAttribute("name");
            CLRName    = metaDef.ManagedNamespace;

            if (second != "")
            {
                NativeName += "::" + second;
                CLRName    += "::" + second;
            }

            if (third != "")
            {
                NativeName += "::" + third;
                CLRName    += "::" + third;
            }

            // If this is a child namespace, set parent and add itself to the parent.
            if (NativeName.Contains("::"))
            {
                // Is a child namespace.
                string parentNamespaceName = NativeName.Substring(0, NativeName.LastIndexOf("::"));
                ParentNamespace = metaDef.GetNameSpace(parentNamespaceName);

                ParentNamespace._childNamespaces.Add(this);
            }
            else
            {
                ParentNamespace = null;
            }

            //
            // Add types contained in this namespace.
            //
            foreach (XmlElement child in elem.ChildNodes)
            {
                AbstractTypeDefinition type = MetaDef.Factory.CreateType(this, null, child);
                if (type != null)
                {
                    _containedTypes.Add(type);
                }
            }
        }
        protected virtual bool HasProtectedTypes()
        {
            foreach (AbstractTypeDefinition nested in _classDefinition.NestedTypes)
            {
                AbstractTypeDefinition type = nested.DetermineType <AbstractTypeDefinition>(nested.Name);

                if (type.ProtectionLevel == ProtectionLevel.Protected &&
                    type.IsSTLContainer && Wrapper.IsTypeWrappable(type))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #14
0
        /// <summary>
        /// Returns the type definition for the specified type or throws a <see cref="KeyNotFoundException"/>
        /// if the type is not part of this namespace.
        /// </summary>
        /// <param name="name">the name of the type to look for. Must come without namespace prepended (i.e.
        /// just the class/type name).</param>
        public AbstractTypeDefinition FindTypeDefinition(string name)
        {
            AbstractTypeDefinition type = null;

            foreach (AbstractTypeDefinition t in _containedTypes)
            {
                if (t.Name == name)
                {
                    type = t;
                    break;
                }
            }

            if (type == null)
            {
                throw new KeyNotFoundException(String.Format("DefType not found for '{0}'", name));
            }

            return(type);
        }
예제 #15
0
        /// <summary>
        /// Finds the specified type in a specified list.
        /// </summary>
        /// <returns>Returns the type definition or <c>null</c>, if it could not be found.</returns>
        private AbstractTypeDefinition FindTypeInList <T>(string name, List <AbstractTypeDefinition> types)
        {
            List <AbstractTypeDefinition> list = new List <AbstractTypeDefinition>();

            string topname   = name;
            string nextnames = null;

            if (name.Contains("::"))
            {
                topname   = name.Substring(0, name.IndexOf("::"));
                nextnames = name.Substring(name.IndexOf("::") + 2);
            }

            foreach (AbstractTypeDefinition t in types)
            {
                if (t.Name == topname && t is T)
                {
                    list.Add(t);
                }
            }

            if (list.Count == 0)
            {
                return(null);
            }

            if (list.Count > 1)
            {
                throw new Exception("Found more than one type");
            }

            AbstractTypeDefinition type = list[0];

            if (nextnames != null)
            {
                return(FindTypeInList <T>(nextnames, ((ClassDefinition)type).NestedTypes));
            }

            return(type);
        }
        public override void GenerateCode()
        {
            Init();

            if (HasProtectedTypes() || HasProtectedStaticFields())
            {
                string className = GetProtectedTypesProxyName(_classDefinition);
                className = className.Substring(className.IndexOf("::") + 2);
                _codeBuilder.AppendLine("class " + className + " : public " + _classDefinition.FullyQualifiedNativeName);
                _codeBuilder.AppendLine("{");
                _codeBuilder.AppendLine("public:");
                _codeBuilder.IncreaseIndent();

                className = _classDefinition.FullyQualifiedCLRName;
                className = className.Substring(className.IndexOf("::") + 2);

                if (_classDefinition.IsInterface)
                {
                    className = className.Replace(_classDefinition.CLRName, _classDefinition.Name);
                }

                className = this.MetaDef.ManagedNamespace + "::" + className;

                _codeBuilder.AppendLine("friend ref class " + className + ";");

                foreach (AbstractTypeDefinition nested in _classDefinition.NestedTypes)
                {
                    AbstractTypeDefinition type = nested.DetermineType <AbstractTypeDefinition>(nested.Name);

                    if (type.ProtectionLevel == ProtectionLevel.Protected &&
                        type.IsSTLContainer && Wrapper.IsTypeWrappable(type))
                    {
                        GenerateCodeNestedType(type);
                    }
                }

                _codeBuilder.DecreaseIndent();
                _codeBuilder.AppendLine("};\n");
            }
        }
예제 #17
0
        protected override void GenerateCodeAllNestedTypes()
        {
            //Predeclare all nested classes in case there are classes referencing their "siblings"
            foreach (AbstractTypeDefinition nested in _classDefinition.NestedTypes)
            {
                if (nested.ProtectionLevel == ProtectionLevel.Public ||
                    ((AllowProtectedMembers || AllowSubclassing) && nested.ProtectionLevel == ProtectionLevel.Protected))
                {
                    AbstractTypeDefinition expl = _classDefinition.DetermineType <AbstractTypeDefinition>(nested.Name);

                    if (expl.IsSTLContainer ||
                        (!nested.IsValueType && nested is ClassDefinition && !(nested as ClassDefinition).IsInterface && Wrapper.IsTypeWrappable(nested)))
                    {
                        _codeBuilder.AppendLine(nested.ProtectionLevel.GetCLRProtectionName() + ": ref class " + nested.CLRName + ";");
                    }
                }
            }

            _codeBuilder.AppendEmptyLine();

            base.GenerateCodeAllNestedTypes();
        }
예제 #18
0
        public override void ProduceDefaultParamValueConversionCode(ParamDefinition param, out string preConversion, out string conversion, out string postConversion, out AbstractTypeDefinition dependancyType)
        {
            preConversion  = postConversion = "";
            dependancyType = null;
            switch (param.PassedByType)
            {
            case PassedByType.Pointer:
                preConversion = FullyQualifiedCLRName + " out_" + param.Name + ";";
                conversion    = "out_" + param.Name;
                return;

            default:
                conversion = FullyQualifiedCLRName + "::" + param.DefaultValue;
                return;
            }
        }
예제 #19
0
        public override void ProduceDefaultParamValueConversionCode(ParamDefinition param, out string preConversion, out string conversion, out string postConversion, out AbstractTypeDefinition dependancyType)
        {
            preConversion  = postConversion = "";
            dependancyType = null;
            if (IsVoid)
            {
                conversion = param.DefaultValue;
                return;
            }

            switch (param.PassedByType)
            {
            case PassedByType.Pointer:
                if (!param.IsConst)
                {
                    preConversion = FullyQualifiedCLRName + " out_" + param.Name + ";";
                    conversion    = "out_" + param.Name;
                    return;
                }

                throw new Exception("Unexpected");

            default:
                conversion = param.DefaultValue;
                break;
            }
        }
예제 #20
0
 protected virtual void GenerateCodeNestedTypeBeforeMainType(AbstractTypeDefinition nested)
 {
 }
예제 #21
0
 protected override void GenerateCodeNestedTypeBeforeMainType(AbstractTypeDefinition nested)
 {
     base.GenerateCodeNestedType(nested);
     _wrapper.CppAddType(nested, _codeBuilder);
 }
예제 #22
0
 public override void ProduceDefaultParamValueConversionCode(ParamDefinition param, out string preConversion, out string conversion, out string postConversion, out AbstractTypeDefinition dependancyType)
 {
     preConversion  = postConversion = "";
     dependancyType = null;
     if (!(this is DefTemplateOneType || this is DefTemplateTwoTypes) && BaseType is DefInternal)
     {
         conversion = param.DefaultValue;
     }
     else
     {
         throw new Exception("Unexpected");
     }
 }
예제 #23
0
 protected virtual void AddTypeDependancy(AbstractTypeDefinition type)
 {
 }
예제 #24
0
 protected override void AddTypeDependancy(AbstractTypeDefinition type)
 {
     base.AddTypeDependancy(type);
     _wrapper.AddTypeDependancy(type);
 }
예제 #25
0
 public TypeParamDefinition(AbstractTypeDefinition type, PassedByType passed, bool isConst)
 {
     ParamType = type;
     _passed   = passed;
     _isConst  = isConst;
 }
예제 #26
0
 protected override void AddTypeDependancy(AbstractTypeDefinition type)
 {
     _wrapper.CppCheckTypeForDependancy(type);
 }
        /// <summary>
        /// Checks whether this method is a get accessor for a CLR property.
        /// </summary>
        /// <seealso cref="IsPropertyGetAccessor"/>
        public static bool CheckForGetAccessor(MemberMethodDefinition methodDef)
        {
            //
            // IMPORTANT: Don't use any of the "IsProperty..." properties of MemberMethodDefinition
            //   in this method as those properties use this method to determine their values.
            //
            if (methodDef.IsOverriding)
            {
                // Check this before checking possible attributes
                return(methodDef.BaseMethod.IsPropertyGetAccessor);
            }

            if (methodDef.IsConstructor || methodDef.MemberTypeName == "void" || methodDef.Parameters.Count != 0)
            {
                // Check this before checking possible attributes
                return(false);
            }

            if (methodDef.HasAttribute <PropertyAttribute>())
            {
                return(true);
            }

            if (methodDef.HasAttribute <MethodAttribute>())
            {
                return(false);
            }

            if (methodDef.HasAttribute <CustomIncDeclarationAttribute>() ||
                methodDef.HasAttribute <CustomCppDeclarationAttribute>())
            {
                return(false);
            }

            string name = methodDef.GetRenameName();

            if (methodDef.MemberTypeName == "bool" &&
                ((name.StartsWith("is") && Char.IsUpper(name[2]) && methodDef.MetaDef.CodeStyleDef.AllowIsInPropertyName) ||
                 (name.StartsWith("has") && Char.IsUpper(name[3]))) &&
                methodDef.Parameters.Count == 0)
            {
                return(true);
            }

            if (!methodDef.MemberType.IsValueType &&
                (methodDef.MemberType.IsSharedPtr || methodDef.MemberType is DefTemplateOneType || methodDef.MemberType is DefTemplateTwoTypes))
            {
                return(false);
            }

            if (methodDef.MemberType.HasAttribute <ReturnOnlyByMethodAttribute>())
            {
                // Invalid type for a property
                return(false);
            }

            string propName;

            if (name.StartsWith("get") && Char.IsUpper(name[3]))
            {
                propName = name.Substring(3);
            }
            else if (name.StartsWith("is") && Char.IsUpper(name[2]))
            {
                propName = name.Substring(2);
            }
            else
            {
                // Not a valid getter prefix.
                return(false);
            }

            // Check if the property's name collides with the name of a nested type. In this
            // case we can't convert the method into a property.
            AbstractTypeDefinition type = methodDef.ContainingClass.GetNestedType(propName, false);

            if (type != null)
            {
                return(false);
            }

            // Check if the property's name collides with the name of a method. In this
            // case we can't convert the method into a property.
            MemberMethodDefinition method = methodDef.ContainingClass.GetMethodByCLRName(propName, true, false);

            // If there is no method == valid property name
            return(method == null);
        }
예제 #28
0
 public virtual void ProduceDefaultParamValueConversionCode(ParamDefinition param, out string preConversion, out string conversion, out string postConversion, out AbstractTypeDefinition dependancyType)
 {
     throw new Exception("Unexpected");
 }
예제 #29
0
        public override void ProduceDefaultParamValueConversionCode(ParamDefinition param, out string preConversion, out string conversion, out string postConversion, out AbstractTypeDefinition dependancyType)
        {
            preConversion  = postConversion = "";
            dependancyType = null;
            switch (param.PassedByType)
            {
            case PassedByType.Pointer:
                if (param.DefaultValue == "NULL" || param.DefaultValue == "0")
                {
                    conversion = "nullptr";
                    return;
                }

                throw new Exception("Unexpected");

            default:
                throw new Exception("Unexpected");
            }
        }
예제 #30
0
 protected virtual void CheckTypeForDependancy(AbstractTypeDefinition type)
 {
     _wrapper.CheckTypeForDependancy(type);
 }