Beispiel #1
0
        public void FieldModifiers()
        {
            var text =
@"
class A
{
    internal protected const long N1 = 0;
    public volatile byte N2 = 0;
    private static char N3 = ' ';
}
";
            var comp = CreateEmptyCompilation(text);
            var global = comp.GlobalNamespace;
            var a = global.GetTypeMembers("A", 0).Single();
            var n1 = a.GetMembers("N1").Single() as FieldSymbol;
            Assert.True(n1.IsConst);
            Assert.False(n1.IsVolatile);
            Assert.True(n1.IsStatic);
            Assert.Equal(0, n1.TypeWithAnnotations.CustomModifiers.Length);

            var n2 = a.GetMembers("N2").Single() as FieldSymbol;
            Assert.False(n2.IsConst);
            Assert.True(n2.IsVolatile);
            Assert.False(n2.IsStatic);
            Assert.Equal(1, n2.TypeWithAnnotations.CustomModifiers.Length);
            CustomModifier mod = n2.TypeWithAnnotations.CustomModifiers[0];
            Assert.False(mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsVolatile[missing]", mod.Modifier.ToTestDisplayString());

            var n3 = a.GetMembers("N3").Single() as FieldSymbol;
            Assert.False(n3.IsConst);
            Assert.False(n3.IsVolatile);
            Assert.True(n3.IsStatic);
            Assert.Equal(0, n3.TypeWithAnnotations.CustomModifiers.Length);
        }
        private static bool CustomModifiersMatch(ImmutableArray <CustomModifier> candidateCustomModifiers, ImmutableArray <ModifierInfo <TypeSymbol> > targetCustomModifiers)
        {
            if (targetCustomModifiers.IsDefault || targetCustomModifiers.IsEmpty)
            {
                return(candidateCustomModifiers.IsDefault || candidateCustomModifiers.IsEmpty);
            }
            else if (candidateCustomModifiers.IsDefault)
            {
                return(false);
            }

            var n = candidateCustomModifiers.Length;

            if (targetCustomModifiers.Length != n)
            {
                return(false);
            }

            for (int i = 0; i < n; i++)
            {
                var            targetCustomModifier    = targetCustomModifiers[i];
                CustomModifier candidateCustomModifier = candidateCustomModifiers[i];

                if (targetCustomModifier.IsOptional != candidateCustomModifier.IsOptional ||
                    !object.Equals(targetCustomModifier.Modifier, ((CSharpCustomModifier)candidateCustomModifier).ModifierSymbol))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
 private CustomModifier VisitCustomModifier(CustomModifier modifier)
 {
     var type = (NamedTypeSymbol)this.Visit((Symbol)modifier.Modifier);
     Debug.Assert((object)type != null);
     return modifier.IsOptional ?
         CSharpCustomModifier.CreateOptional(type) :
         CSharpCustomModifier.CreateRequired(type);
 }
Beispiel #4
0
        /*-------------------- Constructors ---------------------------------*/

        /// <summary>
        /// Create a new custom modifier for a type
        /// </summary>
        /// <param name="type">the type to be modified</param>
        /// <param name="cmod">the modifier</param>
        /// <param name="cmodType">the type reference to be associated with the type</param>
        public CustomModifiedType(Type type, CustomModifier cmod, Class cmodType)
            : base((byte)cmod)
        {
            Contract.Requires(type != null);
            Contract.Requires(cmodType != null);
            this.type     = type;
            this.cmodType = cmodType;
        }
Beispiel #5
0
 internal bool AreEquivalent(
     CustomModifier x,
     CustomModifier y,
     Dictionary <
         INamedTypeSymbol,
         INamedTypeSymbol
         >?equivalentTypesWithDifferingAssemblies
     ) =>
 x.IsOptional == y.IsOptional &&
 AreEquivalent(x.Modifier, y.Modifier, equivalentTypesWithDifferingAssemblies);
		/// <summary>
		/// Create a new custom modifier for a type
		/// </summary>
		/// <param name="type">the type to be modified</param>
		/// <param name="cmod">the modifier</param>
		/// <param name="cmodType">the type reference to be associated with the type</param>
		public CustomModifiedType(Type type, CustomModifier cmod, Class cmodType)
			: base((byte)cmod) 
		{
			this.type = type;
			this.cmodType = cmodType;
		}
Beispiel #7
0
        public void Test1()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(mrefs: new[]
            {
                TestReferences.SymbolsTests.Fields.CSFields.dll,
                TestReferences.SymbolsTests.Fields.VBFields.dll,
                TestReferences.NetFx.v4_0_21006.mscorlib
            },
                                                                         options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal));

            var module1 = assemblies[0].Modules[0];
            var module2 = assemblies[1].Modules[0];
            var module3 = assemblies[2].Modules[0];

            var vbFields = module2.GlobalNamespace.GetTypeMembers("VBFields").Single();
            var csFields = module1.GlobalNamespace.GetTypeMembers("CSFields").Single();

            var f1 = (FieldSymbol)vbFields.GetMembers("F1").Single();
            var f2 = (FieldSymbol)vbFields.GetMembers("F2").Single();
            var f3 = (FieldSymbol)vbFields.GetMembers("F3").Single();
            var f4 = (FieldSymbol)vbFields.GetMembers("F4").Single();
            var f5 = (FieldSymbol)vbFields.GetMembers("F5").Single();
            var f6 = (FieldSymbol)csFields.GetMembers("F6").Single();

            Assert.Equal("F1", f1.Name);
            Assert.Same(vbFields.TypeParameters[0], f1.Type);
            Assert.False(f1.IsAbstract);
            Assert.False(f1.IsConst);
            Assert.True(f1.IsDefinition);
            Assert.False(f1.IsExtern);
            Assert.False(f1.IsOverride);
            Assert.False(f1.IsReadOnly);
            Assert.False(f1.IsSealed);
            Assert.True(f1.IsStatic);
            Assert.False(f1.IsVirtual);
            Assert.False(f1.IsVolatile);
            Assert.Equal(SymbolKind.Field, f1.Kind);
            Assert.Equal(module2.Locations, f1.Locations);
            Assert.Same(f1, f1.OriginalDefinition);
            Assert.Equal(Accessibility.Public, f1.DeclaredAccessibility);
            Assert.Same(vbFields, f1.ContainingSymbol);
            Assert.Equal(0, f1.CustomModifiers.Length);

            Assert.Equal("F2", f2.Name);
            Assert.Same(((PEModuleSymbol)module2).GetCorLibType(SpecialType.System_Int32), f2.Type);
            Assert.False(f2.IsConst);
            Assert.True(f2.IsReadOnly);
            Assert.False(f2.IsStatic);
            Assert.False(f2.IsVolatile);
            Assert.Equal(Accessibility.Protected, f2.DeclaredAccessibility);
            Assert.Equal(0, f2.CustomModifiers.Length);

            Assert.Equal("F3", f3.Name);
            Assert.False(f3.IsConst);
            Assert.False(f3.IsReadOnly);
            Assert.False(f3.IsStatic);
            Assert.False(f3.IsVolatile);
            Assert.Equal(Accessibility.Internal, f3.DeclaredAccessibility);
            Assert.Equal(0, f3.CustomModifiers.Length);

            Assert.Equal("F4", f4.Name);
            Assert.False(f4.IsConst);
            Assert.False(f4.IsReadOnly);
            Assert.False(f4.IsStatic);
            Assert.False(f4.IsVolatile);
            Assert.Equal(Accessibility.ProtectedOrInternal, f4.DeclaredAccessibility);
            Assert.Equal(0, f4.CustomModifiers.Length);

            Assert.Equal("F5", f5.Name);
            Assert.True(f5.IsConst);
            Assert.False(f5.IsReadOnly);
            Assert.True(f5.IsStatic);
            Assert.False(f5.IsVolatile);
            Assert.Equal(Accessibility.Protected, f5.DeclaredAccessibility);
            Assert.Equal(0, f5.CustomModifiers.Length);

            Assert.Equal("F6", f6.Name);
            Assert.False(f6.IsConst);
            Assert.False(f6.IsReadOnly);
            Assert.False(f6.IsStatic);
            Assert.True(f6.IsVolatile);
            Assert.Equal(1, f6.CustomModifiers.Length);

            CustomModifier mod = f6.CustomModifiers[0];

            Assert.False(mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsVolatile", mod.Modifier.ToTestDisplayString());

            Assert.Equal(SymbolKind.NamedType, csFields.GetMembers("FFF").Single().Kind);
            Assert.Equal(SymbolKind.Field, csFields.GetMembers("Fff").Single().Kind);
            Assert.Equal(SymbolKind.Method, csFields.GetMembers("FfF").Single().Kind);
        }
 protected IEnumerable<ICustomModifier>/*?*/ GetCustomModifiers(out bool isPinned) {
   isPinned = false;
   List<ICustomModifier> customModifierList = null;
   ICustomModifier customModifier = null;
   while (this.SignatureMemoryReader.NotEndOfBytes) {
     byte header = this.SignatureMemoryReader.PeekByte(0);
     if (header == ElementType.Pinned) {
       this.SignatureMemoryReader.SkipBytes(1);
       isPinned = true;
       continue;
     }
     if (header != ElementType.RequiredModifier && header != ElementType.OptionalModifier)
       break;
     this.SignatureMemoryReader.SkipBytes(1);
     uint typeDefOrRefEncoded = (uint)this.SignatureMemoryReader.ReadCompressedUInt32();
     uint typeToken = TypeDefOrRefTag.ConvertToToken(typeDefOrRefEncoded);
     uint tokenType = typeToken & TokenTypeIds.TokenTypeMask;
     uint typeRID = typeToken & TokenTypeIds.RIDMask;
     ITypeReference/*?*/ typeRef = null;
     if (tokenType == TokenTypeIds.TypeDef)
       typeRef = this.PEFileToObjectModel.GetTypeDefinitionAtRow(typeRID);
     else if (tokenType == TokenTypeIds.TypeRef)
       typeRef = this.PEFileToObjectModel.GetTypeRefReferenceAtRow(typeRID);
     else
       typeRef = this.PEFileToObjectModel.GetTypeSpecReferenceAtRow(this.MetadataOwnerObject, typeRID).UnderlyingModuleTypeReference;
     if (typeRef == null) {
       //  Error...
       continue;
     }
     if (customModifier != null && customModifierList == null) {
       customModifierList = new List<ICustomModifier>(4);
       customModifierList.Add(customModifier);
     }
     customModifier = new CustomModifier(header == ElementType.OptionalModifier, typeRef);
     if (customModifierList != null) customModifierList.Add(customModifier);
   }
   if (this.SignatureMemoryReader.RemainingBytes <= 0) {
     //  TODO: Handle error...
   }
   if (customModifierList == null) {
     if (customModifier == null) return null;
     return IteratorHelper.GetSingletonEnumerable(customModifier);
   } else {
     return IteratorHelper.GetReadonly(customModifierList.ToArray());
   }
 }
Beispiel #9
0
		public CustomModifiedType(Type type, CustomModifier cmod, PrimitiveTypeRef cmodType)
			: base((byte)cmod)
		{
			this.type = type;
			this.cmodPrimType = cmodType;
		}
 protected EnumerableArrayWrapper<CustomModifier, ICustomModifier> GetCustomModifiers(
   out bool isPinned
 ) {
   isPinned = false;
   List<CustomModifier> customModifierList = new List<CustomModifier>();
   while (this.SignatureMemoryReader.NotEndOfBytes) {
     byte header = this.SignatureMemoryReader.PeekByte(0);
     if (header == ElementType.Pinned) {
       this.SignatureMemoryReader.SkipBytes(1);
       isPinned = true;
       continue;
     }
     if (header != ElementType.RequiredModifier && header != ElementType.OptionalModifier)
       break;
     this.SignatureMemoryReader.SkipBytes(1);
     CustomModifier customModifier;
     uint typeDefOrRefEncoded = (uint)this.SignatureMemoryReader.ReadCompressedUInt32();
     uint typeToken = TypeDefOrRefTag.ConvertToToken(typeDefOrRefEncoded);
     uint tokenType = typeToken & TokenTypeIds.TokenTypeMask;
     uint typeRID = typeToken & TokenTypeIds.RIDMask;
     ITypeReference/*?*/ typeRef = null;
     if (tokenType == TokenTypeIds.TypeDef) {
       typeRef = this.PEFileToObjectModel.GetTypeDefinitionAtRow(typeRID);
     } else if (tokenType == TokenTypeIds.TypeRef) {
       typeRef = this.PEFileToObjectModel.GetTypeRefReferenceAtRow(typeRID);
     } else {
       typeRef = this.PEFileToObjectModel.GetTypeSpecReferenceAtRow(this.MetadataOwnerObject, typeRID).UnderlyingModuleTypeReference;
     }
     if (typeRef == null) {
       //  Error...
       continue;
     }
     customModifier = new CustomModifier(header == ElementType.OptionalModifier, typeRef);
     customModifierList.Add(customModifier);
   }
   if (this.SignatureMemoryReader.RemainingBytes <= 0) {
     //  TODO: Handle error...
   }
   if (customModifierList.Count == 0) {
     return TypeCache.EmptyCustomModifierArray;
   } else {
     return new EnumerableArrayWrapper<CustomModifier, ICustomModifier>(customModifierList.ToArray(), Dummy.CustomModifier);
   }
 }
Beispiel #11
0
 public static NamedTypeSymbol Modifier(this CustomModifier m)
 {
     return(((CSharpCustomModifier)m).ModifierSymbol);
 }
Beispiel #12
0
 public void SetModifier(CustomModifier cmod)
 {
     typeIndex = (byte) cmod;
 }
Beispiel #13
0
    public static string currentDice = "d20"; //default

    private void Start()
    {
        proficiency    = GameObject.Find("ProficiencyToggle").GetComponent <Toggle>();
        expertise      = GameObject.Find("ExpertiseToggle").GetComponent <Toggle>();
        customModifier = GameObject.Find("CustomModifier").GetComponent <CustomModifier>();
    }
 internal bool AreEquivalent(CustomModifier x, CustomModifier y, Dictionary<INamedTypeSymbol, INamedTypeSymbol> equivalentTypesWithDifferingAssemblies)
 {
     return x.IsOptional == y.IsOptional && AreEquivalent(x.Modifier, y.Modifier, equivalentTypesWithDifferingAssemblies);
 }
Beispiel #15
0
 /*-------------------- Constructors ---------------------------------*/
 /// <summary>
 /// Create a new custom modifier for a type
 /// </summary>
 /// <param name="type">the type to be modified</param>
 /// <param name="cmod">the modifier</param>
 /// <param name="cmodType">the type reference to be associated with the type</param>
 public CustomModifiedType(Type type, CustomModifier cmod, Class cmodType)
     : base((byte)cmod)
 {
     Contract.Requires(type != null);
     Contract.Requires(cmodType != null);
     this.type = type;
     this.cmodType = cmodType;
 }
Beispiel #16
0
 public void SetModifier(CustomModifier cmod)
 {
     typeIndex = (byte)cmod;
 }