示例#1
0
        private object getDefaultValue(ConstantKind kind, int index)
        {
            switch (kind)
            {
            case ConstantKind.Utf8: return(strings[index]);

            case ConstantKind.Int: return(ints[index]);

            case ConstantKind.UInt: return(uints[index]);

            case ConstantKind.Double: return(doubles[index]);

            case ConstantKind.False:
            case ConstantKind.True:
            case ConstantKind.Null: return(const_values[index]);

            case ConstantKind.Namespace:
            case ConstantKind.PrivateNs:
            case ConstantKind.PackageNs:
            case ConstantKind.PackageInternalNs:
            case ConstantKind.ProtectedNs:
            case ConstantKind.StaticProtectedNs:
            case ConstantKind.StaticProtectedNs2: return(namespaces[index]);

            default:
                Console.WriteLine("-- Error: unknown kind [" + kind + "]");
                return(null);
            }
        }
示例#2
0
        public void Write(ConstantKind kind, object value)
        {
            Write((byte)kind);
            switch (kind)
            {
            case ConstantKind.Double:
                Write((double)value);
                break;

            case ConstantKind.Integer:
                Write((int)value);
                break;

            case ConstantKind.UInteger:
                Write((uint)value);
                break;

            case ConstantKind.String:
                Write((string)value);
                break;

            case ConstantKind.Null:
                Write("null");
                break;

            case ConstantKind.True:
                Write(true);
                break;

            case ConstantKind.False:
                Write(false);
                break;
            }
        }
示例#3
0
        string GetType(ConstantKind kind)
        {
            switch (kind)
            {
            case ConstantKind.Char:
                return("char");

            case ConstantKind.String:
                return("string");

            case ConstantKind.Int32:
            case ConstantKind.Index:
                return("int");

            case ConstantKind.UInt32:
                return("uint");

            case ConstantKind.UInt64:
                return("ulong");

            case ConstantKind.Register:
            case ConstantKind.MemorySize:
                return(EnumUtils.GetEnumType(genTypes, kind).Name(idConverter));

            default:
                throw new InvalidOperationException();
            }
        }
示例#4
0
 public Constant(ConstantKind kind, string name, ulong value, ConstantsTypeFlags flags = ConstantsTypeFlags.None, string?documentation = null)
 {
     DeclaringType = null !;
     Kind          = kind;
     RawName       = name;
     Documentation = documentation;
     ValueUInt64   = value;
     RefValue      = null;
     IsPublic      = (flags & ConstantsTypeFlags.Public) != 0;
     UseHex        = (flags & ConstantsTypeFlags.Hex) != 0;
 }
示例#5
0
 public Constant(ConstantKind kind, string name, ulong value, ConstantsTypeFlags flags, string?documentation, DeprecatedInfo deprecatedInfo)
 {
     DeclaringType  = null !;
     Kind           = kind;
     RawName        = name;
     Documentation  = documentation;
     DeprecatedInfo = deprecatedInfo;
     ValueUInt64    = value;
     RefValue       = null;
     IsPublic       = (flags & ConstantsTypeFlags.Public) != 0;
     UseHex         = (flags & ConstantsTypeFlags.Hex) != 0;
 }
示例#6
0
 public Constant(ConstantKind kind, string name, object value, ConstantsTypeFlags flags = ConstantsTypeFlags.None, string?documentation = null)
 {
     if (!(value is null) && value.GetType().IsValueType)
     {
         throw new ArgumentException();
     }
     DeclaringType = null !;
     Kind          = kind;
     RawName       = name;
     Documentation = documentation;
     ValueUInt64   = 0;
     RefValue      = value;
     IsPublic      = (flags & ConstantsTypeFlags.Public) != 0;
     UseHex        = (flags & ConstantsTypeFlags.Hex) != 0;
 }
示例#7
0
 public Constant(ConstantKind kind, string name, object value, ConstantsTypeFlags flags, string?documentation, DeprecatedInfo deprecatedInfo)
 {
     if (value is not null && value.GetType().IsValueType)
     {
         throw new ArgumentException();
     }
     DeclaringType  = null !;
     Kind           = kind;
     RawName        = name;
     Documentation  = documentation;
     DeprecatedInfo = deprecatedInfo;
     ValueUInt64    = 0;
     RefValue       = value;
     IsPublic       = (flags & ConstantsTypeFlags.Public) != 0;
     UseHex         = (flags & ConstantsTypeFlags.Hex) != 0;
 }
示例#8
0
        public object GetConstant(ConstantKind type, int index)
        {
            switch (type)
            {
            case ConstantKind.True: return(true);

            case ConstantKind.False: return(false);

            case ConstantKind.Null:
            case ConstantKind.Undefined: return(null);

            case ConstantKind.String: return(Strings[index]);

            case ConstantKind.Double: return(Doubles[index]);

            case ConstantKind.Integer: return(Integers[index]);

            case ConstantKind.UInteger: return(UIntegers[index]);

            case ConstantKind.Namespace: return(Namespaces[index]);

            default: return(null);
            }
        }
示例#9
0
        public ConstantsType ToConstantsType(ConstantKind constantKind)
        {
            var flags = ConstantsTypeFlags.None;

            if (IsPublic)
            {
                flags |= ConstantsTypeFlags.Public;
            }
            if (IsFlags)
            {
                flags |= ConstantsTypeFlags.Hex;
            }

            var constants = new Constant[Values.Length];

            for (int i = 0; i < constants.Length; i++)
            {
                var value    = Values[i];
                var constant = new Constant(constantKind, value.RawName, value.Value, flags, value.Documentation, value.DeprecatedInfo);
                constants[i] = constant;
            }

            return(new ConstantsType(RawName, TypeId, flags, Documentation, constants));
        }
示例#10
0
 public Constant(ConstantKind kind, string name, object value, ConstantsTypeFlags flags = ConstantsTypeFlags.None)
     : this(kind, name, value, flags, default, default)
 {
 }
示例#11
0
 public static EnumType GetEnumType(ConstantKind kind) =>
 kind switch
 {
示例#12
0
 public ConstantExpression(SourceSpan span, string value, ConstantKind kind)
     : base(span)
 {
     Value        = value;
     ConstentKind = kind;
 }
示例#13
0
        private void parseMethodInfos(BinaryReader br)
        {
            long start = br.BaseStream.Position;

            names[0] = new QName(publicNs, "*");
            int method_count = readU32(br);

            methods = new MethodInfo[method_count];

            for (int i = 0; i < method_count; i++)
            {
                MethodInfo m = new MethodInfo();
                methods[i] = m;
                int param_count = readU32(br);
                m.returnType = (QName)names[readU32(br)];
                m.paramTypes = new QName[param_count];
                for (int j = 0; j < param_count; j++)
                {
                    m.paramTypes[j] = (QName)names[readU32(br)];
                }
                m.debugName = (string)strings[readU32(br)];
                m.flags     = (MethodFlags)br.ReadSByte();

                if ((m.flags & MethodFlags.NeedRest) > 0)
                {
                    QName[] temp = m.paramTypes;
                    m.paramTypes = new QName[param_count + 1];
                    temp.CopyTo(m.paramTypes, 0);
                    m.paramTypes[param_count] = new QName("Array");
                }
                if ((m.flags & MethodFlags.HasOptional) > 0)
                {
                    // has_optional
                    int optional_count = readU32(br);
                    if ((m.flags & MethodFlags.NeedRest) > 0)
                    {
                        m.optionalValues = new object[optional_count + 1];
                        m.optionalValues[optional_count] = null;
                    }
                    else
                    {
                        m.optionalValues = new object[optional_count];
                    }
                    for (int k = 0; k < optional_count; k++)
                    {
                        int          index = readU32(br);                   // optional value index
                        ConstantKind kind  = (ConstantKind)br.ReadSByte();  // kind byte for each default value
                        if (index == 0)
                        {
                            // kind is ignored, default value is based on type
                            m.optionalValues[k] = null;
                        }
                        else
                        {
                            m.optionalValues[k] = getDefaultValue(kind, index);
                        }
                    }
                }
                if ((m.flags & MethodFlags.HasParamNames) > 0)
                {
                    // has_paramnames
                    if ((m.flags & MethodFlags.NeedRest) > 0)
                    {
                        m.paramNames = new string[param_count + 1];
                        m.paramNames[param_count] = "...rest";
                    }
                    else
                    {
                        m.paramNames = new string[param_count];
                    }
                    for (int k = 0; k < param_count; k++)                   //++k)
                    {
                        int index = readU32(br);
                        if (index < strings.Length && strings[index] != null)
                        {
                            m.paramNames[k] = (string)strings[index];
                        }
                    }
                }
            }
            //Console.WriteLine("MethodInfo count " +method_count+ " size "+(br.BaseStream.Position-start)+" "+(int)(100*(br.BaseStream.Position-start)/br.BaseStream.Length)+" %");
        }
示例#14
0
 /// <summary>
 /// Initializes the <see cref="Tag"/>.
 /// </summary>
 /// <param name="tag">The <see cref="ConstantKind"/>.</param>
 protected Constant(ConstantKind tag) => Tag = tag;
示例#15
0
 public Constant(ConstantKind kind, string name, ulong value, ConstantsTypeFlags flags = ConstantsTypeFlags.None)
     : this(kind, name, value, flags, null, default)
 {
 }
示例#16
0
文件: Constant.cs 项目: lanicon/Bali
 /// <summary>
 /// Initializes the <see cref="Tag"/>.
 /// </summary>
 /// <param name="tag">The <see cref="ConstantKind"/>.</param>
 protected Constant(ConstantKind tag)
 {
     Tag = tag;
 }
示例#17
0
 public ConstantExpressionNode(ConstantKind constantKind) : base(NodeKind.ConstantExpression)
 {
     this.ConstantKind = constantKind;
 }
示例#18
0
 string GetType(ConstantKind kind) =>
 kind switch
 {
示例#19
0
 public ConstantExpression(SourceLocation location, string value, ConstantKind kind) : base(location)
 {
     this.Value = value;
     this.Kind  = kind;
 }
示例#20
0
文件: EnumUtils.cs 项目: wtf3505/iced
 public static EnumType GetEnumType(GenTypes genTypes, ConstantKind kind) =>
 kind switch
 {
示例#21
0
 public ConstantExpressionNode(ConstantKind constantKind, Type type, object value) : base(NodeKind.ConstantExpression)
 {
     this.ConstantKind = constantKind;
     this.Type         = type;
     this.Value        = value;
 }