Example #1
0
 internal IncludeResolver(
     CppBackend backend,
     IEnvironment env)
 {
     _backend = backend;
     _env     = env;
 }
Example #2
0
        void RegisterType(DataType dt)
        {
            if (dt.IsClosed)
            {
                _type.TypeObjects.Add(dt);
            }
            else if (dt.IsGenericParameter)
            {
                _type.TypeObjects.Add(Type);
            }
            else if (dt.IsGenericMethodType)
            {
                RegisterType(dt.ParentType.MasterDefinition);
            }
            else if (dt.MasterDefinition != Type && !dt.IsArray)
            {
                _type.TypeObjects.Add(dt.MasterDefinition);
            }

            if (!_type.TypeObjects.Contains(dt) &&
                !(Function.IsGenericMethod && CppBackend.Compare(dt, Function.GenericType)) &&
                !CppBackend.Compare(dt, Type) &&
                !dt.IsGenericParameter &&
                dt.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
            {
                _func.PrecalcedTypes.Add(dt);
            }
        }
Example #3
0
 public CppPrecalc(CppBackend backend)
     : base(backend)
 {
     _backend = backend;
     _type    = _backend.GetType(DataType.Null);
     _func    = _backend.GetFunction(Function.Null);
 }
Example #4
0
 void RegisterDependency(DataType dt)
 {
     if (!(Function.IsGenericMethod && CppBackend.Compare(dt, Function.GenericType)) &&
         !CppBackend.Compare(dt, Type) && dt.HasInitializer &&
         dt.BuiltinType != BuiltinType.String && dt.BuiltinType != BuiltinType.Char &&
         dt.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
     {
         _func.Dependencies.Add(dt);
     }
 }
Example #5
0
        internal CppType(
            IEnvironment env,
            CppBackend backend,
            DataType dt)
        {
            EmitTypeObject = !env.HasProperty(dt, "TypeOfFunction");
            IsOpaque       = backend.IsOpaque(dt);
            ReflectedName  = dt.IsIntrinsic ? dt.QualifiedName : dt.ToString();
            StructName     = backend.GetStaticName(dt, dt);
            TypeOfFunction = StructName + "_typeof";
            TypeOfType     = StructName + "_type";

            if (dt.IsGenericMethodType)
            {
                TypeOfType = "uClassType";
                return;
            }

            EmitTypeOfDeclaration = true;

            switch (dt.TypeType)
            {
            case TypeType.Class:
            case TypeType.Struct:
            {
                foreach (var m in dt.Methods)
                {
                    AddClassMethod(env, m);
                }
                foreach (var m in dt.Properties)
                {
                    AddClassMethod(env, m.GetMethod);
                    AddClassMethod(env, m.SetMethod);
                }
                foreach (var m in dt.Events)
                {
                    AddClassMethod(env, m.AddMethod);
                    AddClassMethod(env, m.RemoveMethod);
                }

                foreach (var f in Functions)
                {
                    if (f.IsConstructor ||
                        !f.IsStatic && !f.IsVirtualBase ||
                        f.IsVirtual && (
                            backend.IsTemplate(f.DeclaringType) ||
                            f.DeclaringType.Base == null
                            ))
                    {
                        continue;
                    }

                    StaticMethods.Add(f);
                }

                Fields.AddRange(dt.EnumerateFields());

                for (var bt = dt.Base; bt != null; bt = bt.Base)
                {
                    foreach (var f in bt.EnumerateFields())
                    {
                        if (!f.IsStatic)
                        {
                            FlattenedFields.Add(f);
                        }
                    }
                }
                InheritedFieldCount = FlattenedFields.Count;

                foreach (var f in Fields)
                {
                    if (!f.IsStatic)
                    {
                        FlattenedFields.Add(f);
                    }
                }
                // Strategically add static fields last
                foreach (var f in Fields)
                {
                    if (f.IsStatic)
                    {
                        FlattenedFields.Add(f);
                    }
                }

                // Early out unless reflection is enabled
                if (!backend.EnableReflection || (!backend.EnableDebugDumps && !dt.IsPublic))
                {
                    break;
                }

                foreach (var f in dt.EnumerateFunctions())
                {
                    var prototype = f.Prototype;

                    if (!prototype.IsPublic || env.GetBool(f, "IsIntrinsic"))
                    {
                        continue;
                    }
                    switch (prototype.MemberType)
                    {
                    case MemberType.Cast:
                    case MemberType.Operator:
                    case MemberType.Finalizer:
                        continue;

                    case MemberType.Constructor:
                    {
                        if (prototype.IsStatic || f.ReturnType.IsVoid)
                        {
                            continue;
                        }

                        break;
                    }

                    case MemberType.Method:
                    {
                        var method = (Method)prototype;
                        if (method.ImplementedMethod != null ||
                            method.OverriddenMethod != null ||
                            method.IsGenerated && method.DeclaringMember == null)
                        {
                            continue;
                        }

                        break;
                    }
                    }

                    ReflectedFunctions.Add(f);
                }

                foreach (var f in backend.EnableDebugDumps ? dt.EnumerateFields() : dt.Fields)
                {
                    var prototype = f.Prototype;

                    if (!backend.EnableDebugDumps && (!prototype.IsPublic || prototype.IsGenerated))
                    {
                        continue;
                    }

                    ReflectedFields.Add(f);
                }

                break;
            }

            case TypeType.Interface:
            {
                foreach (var m in dt.Methods)
                {
                    AddInterfaceMethod(m);
                }
                foreach (var m in dt.Properties)
                {
                    AddInterfaceMethod(m.GetMethod);
                    AddInterfaceMethod(m.SetMethod);
                }
                foreach (var m in dt.Events)
                {
                    AddInterfaceMethod(m.AddMethod);
                    AddInterfaceMethod(m.RemoveMethod);
                }

                // Early out unless reflection is enabled
                if (!backend.EnableReflection || !dt.IsPublic)
                {
                    break;
                }

                ReflectedFunctions.AddRange(dt.EnumerateFunctions());
                break;
            }
            }

            // Clear fields on structs where TypeName is overridden,
            // to avoid invalid offsetof() in generated code.
            if (dt.IsStruct && env.HasProperty(dt, "TypeName"))
            {
                FlattenedFields.Clear();
                ReflectedFields.Clear();
            }

            EmitTypeStruct = EmitTypeObject && (
                VTable.Any(x => x.OverriddenMethod == null) ||
                dt.Base == null && dt.Interfaces.Length > 0 ||
                dt.Base != null && dt.Interfaces.Length > dt.Base.Interfaces.Length
                );

            if (!EmitTypeStruct)
            {
                TypeOfType = dt.IsValueType
                    ? "uStructType"
                    : backend.GetTypeOfType(dt.Base, dt);
            }

            Functions.Sort();
            ReflectedFields.Sort();
            ReflectedFunctions.Sort();
            InstanceMethods.Sort();
            VTable.Sort();
        }
Example #6
0
 public CppDecompiler(CppBackend backend)
 {
     _backend = backend;
 }
Example #7
0
 public CppFinallyTransform(CppBackend backend)
     : base(backend)
 {
 }
Example #8
0
 public CppTransform(CppBackend backend)
     : base(backend)
 {
     _backend = backend;
 }