コード例 #1
0
 public CppPrecalc(CppBackend backend)
     : base(backend)
 {
     _backend = backend;
     _type    = _backend.GetType(DataType.Null);
     _func    = _backend.GetFunction(Function.Null);
 }
コード例 #2
0
        bool OptimizeDependencies(CppType type)
        {
            if (!type._isOptimized)
            {
                type._isOptimized = true;

                foreach (var m in type.MethodTypes)
                {
                    OptimizeDependencies(m);
                }

                for (int i = type.Dependencies.Count - 1; i >= 0; i--)
                {
                    if (type.Dependencies[i].Initializer == null &&
                        OptimizeDependencies(_backend.GetType(type.Dependencies[i])))
                    {
                        type.Dependencies.RemoveAt(i);
                    }
                }
            }

            return(type.Dependencies.Count == 0);
        }
コード例 #3
0
ファイル: IncludeResolver.cs プロジェクト: yongaru/uno
        public Declarations GetDeclarations(DataType dt, CppType type)
        {
            var baseTypes       = new HashSet <DataType>();
            var fieldTypes      = new HashSet <DataType>();
            var hIncludes       = new HashSet <string>();
            var hDeclarations   = new HashSet <string>();
            var hTypes          = new HashSet <DataType>();
            var incIncludes     = new HashSet <string>();
            var incTypes        = new HashSet <DataType>();
            var cppTypes        = new HashSet <DataType>();
            var cppIncludes     = new HashSet <string>();
            var cppDeclarations = new HashSet <string>();

            Resolve(dt, baseTypes, fieldTypes, hTypes, incTypes, cppTypes);

            foreach (var t in type.Dependencies)
            {
                Add(cppTypes, t);
            }
            foreach (var t in type.PrecalcedTypes)
            {
                Add(cppTypes, t);
            }
            foreach (var m in type.MethodTypes)
            {
                foreach (var t in m.Dependencies)
                {
                    Add(cppTypes, t);
                }
                foreach (var t in m.PrecalcedTypes)
                {
                    Add(cppTypes, t);
                }
            }

            if (_backend.HasForwardDeclaration(dt))
            {
                hDeclarations.Add(_backend.GetForwardDeclaration(dt));
            }

            foreach (var e in fieldTypes)
            {
                if (e.IsStruct && !_backend.IsOpaque(e))
                {
                    baseTypes.Add(e.MasterDefinition);
                }
                else
                {
                    hTypes.Add(e.MasterDefinition);
                }
            }

            foreach (var e in baseTypes)
            {
                hIncludes.Add(_backend.GetIncludeFilename(e));
                hTypes.Remove(e.MasterDefinition);
                incTypes.Remove(e.MasterDefinition);
                cppTypes.Add(e.MasterDefinition);
            }

            foreach (var e in hTypes)
            {
                hDeclarations.Add(_backend.GetForwardDeclaration(e));
                cppTypes.Add(e.MasterDefinition);
            }

            foreach (var e in incTypes)
            {
                incIncludes.Add(_backend.GetIncludeFilename(e));
            }
            foreach (var e in cppTypes)
            {
                cppIncludes.Add(_backend.GetIncludeFilename(e));
            }

            if (hIncludes.Count == 0)
            {
                hIncludes.Add("Uno.h");
            }

            foreach (var e in _env.GetSet(dt, "Header.Declaration"))
            {
                hDeclarations.Add(e.Trim());
            }
            foreach (var e in _env.GetSet(dt, "Header.Include"))
            {
                hIncludes.Add(e.Trim());
            }
            foreach (var e in _env.GetSet(dt, "Header.Import"))
            {
                hDeclarations.Add("#import <" + e.Trim() + ">");
            }

            foreach (var e in _env.GetSet(dt, "Source.Declaration"))
            {
                cppDeclarations.Add(e.Trim());
            }
            foreach (var e in _env.GetSet(dt, "Source.Include"))
            {
                cppIncludes.Add(e.Trim());
            }
            foreach (var e in _env.GetSet(dt, "Source.Import"))
            {
                cppDeclarations.Add("#import <" + e.Trim() + ">");
            }

            SourceValue val;

            if (_env.TryGetValue(dt, "ForwardDeclaration", out val))
            {
                hDeclarations.Add(val.String.Trim());
            }
            if (_env.TryGetValue(dt, "Include", out val))
            {
                hIncludes.Add(val.String.Trim());
            }

            foreach (var e in hIncludes)
            {
                cppIncludes.Remove(e);
                incIncludes.Remove(e);
            }
            foreach (var e in incIncludes)
            {
                cppIncludes.Remove(e);
            }

            foreach (var e in hIncludes)
            {
                hDeclarations.Add("#include <" + e + ">");
            }
            foreach (var e in cppIncludes)
            {
                cppDeclarations.Add("#include <" + e + ">");
            }

            hDeclarations.Remove(null);
            cppDeclarations.Remove(null);
            incIncludes.Remove(null);

            var inlineDeclarations = incIncludes.ToArray();

            for (int i = 0; i < inlineDeclarations.Length; i++)
            {
                inlineDeclarations[i] = "#include <" + inlineDeclarations[i] + ">";
            }

            var result = new Declarations
            {
                Header = hDeclarations.ToArray(),
                Source = cppDeclarations.ToArray(),
                Inline = inlineDeclarations,
            };

            Array.Sort(result.Header);
            Array.Sort(result.Source);
            Array.Sort(result.Inline);
            return(result);
        }
コード例 #4
0
 public override void End(DataType dt)
 {
     _type = _backend.GetType(DataType.Null);
 }
コード例 #5
0
 public override bool Begin(DataType dt)
 {
     _type = _backend.GetType(dt);
     return(true);
 }