Exemplo n.º 1
0
        public static T GetGlobalSymbol <T>(this INativeSymbolLookup lookup, NativeName name)
            where T : NativeSymbol
        {
            var symbol = GetGlobalSymbol(lookup, name);

            return((T)symbol.Symbol);
        }
Exemplo n.º 2
0
        public static void WriteCsv(Stream stream, INativeSymbolLookup lookup)
        {
            var bulkWriter = new CsvBulkWriter(stream);

            WriteCore(bulkWriter, lookup);
            bulkWriter.WriteDone();
        }
Exemplo n.º 3
0
        public static BasicSymbolStorage ToBasicSymbolStorage(this INativeSymbolLookup lookup)
        {
            var storage = new BasicSymbolStorage();

            foreach (var name in lookup.NativeNames)
            {
                var symbol = lookup.GetGlobalSymbol(name);
                storage.Add(symbol);
            }
            return(storage);
        }
Exemplo n.º 4
0
        public static NativeGlobalSymbol GetGlobalSymbol(this INativeSymbolLookup lookup, NativeName name)
        {
            NativeGlobalSymbol symbol;

            if (!lookup.TryGetGlobalSymbol(name, out symbol))
            {
                throw new Exception($"Unable to get symbol {name}");
            }

            return(symbol);
        }
Exemplo n.º 5
0
            internal override void Write(INativeSymbolLookup lookup)
            {
                foreach (var name in lookup.NativeNames)
                {
                    if (name.Kind == NativeNameKind.EnumValue)
                    {
                        continue;
                    }

                    _storage.Add(lookup.GetGlobalSymbol(name));
                }
            }
Exemplo n.º 6
0
        public static bool TryGetEnumByValueName(this INativeSymbolLookup lookup, string enumValueName, out NativeEnum enumeration, out NativeEnumValue value)
        {
            if (!lookup.TryGetGlobalSymbol(new NativeName(enumValueName, NativeNameKind.EnumValue), out value))
            {
                enumeration = null;
                return(false);
            }

            return(lookup.TryGetGlobalSymbol(
                       new NativeName(value.EnumName, NativeNameKind.Enum),
                       out enumeration));
        }
Exemplo n.º 7
0
        public void Write(INativeSymbolLookup lookup)
        {
            foreach (var name in lookup.NativeNames)
            {
                if (name.Kind == NativeNameKind.EnumValue)
                {
                    continue;
                }

                Write(lookup.GetGlobalSymbol(name));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Do a lookup for a symbol with a specific name of the specified type.
        /// </summary>
        public static bool TryGetGlobalSymbol <T>(this INativeSymbolLookup lookup, string name, out T symbol)
            where T : NativeSymbol
        {
            NativeGlobalSymbol globalSymbol;

            if (!lookup.TryGetGlobalSymbol(name, out globalSymbol))
            {
                symbol = null;
                return(false);
            }

            symbol = globalSymbol.Symbol as T;
            return(symbol != null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Do a lookup for a symbol with a specific name of the specified type.
        /// </summary>
        internal static bool TryGetGlobalSymbolExhaustive(this INativeSymbolLookup lookup, string name, out NativeGlobalSymbol symbol)
        {
            foreach (var kind in Enum.GetValues(typeof(NativeNameKind)).Cast <NativeNameKind>())
            {
                var nativeName = new NativeName(name, kind);
                if (lookup.TryGetGlobalSymbol(nativeName, out symbol))
                {
                    return(true);
                }
            }

            symbol = default(NativeGlobalSymbol);
            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a NativeTypeBag from the result of a code analysis
        /// </summary>
        public static NativeSymbolBag CreateFrom(NativeCodeAnalyzerResult result, INativeSymbolLookup nextSymbolBag, ErrorProvider ep)
        {
            var bag = new NativeSymbolBag(nextSymbolBag);

            foreach (var symbol in result.Symbols)
            {
                try
                {
                    bag.Add(symbol);
                }
                catch
                {
                    ep.AddError($"Error adding symbol {symbol.Name.Name}");
                }
            }
            return(bag);
        }
Exemplo n.º 11
0
        private void TestRoundTrip(INativeSymbolLookup lookup)
        {
            foreach (var util in _utilList)
            {
                util.Write(lookup);
                var storage = util.Read();
                foreach (var name in lookup.NativeNames)
                {
                    if (name.Kind == NativeNameKind.EnumValue)
                    {
                        continue;
                    }

                    var symbol = lookup.GetGlobalSymbol(name);
                    NativeGlobalSymbol other;

                    if (!storage.TryGetGlobalSymbol(name, out other))
                    {
                    }
                    Assert.True(storage.TryGetGlobalSymbol(name, out other));
                    Assert.Equal(SymbolPrinter.Convert(symbol.Symbol), SymbolPrinter.Convert(other.Symbol));
                }
            }
        }
Exemplo n.º 12
0
 public NativeSymbolBag(INativeSymbolLookup nextSymbolBag = null)
 {
     _storage          = new BasicSymbolStorage();
     _nextSymbolLookup = nextSymbolBag ?? EmptyLookup;
 }
Exemplo n.º 13
0
 internal override void Write(INativeSymbolLookup lookup)
 {
     _stream.Position = 0;
     StorageUtil.WriteCsv(_stream, lookup);
 }
Exemplo n.º 14
0
        public static bool Contains(this INativeSymbolLookup lookup, string name)
        {
            NativeGlobalSymbol symbol;

            return(lookup.TryGetGlobalSymbol(name, out symbol));
        }
Exemplo n.º 15
0
 internal abstract void Write(INativeSymbolLookup lookup);
Exemplo n.º 16
0
        /// <summary>
        /// Find all NativeEnum which have a value of this name in this lookup.
        /// </summary>
        public static bool TryGetEnumByValueName(this INativeSymbolLookup lookup, string enumValueName, out NativeEnum enumeration)
        {
            NativeEnumValue value;

            return(TryGetEnumByValueName(lookup, enumValueName, out enumeration, out value));
        }
Exemplo n.º 17
0
 public static bool TryGetValue(this INativeSymbolLookup lookup, string name, out NativeSymbol symbol) =>
 lookup.TryGetGlobalSymbol(new NativeName(name, NativeNameKind.Constant), out symbol) ||
 lookup.TryGetGlobalSymbol(new NativeName(name, NativeNameKind.EnumValue), out symbol);
Exemplo n.º 18
0
        private static void WriteCore(IBulkWriter writer, INativeSymbolLookup lookup)
        {
            var exporter = new BulkExporter(writer);

            exporter.Write(lookup);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Try and find any global symbol with the specified name.
 /// </summary>
 public static bool TryGetType(this INativeSymbolLookup lookup, string name, out NativeType nt)
 {
     return(lookup.TryGetGlobalSymbol(name, out nt));
 }
Exemplo n.º 20
0
        public static void WriteBinary(Stream stream, INativeSymbolLookup lookup)
        {
            var writer = new BinaryBulkWriter(stream);

            WriteCore(writer, lookup);
        }