~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/reflect/Metadata/MetadataRW.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2009 Jeroen Frijters
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
*/
 
24
using System;
 
25
using System.Collections.Generic;
 
26
using System.Text;
 
27
 
 
28
namespace IKVM.Reflection.Metadata
 
29
{
 
30
        // base class for MetadataReader and MetadataWriter
 
31
        abstract class MetadataRW
 
32
        {
 
33
                internal readonly bool bigStrings;
 
34
                internal readonly bool bigGuids;
 
35
                internal readonly bool bigBlobs;
 
36
                internal readonly bool bigResolutionScope;
 
37
                internal readonly bool bigTypeDefOrRef;
 
38
                internal readonly bool bigMemberRefParent;
 
39
                internal readonly bool bigHasCustomAttribute;
 
40
                internal readonly bool bigCustomAttributeType;
 
41
                internal readonly bool bigMethodDefOrRef;
 
42
                internal readonly bool bigHasConstant;
 
43
                internal readonly bool bigHasSemantics;
 
44
                internal readonly bool bigHasFieldMarshal;
 
45
                internal readonly bool bigHasDeclSecurity;
 
46
                internal readonly bool bigTypeOrMethodDef;
 
47
                internal readonly bool bigMemberForwarded;
 
48
                internal readonly bool bigImplementation;
 
49
                internal readonly bool bigField;
 
50
                internal readonly bool bigMethodDef;
 
51
                internal readonly bool bigParam;
 
52
                internal readonly bool bigTypeDef;
 
53
                internal readonly bool bigProperty;
 
54
                internal readonly bool bigEvent;
 
55
                internal readonly bool bigGenericParam;
 
56
                internal readonly bool bigModuleRef;
 
57
 
 
58
                protected MetadataRW(Module module, bool bigStrings, bool bigGuids, bool bigBlobs)
 
59
                {
 
60
                        this.bigStrings = bigStrings;
 
61
                        this.bigGuids = bigGuids;
 
62
                        this.bigBlobs = bigBlobs;
 
63
                        this.bigField = module.Field.IsBig;
 
64
                        this.bigMethodDef = module.MethodDef.IsBig;
 
65
                        this.bigParam = module.Param.IsBig;
 
66
                        this.bigTypeDef = module.TypeDef.IsBig;
 
67
                        this.bigProperty = module.Property.IsBig;
 
68
                        this.bigEvent = module.Event.IsBig;
 
69
                        this.bigGenericParam = module.GenericParam.IsBig;
 
70
                        this.bigModuleRef = module.ModuleRef.IsBig;
 
71
                        this.bigResolutionScope = IsBig(2, module.ModuleTable, module.ModuleRef, module.AssemblyRef, module.TypeRef);
 
72
                        this.bigTypeDefOrRef = IsBig(2, module.TypeDef, module.TypeRef, module.TypeSpec);
 
73
                        this.bigMemberRefParent = IsBig(3, module.TypeDef, module.TypeRef, module.ModuleRef, module.MethodDef, module.TypeSpec);
 
74
                        this.bigMethodDefOrRef = IsBig(1, module.MethodDef, module.MemberRef);
 
75
                        this.bigHasCustomAttribute = IsBig(5, module.MethodDef, module.Field, module.TypeRef, module.TypeDef, module.Param, module.InterfaceImpl, module.MemberRef,
 
76
                                module.ModuleTable, /*module.Permission,*/ module.Property, module.Event, module.StandAloneSig, module.ModuleRef, module.TypeSpec, module.AssemblyTable,
 
77
                                module.AssemblyRef, module.File, module.ExportedType, module.ManifestResource);
 
78
                        this.bigCustomAttributeType = IsBig(3, module.MethodDef, module.MemberRef);
 
79
                        this.bigHasConstant = IsBig(2, module.Field, module.Param, module.Property);
 
80
                        this.bigHasSemantics = IsBig(1, module.Event, module.Property);
 
81
                        this.bigHasFieldMarshal = IsBig(1, module.Field, module.Param);
 
82
                        this.bigHasDeclSecurity = IsBig(2, module.TypeDef, module.MethodDef, module.AssemblyTable);
 
83
                        this.bigTypeOrMethodDef = IsBig(1, module.TypeDef, module.MethodDef);
 
84
                        this.bigMemberForwarded = IsBig(1, module.Field, module.MethodDef);
 
85
                        this.bigImplementation = IsBig(2, module.File, module.AssemblyRef, module.ExportedType);
 
86
                }
 
87
 
 
88
                private static bool IsBig(int bitsUsed, params Table[] tables)
 
89
                {
 
90
                        int limit = 1 << (16 - bitsUsed);
 
91
                        foreach (Table table in tables)
 
92
                        {
 
93
                                if (table.RowCount >= limit)
 
94
                                {
 
95
                                        return true;
 
96
                                }
 
97
                        }
 
98
                        return false;
 
99
                }
 
100
        }
 
101
}