コード例 #1
0
        public void Add(NativeGlobalSymbol globalSymbol)
        {
            var symbol = globalSymbol.Symbol;
            var name   = globalSymbol.Name;

            switch (globalSymbol.Kind)
            {
            case NativeNameKind.Struct:
            case NativeNameKind.Union:
            case NativeNameKind.FunctionPointer:
                _definedMap.Add(name.Name, (NativeDefinedType)symbol);
                break;

            case NativeNameKind.Enum:
            {
                // https://github.com/jaredpar/pinvoke/issues/16
                var enumeration = (NativeEnum)symbol;
                _definedMap.Add(enumeration.Name, enumeration);
                foreach (var value in enumeration.Values)
                {
                    _enumValueMap.Add(value.Name, value);
                }
            }
            break;

            case NativeNameKind.Procedure:
                _procMap.Add(name.Name, (NativeProcedure)symbol);
                break;

            case NativeNameKind.TypeDef:
                _typeDefMap.Add(name.Name, (NativeTypeDef)symbol);
                break;

            case NativeNameKind.Constant:
                _constMap.Add(name.Name, (NativeConstant)symbol);
                break;

            case NativeNameKind.EnumValue:
                throw new Exception("EnumValues are added automatically as a part of their containing enumeration");

            default:
                throw Contract.CreateInvalidEnumValueException(globalSymbol.Kind);
            }
        }
コード例 #2
0
 public void Add(NativeGlobalSymbol symbol) => _storage.Add(symbol);
コード例 #3
0
 public bool TryGetGlobalSymbol(NativeName name, out NativeGlobalSymbol symbol) =>
 _storage.TryGetGlobalSymbol(name, out symbol) ||
 _nextSymbolLookup.TryGetGlobalSymbol(name, out symbol);
コード例 #4
0
 public bool TryGetGlobalSymbol(NativeName name, out NativeGlobalSymbol symbol)
 {
     symbol = default(NativeGlobalSymbol);
     return(false);
 }
コード例 #5
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);
        }
コード例 #6
0
        public bool TryGetGlobalSymbol(NativeName name, out NativeGlobalSymbol symbol)
        {
            switch (name.Kind)
            {
            case NativeNameKind.Struct:
            case NativeNameKind.Union:
            case NativeNameKind.FunctionPointer:
            case NativeNameKind.Enum:
            {
                NativeDefinedType definedType;
                if (_definedMap.TryGetValue(name.Name, out definedType))
                {
                    symbol = new NativeGlobalSymbol(definedType);
                    return(true);
                }
            }
            break;

            case NativeNameKind.Procedure:
            {
                NativeProcedure proc;
                if (_procMap.TryGetValue(name.Name, out proc))
                {
                    symbol = new NativeGlobalSymbol(proc);
                    return(true);
                }
            }
            break;

            case NativeNameKind.TypeDef:
            {
                NativeTypeDef typeDef;
                if (_typeDefMap.TryGetValue(name.Name, out typeDef))
                {
                    symbol = new NativeGlobalSymbol(typeDef);
                    return(true);
                }
            }
            break;

            case NativeNameKind.Constant:
            {
                NativeConstant constant;
                if (_constMap.TryGetValue(name.Name, out constant))
                {
                    symbol = new NativeGlobalSymbol(constant);
                    return(true);
                }
            }
            break;

            case NativeNameKind.EnumValue:
            {
                NativeEnumValue value;
                if (_enumValueMap.TryGetValue(name.Name, out value))
                {
                    symbol = new NativeGlobalSymbol(value);
                    return(true);
                }
            }
            break;

            default:
                Contract.ThrowInvalidEnumValue(name.Kind);
                break;
            }

            symbol = default(NativeGlobalSymbol);
            return(false);
        }
コード例 #7
0
 public bool TryGetGlobalSymbol(string name, out NativeGlobalSymbol symbol)
 {
     return(this.TryGetGlobalSymbolExhaustive(name, out symbol));
 }