예제 #1
0
        /// <summary>
        /// Returns a reference to the unit that defines the given referenced type. If the referenced type is a structural type, such as a pointer or a generic type instance,
        /// then the result is null.
        /// </summary>
        public static IUnitReference /*?*/ GetDefiningUnitReference(ITypeReference typeReference, EmitContext context)
        {
            INestedTypeReference /*?*/ nestedTypeReference = typeReference.AsNestedTypeReference;

            while (nestedTypeReference != null)
            {
                if (nestedTypeReference.AsGenericTypeInstanceReference != null)
                {
                    return(null);
                }

                typeReference       = nestedTypeReference.GetContainingType(context);
                nestedTypeReference = typeReference.AsNestedTypeReference;
            }

            INamespaceTypeReference /*?*/ namespaceTypeReference = typeReference.AsNamespaceTypeReference;

            if (namespaceTypeReference == null)
            {
                return(null);
            }

            Debug.Assert(namespaceTypeReference.AsGenericTypeInstanceReference == null);

            return(namespaceTypeReference.GetUnit(context));
        }
예제 #2
0
        public static string GetTypeFullName(this INamespaceTypeReference t)
        {
            var nsPart   = TypeHelper.GetNamespaceName(t.ContainingUnitNamespace, NameFormattingOptions.None);
            var typePart = t.Name.Value + (t.MangleName ? "`" + t.GenericParameterCount : "");

            return(nsPart + "." + typePart);
        }
예제 #3
0
        private CCI2Slicer(HostEnvironment host)
        {
            Contract.Requires(host != null);

            this.host         = host;
            this.systemString = this.host.PlatformType.SystemString;
            this.systemInt    = this.host.PlatformType.SystemInt32;
        }
 public override void Visit(INamespaceTypeReference namespaceTypeReference)
 {
     if (Process(namespaceTypeReference))
     {
         visitor.Visit(namespaceTypeReference);
     }
     base.Visit(namespaceTypeReference);
 }
예제 #5
0
        public override void Visit(INamespaceTypeReference type)
        {
            INamespaceTypeReference typeRef = (INamespaceTypeReference)Util.CanonicalizeType(type);

            // The type can resolve to an external assembly, so we need to check whether we can include the external assembly.
            if (m_implModel.CanInclude(typeRef))
            {
                Visit(Util.ResolveTypeThrowing(typeRef));
            }
        }
예제 #6
0
    public override void TraverseChildren(INamespaceTypeReference namespaceTypeReference)
    {
        var typ = namespaceTypeReference.ResolvedType;

        if (typ == Dummy.Type)
        {
            this.EmitError(namespaceTypeReference, ErrorCode.NamespaceTypeResolution);
        }
        base.TraverseChildren(namespaceTypeReference);
    }
예제 #7
0
        private static void AppendAssemblyQualifierIfNecessary(StringBuilder sb, ITypeReference typeReference, out bool isAssemQualified, EmitContext context)
        {
            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, nestedType.GetContainingType(context), out isAssemQualified, context);
                return;
            }

            IGenericTypeInstanceReference genInst = typeReference.AsGenericTypeInstanceReference;

            if (genInst != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, genInst.GetGenericType(context), out isAssemQualified, context);
                return;
            }

            IArrayTypeReference arrType = typeReference as IArrayTypeReference;

            if (arrType != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, arrType.GetElementType(context), out isAssemQualified, context);
                return;
            }

            IPointerTypeReference pointer = typeReference as IPointerTypeReference;

            if (pointer != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, pointer.GetTargetType(context), out isAssemQualified, context);
                return;
            }

            isAssemQualified = false;
            IAssemblyReference      referencedAssembly = null;
            INamespaceTypeReference namespaceType      = typeReference.AsNamespaceTypeReference;

            if (namespaceType != null)
            {
                referencedAssembly = namespaceType.GetUnit(context) as IAssemblyReference;
            }

            if (referencedAssembly != null)
            {
                var containingAssembly = context.Module.GetContainingAssembly(context);

                if (containingAssembly == null || !ReferenceEquals(referencedAssembly, containingAssembly))
                {
                    sb.Append(", ");
                    sb.Append(MetadataWriter.StrongName(referencedAssembly));
                    isAssemQualified = true;
                }
            }
        }
예제 #8
0
        private string SerializeVisualBasicImportTypeReference(ITypeReference typeReference)
        {
            Debug.Assert(!(typeReference is IArrayTypeReference));
            Debug.Assert(!(typeReference is IPointerTypeReference));
            Debug.Assert(!(typeReference is IManagedPointerTypeReference));
            Debug.Assert(!typeReference.IsTypeSpecification());

            var result = PooledStringBuilder.GetInstance();
            ArrayBuilder <string> nestedNamesReversed;

            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                nestedNamesReversed = ArrayBuilder <string> .GetInstance();

                while (nestedType != null)
                {
                    nestedNamesReversed.Add(nestedType.Name);
                    typeReference = nestedType.GetContainingType(_metadataWriter.Context);
                    nestedType    = typeReference.AsNestedTypeReference;
                }
            }
            else
            {
                nestedNamesReversed = null;
            }

            INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference;

            Debug.Assert(namespaceType != null);

            string namespaceName = namespaceType.NamespaceName;

            if (namespaceName.Length != 0)
            {
                result.Builder.Append(namespaceName);
                result.Builder.Append('.');
            }

            result.Builder.Append(namespaceType.Name);

            if (nestedNamesReversed != null)
            {
                for (int i = nestedNamesReversed.Count - 1; i >= 0; i--)
                {
                    result.Builder.Append('.');
                    result.Builder.Append(nestedNamesReversed[i]);
                }

                nestedNamesReversed.Free();
            }

            return(result.ToStringAndFree());
        }
예제 #9
0
 /// <summary>
 /// Need this override because when a GenericTypeInstanceReference is rewritten, its GenericType is visited
 /// as an INamespaceTypeReference and so the above override is never executed.
 /// </summary>
 public override INamespaceTypeReference Rewrite(INamespaceTypeReference namespaceTypeReference)
 {
     if (namespaceTypeReference.InternedKey == this.contractClass.InternedKey && this.abstractType is INamespaceTypeReference)
     {
         return((INamespaceTypeReference)this.abstractType);
     }
     else
     {
         return(base.Rewrite(namespaceTypeReference));
     }
 }
예제 #10
0
        public override void Visit(INamespaceTypeReference type)
        {
            ITypeDefinition typeDef = type.ResolvedType;

            if (typeDef.IsDummy())
            {
                AddUnresolvedReference(type);
            }

            base.Visit(type);
        }
예제 #11
0
        static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("usage: FindThrowArgumentNull [path]fileName.ext");
                return;
            }

            using (var host = new PeReader.DefaultHost()) {
                var module = host.LoadUnitFrom(args[0]) as IModule;

                if (module == null)
                {
                    Console.WriteLine(args[0] + " is not a PE file containing a CLR module or assembly.");
                    return;
                }

                var platformType = new MyPlatformType(host);
                INamespaceTypeReference systemArgumentNullException = platformType.SystemArgumentNullException;
                IName ctor = host.NameTable.Ctor;

                //write out the signature of every method that contains the IL equivalent of "throw new System.ArgumentNullException();"
                foreach (var type in module.GetAllTypes())
                {
                    foreach (var methodDefinition in type.Methods)
                    {
                        var lastInstructionWasNewObjSystemArgumentNull = false;
                        foreach (var operation in methodDefinition.Body.Operations)
                        {
                            if (operation.OperationCode == OperationCode.Newobj)
                            {
                                var consRef = operation.Value as IMethodReference;
                                if (consRef != null && consRef.Name == ctor &&
                                    TypeHelper.TypesAreEquivalent(consRef.ContainingType, systemArgumentNullException))
                                {
                                    lastInstructionWasNewObjSystemArgumentNull = true;
                                }
                            }
                            else if (lastInstructionWasNewObjSystemArgumentNull && operation.OperationCode == OperationCode.Throw)
                            {
                                Console.WriteLine(MemberHelper.GetMethodSignature(methodDefinition,
                                                                                  NameFormattingOptions.ReturnType | NameFormattingOptions.TypeParameters | NameFormattingOptions.Signature));
                                break;
                            }
                            else
                            {
                                lastInstructionWasNewObjSystemArgumentNull = false;
                            }
                        }
                    }
                }
            }
        }
예제 #12
0
        public override INamespaceTypeReference Rewrite(INamespaceTypeReference namespaceTypeReference)
        {
            namespaceTypeReference = base.Rewrite(namespaceTypeReference);
            var unit = TypeHelper.GetDefiningUnitReference(namespaceTypeReference);

            if (unit == this.mergedModule)
            {
                var resolvedType = namespaceTypeReference.ResolvedType;
                Contract.Assume(!(resolvedType is Dummy));
                return(resolvedType);
            }
            return(namespaceTypeReference);
        }
        public override void TraverseChildren(IMethodCall methodCall)
        {
            if (PhoneCodeHelper.instance().PhoneFeedbackToggled)
            {
                // check for handlers we do not wish to add feedback checks to
                if (methodCall.MethodToCall.Name.Value.StartsWith("add_"))
                {
                    string eventName = methodCall.MethodToCall.Name.Value.Remove(0, "add_".Length);
                    if (PhoneCodeHelper.IgnoredEvents.Contains(eventName))
                    {
                        IMethodReference eventHandler = null;
                        foreach (IExpression arg in methodCall.Arguments)
                        {
                            ICreateDelegateInstance createDelegate = arg as ICreateDelegateInstance;
                            if (createDelegate == null)
                            {
                                continue;
                            }

                            ITypeReference typeRef = createDelegate.Type;
                            if (!typeRef.isRoutedEventHandlerClass(host))
                            {
                                continue;
                            }

                            eventHandler = createDelegate.MethodToCallViaDelegate;
                            break;
                        }

                        if (eventHandler != null)
                        {
                            INamespaceTypeReference namedType = eventHandler.ContainingType.ResolvedType as INamespaceTypeReference;
                            if (namedType != null)
                            {
                                INamespaceTypeDefinition namedTypeDef = namedType.ResolvedType;
                                if (namedTypeDef != null)
                                {
                                    PhoneCodeHelper.instance().ignoreEventHandler(namedTypeDef.ContainingUnitNamespace.Name + "." + namedTypeDef.Name + "." + eventHandler.Name);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #14
0
        private static void trackControlVariableName(IFieldDefinition fieldDefinition, Bpl.Variable fieldVar)
        {
            INamespaceTypeReference namedContainerRef = fieldDefinition.ContainingType as INamespaceTypeReference;

            if (namedContainerRef != null)
            {
                string containerName = namedContainerRef.ContainingUnitNamespace.Unit.Name.Value + "." + namedContainerRef.Name.Value;
                IEnumerable <ControlInfoStructure> controls = PhoneCodeHelper.instance().PhonePlugin.getControlsForPage(containerName);
                if (controls != null)
                {
                    ControlInfoStructure ctrlInfo = controls.FirstOrDefault(ctrl => ctrl.Name == fieldDefinition.Name.Value);
                    if (ctrlInfo != null)
                    {
                        ctrlInfo.BplName = fieldVar.Name;
                    }
                }
            }
        }
예제 #15
0
        public static string GetNamespaceName(this ITypeReference type)
        {
            INamespaceTypeReference nsType = type as INamespaceTypeReference;

            if (nsType != null)
            {
                return(TypeHelper.GetNamespaceName(nsType.ContainingUnitNamespace, NameFormattingOptions.None));
            }

            INestedTypeReference ntType = type as INestedTypeReference;

            if (ntType != null)
            {
                return(GetNamespaceName(ntType.ContainingType));
            }

            return("");
        }
예제 #16
0
        private static IEnumerable <string> AllNamespaces(this ITypeDefinition type)
        {
            INestedTypeDefinition nestedType = type as INestedTypeDefinition;

            if (nestedType != null)
            {
                return(nestedType.AllNamespaces());
            }

            INamespaceTypeReference namespaceType = type as INamespaceTypeReference;

            if (namespaceType != null)
            {
                return(namespaceType.AllNamespaces());
            }

            return("".Return());
        }
예제 #17
0
        private Prune(
            IMetadataHost host,
            MetadataDeepCopier copier,
            HashSet <object> thingsToKeep,
            HashSet <uint> methodsWhoseBodiesShouldBeKept,
            IDictionary <IMethodDefinition, MethodHashAttribute> methodHashAttributes
            )
            : base(host)
        {
            Contract.Requires(host != null);
            Contract.Requires(copier != null);
            Contract.Requires(thingsToKeep != null);
            Contract.Requires(methodsWhoseBodiesShouldBeKept != null);
            Contract.Requires(methodHashAttributes != null);

            this.copier               = copier;
            this.thingsToKeep         = thingsToKeep;
            this.methodDefsToKeep     = methodsWhoseBodiesShouldBeKept;
            this.methodHashAttributes = methodHashAttributes;

            this.systemInt    = host.PlatformType.SystemInt32;
            this.systemString = host.PlatformType.SystemString;
        }
예제 #18
0
        public override INamespaceTypeReference Rewrite(INamespaceTypeReference namespaceTypeReference)
        {
            if (TypeHelper.GetDefiningUnitReference(namespaceTypeReference) != this.assembly)
            {
                return(namespaceTypeReference);
            }
            var mutableNamespaceTypeReference = namespaceTypeReference as Microsoft.Cci.MutableCodeModel.NamespaceTypeReference;

            if (mutableNamespaceTypeReference == null || mutableNamespaceTypeReference.IsFrozen)
            {
                return(namespaceTypeReference);
            }
            object result;

            if (this.referenceRewrites.TryGetValue(mutableNamespaceTypeReference, out result))
            {
                return((INamespaceTypeReference)result);
            }
            this.referenceRewrites[mutableNamespaceTypeReference] = mutableNamespaceTypeReference;
            mutableNamespaceTypeReference.Name = this.host.NameTable.GetNameFor(this.pattern.Replace(namespaceTypeReference.Name.Value, this.evaluator));
            this.RewriteChildren(mutableNamespaceTypeReference);
            return(mutableNamespaceTypeReference);
        }
예제 #19
0
        ILocalDefinition addDeadLocal(string targetType)
        {
            LocalDefinition result = new LocalDefinition();

            result.IsReference      = result.IsPinned = result.IsModified = false;
            result.MethodDefinition = methodCfg.method;

            // Switch for local type (TODO: Support more).
            // Maybe create multiple variables of the same type to add diffusion (but add upper bound).
            INamespaceTypeReference type = null;

            switch (targetType)
            {
            case "System.Int32":   type = host.PlatformType.SystemInt32; break;

            case "System.String":  type = host.PlatformType.SystemString; break;

            case "System.Boolean": type = host.PlatformType.SystemBoolean; break;

            default:
                throw new ArgumentException("Cannot add dead local of unsupported type.");
            }

            // Add the new local variable to our method.
            result.Type = type;
            manipulator.addLocalVariable(result);

            // Initialize dead local variable in the method's first basic block according to its type.
            // TODO: This might be used to easily detect dead locals. Improve on this.
            var loadSequence = loadBogusParameter(type);

            loadSequence.Add(createNewOperation(OperationCode.Stloc, result));

            methodCfg.startBasicBlock.operations.InsertRange(0, loadSequence);
            return(result);
        }
예제 #20
0
    private Prune(
      IMetadataHost host,
      MetadataDeepCopier copier,
      HashSet<object> thingsToKeep,
      HashSet<uint> methodsWhoseBodiesShouldBeKept,
      IDictionary<IMethodDefinition, MethodHashAttribute> methodHashAttributes
      )
      : base(host) {

      Contract.Requires(host != null);
      Contract.Requires(copier != null);
      Contract.Requires(thingsToKeep != null);
      Contract.Requires(methodsWhoseBodiesShouldBeKept != null);
      Contract.Requires(methodHashAttributes != null);

      this.copier = copier;
      this.thingsToKeep = thingsToKeep;
      this.methodDefsToKeep = methodsWhoseBodiesShouldBeKept;
      this.methodHashAttributes = methodHashAttributes;

      this.systemInt = host.PlatformType.SystemInt32;
      this.systemString = host.PlatformType.SystemString;

    }
예제 #21
0
        public override void Visit(INamespaceTypeReference namespaceTypeReference)
        {
            var assemblyReference = namespaceTypeReference.ContainingUnitNamespace.Unit as IAssemblyReference;

            if (assemblyReference != null)
            {
                var assembly = this.mapper.GetAssembly(assemblyReference);
                this.result = assembly.GetType(TypeHelper.GetTypeName(namespaceTypeReference, NameFormattingOptions.UseGenericTypeNameSuffix));
                if (this.result == null && namespaceTypeReference.GenericParameterCount > 0)
                {
                    this.result = assembly.GetType(TypeHelper.GetTypeName(namespaceTypeReference));
                }
            }
            else
            {
                var mod    = (IModuleReference)namespaceTypeReference.ContainingUnitNamespace.Unit;
                var module = this.mapper.GetModule(mod);
                this.result = module.GetType(TypeHelper.GetTypeName(namespaceTypeReference, NameFormattingOptions.UseGenericTypeNameSuffix));
                if (this.result == null && namespaceTypeReference.GenericParameterCount > 0)
                {
                    this.result = module.GetType(TypeHelper.GetTypeName(namespaceTypeReference));
                }
            }
        }
예제 #22
0
        public override void Visit(INamespaceTypeReference namespaceTypeReference)
        {
            if (!this.typeReferenceNeedsToken && namespaceTypeReference.TypeCode(Context) != PrimitiveTypeCode.NotPrimitive)
            {
                return;
            }

            RecordTypeReference(namespaceTypeReference);

            var unit = namespaceTypeReference.GetUnit(Context);

            var assemblyReference = unit as IAssemblyReference;

            if (assemblyReference != null)
            {
                this.Visit(assemblyReference);
            }
            else
            {
                var moduleReference = unit as IModuleReference;
                if (moduleReference != null)
                {
                    // If this is a module from a referenced multi-module assembly,
                    // the assembly should be used as the resolution scope.
                    assemblyReference = moduleReference.GetContainingAssembly(Context);
                    if (assemblyReference != null && assemblyReference != this.module.AsAssembly)
                    {
                        this.Visit(assemblyReference);
                    }
                    else
                    {
                        this.Visit(moduleReference);
                    }
                }
            }
        }
예제 #23
0
 public void Visit(INamespaceTypeReference namespaceTypeReference)
 {
     this.traverser.Traverse(namespaceTypeReference);
 }
예제 #24
0
        public override void TraverseChildren(INamespaceTypeReference namespaceTypeReference)
{ MethodEnter(namespaceTypeReference);
            base.TraverseChildren(namespaceTypeReference);
     MethodExit();   }
예제 #25
0
 public virtual void onMetadataElement(INamespaceTypeReference namespaceTypeReference) { }
 public override void TraverseChildren(INamespaceTypeReference namespaceTypeReference) {
   base.TraverseChildren(namespaceTypeReference);
 }
예제 #27
0
        /// <summary>
        /// Use this routine, rather than ITypeReference.Dispatch, to call the appropriate derived overload of an ITypeReference.
        /// The former routine will call Visit(INamespaceTypeDefinition) rather than Visit(INamespaceTypeReference), etc.,
        /// in the case where a definition is used as a reference to itself.
        /// </summary>
        /// <param name="typeReference">A reference to a type definition. Note that a type definition can serve as a reference to itself.</param>
        protected void DispatchAsReference(ITypeReference typeReference)
        {
            INamespaceTypeReference namespaceTypeReference = typeReference.AsNamespaceTypeReference;

            if (namespaceTypeReference != null)
            {
                this.Visit(namespaceTypeReference);
                return;
            }

            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                this.Visit(genericTypeInstanceReference);
                return;
            }

            INestedTypeReference nestedTypeReference = typeReference.AsNestedTypeReference;

            if (nestedTypeReference != null)
            {
                this.Visit(nestedTypeReference);
                return;
            }

            IArrayTypeReference arrayTypeReference = typeReference as IArrayTypeReference;

            if (arrayTypeReference != null)
            {
                this.Visit(arrayTypeReference);
                return;
            }

            IGenericTypeParameterReference genericTypeParameterReference = typeReference.AsGenericTypeParameterReference;

            if (genericTypeParameterReference != null)
            {
                this.Visit(genericTypeParameterReference);
                return;
            }

            IGenericMethodParameterReference genericMethodParameterReference = typeReference.AsGenericMethodParameterReference;

            if (genericMethodParameterReference != null)
            {
                this.Visit(genericMethodParameterReference);
                return;
            }

            IPointerTypeReference pointerTypeReference = typeReference as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                this.Visit(pointerTypeReference);
                return;
            }

            IModifiedTypeReference modifiedTypeReference = typeReference as IModifiedTypeReference;

            if (modifiedTypeReference != null)
            {
                this.Visit(modifiedTypeReference);
                return;
            }
        }
예제 #28
0
 /// <summary>
 /// Performs some computation with the given namespace type reference.
 /// </summary>
 public void Visit(INamespaceTypeReference namespaceTypeReference)
 {
     this.Visit((INamedTypeReference)namespaceTypeReference);
 }
예제 #29
0
파일: Duplicator.cs 프로젝트: xornand/cci
 /// <summary>
 /// Leaves namespace type references alone since they cannot involve type parameters of the target class or method.
 /// </summary>
 /// <param name="namespaceTypeReference">The namespace type reference.</param>
 public override INamespaceTypeReference Visit(INamespaceTypeReference namespaceTypeReference)
 {
     return(namespaceTypeReference);
 }
    private void InitializeTraverser() {
      Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;
      coreAssemblyRef = platform.CoreAssemblyRef;

      // TODO obtain version, culture and signature data dynamically
      AssemblyIdentity MSPhoneAssemblyId =
          new AssemblyIdentity(host.NameTable.GetNameFor("Microsoft.Phone"), "", new Version("7.0.0.0"),
                               new byte[] { 0x24, 0xEE, 0xC0, 0xD8, 0xC8, 0x6C, 0xDA, 0x1E }, "");
      AssemblyIdentity MSPhoneControlsAssemblyId=
          new AssemblyIdentity(host.NameTable.GetNameFor("Microsoft.Phone.Controls"), "", new Version("7.0.0.0"),
                               new byte[] { 0x24, 0xEE, 0xC0, 0xD8, 0xC8, 0x6C, 0xDA, 0x1E }, "");

      AssemblyIdentity MSPhoneSystemWindowsAssemblyId =
          new AssemblyIdentity(host.NameTable.GetNameFor("System.Windows"), coreAssemblyRef.Culture, coreAssemblyRef.Version,
                               coreAssemblyRef.PublicKeyToken, "");

      phoneAssembly = host.FindAssembly(MSPhoneAssemblyId);
      phoneSystemWindowsAssembly = host.FindAssembly(MSPhoneSystemWindowsAssemblyId);
      MSPhoneControlsAssembly= host.FindAssembly(MSPhoneControlsAssemblyId);
      // TODO BUG / XAML DEPENDENCE If a control is declared in XAML, it may be one from a library *not* linked! So, assemblies could be dummy here

      // TODO determine the needed types dynamically
      if (phoneAssembly != Dummy.Assembly) {
        appBarIconButtonType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarIconButton");
        appBarMenuItemType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarMenuItem");
      } else {
        appBarIconButtonType = host.PlatformType.SystemObject;
        appBarMenuItemType = host.PlatformType.SystemObject;
      }

      if (phoneSystemWindowsAssembly != Dummy.Assembly) {
        checkBoxType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "CheckBox");
        radioButtonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "RadioButton");
        buttonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Button");
        buttonBaseType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Primitives", "ButtonBase");
        toggleButtonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Primitives", "ToggleButton");
        controlType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Control");
        uiElementType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "UIElement");
        listBoxType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "ListBox");
      } else {
        checkBoxType = host.PlatformType.SystemObject;
        radioButtonType = host.PlatformType.SystemObject;
        buttonType = host.PlatformType.SystemObject;
        buttonBaseType = host.PlatformType.SystemObject;
        toggleButtonType = host.PlatformType.SystemObject;
        controlType = host.PlatformType.SystemObject;
        uiElementType = host.PlatformType.SystemObject;
        listBoxType = host.PlatformType.SystemObject;
      }

      if (MSPhoneControlsAssembly != Dummy.Assembly) {
        pivotType = platform.CreateReference(MSPhoneControlsAssembly, "Microsoft", "Phone", "Controls", "Pivot");
      } else {
        pivotType = host.PlatformType.SystemObject;
      }

      

      trueConstant = new CompileTimeConstant() {
        Type = platform.SystemBoolean,
        Value = true
      };
      falseConstant = new CompileTimeConstant() {
        Type = platform.SystemBoolean,
        Value = false
      };

      IEnumerable<IPropertyDefinition> controlProperties = controlType.ResolvedType.Properties;
      IEnumerable<IPropertyDefinition> toggleButtonProperties = toggleButtonType.ResolvedType.Properties;
      IEnumerable<IPropertyDefinition> uiElementProperties = uiElementType.ResolvedType.Properties;

      IPropertyDefinition prop = controlProperties.Single(p => p.Name.Value == "IsEnabled");
      isEnabledSetter = prop.Setter;
      isEnabledGetter = prop.Getter;
      prop = toggleButtonProperties.Single(p => p.Name.Value == "IsChecked");
      isCheckedSetter = prop.Setter;
      isCheckedGetter = prop.Getter;
      prop = uiElementProperties.Single(p => p.Name.Value == "Visibility");
      visibilitySetter = prop.Setter;
      visibilityGetter = prop.Getter;

      IEnumerable<IEventDefinition> buttonBaseEvents = buttonBaseType.ResolvedType.Events;
      IEnumerable<IEventDefinition> toggleButtonEvents = toggleButtonType.ResolvedType.Events;
      IEventDefinition evt = buttonBaseEvents.Single(e => e.Name.Value == "Click");
      clickHandlerAdder = evt.Adder;
      clickHandlerRemover = evt.Remover;
      evt = toggleButtonEvents.Single(e => e.Name.Value == "Checked");
      checkedHandlerAdder = evt.Adder;
      checkedHandlerRemover = evt.Remover;
      evt = toggleButtonEvents.Single(e => e.Name.Value == "Unchecked");
      uncheckedHandlerAdder = evt.Adder;
      uncheckedHandlerRemover = evt.Remover;
    }
 public override void Visit(INamespaceTypeReference type)
 {
     base.Visit(type);
     AddAssemblyReference(type.GetAssemblyReference());
 }
예제 #32
0
파일: Duplicator.cs 프로젝트: xornand/cci
 /// <summary>
 /// Leaves namespace type references alone since they cannot involve type parameters of the target class or method.
 /// </summary>
 /// <param name="namespaceTypeReference">The namespace type reference.</param>
 public override INamespaceTypeReference Visit(INamespaceTypeReference namespaceTypeReference) {
   return namespaceTypeReference;
 }
예제 #33
0
 /// <summary>
 /// Performs some computation with the given namespace type reference.
 /// </summary>
 /// <param name="namespaceTypeReference"></param>
 public virtual void Visit(INamespaceTypeReference namespaceTypeReference)
   //^ ensures this.path.Count == old(this.path.Count);
 {
 }
예제 #34
0
        private static void WriteType(ITypeReference type, TextWriter writer, bool omitOutermostTypeFormals)
        {
            Contract.Requires(type != null);
            Contract.Requires(writer != null);

            IArrayType array = type as IArrayType;

            if (array != null)
            {
                Contract.Assume(array.ElementType != null, "lack of CCI2 contracts");

                WriteType(array.ElementType, writer);
                writer.Write("[");
                if (array.Rank > 1)
                {
                    for (int i = 0; i < array.Rank; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(",");
                        }
                        writer.Write("0:");
                    }
                }
                writer.Write("]");
                return;
            }

            IManagedPointerTypeReference reference = type as IManagedPointerTypeReference;;

            if (reference != null)
            {
                Contract.Assume(reference.TargetType != null, "lack of CCI2 contracts");

                var referencedType = reference.TargetType;
                WriteType(referencedType, writer);
                writer.Write("@");
                return;
            }

            IPointerTypeReference pointer = type as IPointerTypeReference;

            if (pointer != null)
            {
                Contract.Assume(pointer.TargetType != null, "lack of CCI2 contracts");

                WriteType(pointer.TargetType, writer);
                writer.Write("*");
                return;
            }

            IModifiedTypeReference modref = type as IModifiedTypeReference;

            if (modref != null)
            {
                Contract.Assume(modref.UnmodifiedType != null, "lack of CCI2 contracts");
                Contract.Assume(modref.CustomModifiers != null, "lack of CCI2 contracts");

                WriteType(modref.UnmodifiedType, writer);
                foreach (var modifier in modref.CustomModifiers)
                {
                    Contract.Assume(modifier != null, "lack of collection contracts and CCI2 contracts");
                    Contract.Assume(modifier.Modifier != null, "lack of CCI2 contracts");

                    if (modifier.IsOptional)
                    {
                        writer.Write("!");
                    }
                    else
                    {
                        writer.Write("|");
                    }
                    WriteType(modifier.Modifier, writer);
                }
                return;
            }

            IGenericTypeParameterReference gtp = type as IGenericTypeParameterReference;

            if (gtp != null)
            {
                writer.Write("`");
                writer.Write(gtp.Index);
                return;
            }
            IGenericMethodParameterReference gmp = type as IGenericMethodParameterReference;

            if (gmp != null)
            {
                writer.Write("``");
                writer.Write(gmp.Index);
                return;
            }

            IGenericTypeInstanceReference instance = type as IGenericTypeInstanceReference;

            if (instance != null)
            {
                Contract.Assume(instance.GenericType != null, "lack of CCI2 contracts");
                Contract.Assume(instance.GenericArguments != null, "lack of CCI2 contracts");

                WriteType(instance.GenericType, writer, true);
                writer.Write("{");
                var first = true;
                foreach (var arg in instance.GenericArguments)
                {
                    Contract.Assume(arg != null, "lack of collection and CCI2 contracts");

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(",");
                    }
                    WriteType(arg, writer);
                }
                writer.Write("}");
                return;
            }

            // namespace or nested
            INamedTypeReference  named  = (INamedTypeReference)type;
            INestedTypeReference nested = type as INestedTypeReference;

            if (nested != null)
            {
                Contract.Assume(nested.ContainingType != null, "lack of CCI2 contracts");

                // names of nested types begin with outer type name
                WriteType(nested.ContainingType, writer);
                writer.Write(".");
                // continue to write type sig
            }

            INamespaceTypeReference nt = type as INamespaceTypeReference;

            if (nt != null)
            {
                Contract.Assume(nt.ContainingUnitNamespace != null, "lack of CCI2 contracts");

                WriteNamespaceAndSeparator(nt.ContainingUnitNamespace, writer);
                // continue to write type sig
            }
            // name
            writer.Write(named.Name.Value);
            // generic parameters
            if (omitOutermostTypeFormals)
            {
                return;
            }

            if (named.GenericParameterCount > 0)
            {
                writer.Write("`{0}", named.GenericParameterCount);
            }
        }
예제 #35
0
 public virtual void onMetadataElement(INamespaceTypeReference namespaceTypeReference)
 {
 }
예제 #36
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given namespace type reference.
 /// </summary>
 /// <param name="namespaceTypeReference"></param>
 public virtual void Visit(INamespaceTypeReference namespaceTypeReference)
 {
 }
예제 #37
0
 public override void TraverseChildren(INamespaceTypeReference namespaceTypeReference) {
   this.TraverseChildren(namespaceTypeReference.ResolvedType);
 }
 /// <summary>
 /// Rewrites the given namespace type reference.
 /// </summary>
 public virtual INamespaceTypeReference Rewrite(INamespaceTypeReference namespaceTypeReference)
 {
     return namespaceTypeReference;
 }
 public override void Visit(INamespaceTypeReference namespaceTypeReference)
 {
     if(Process(namespaceTypeReference)){visitor.Visit(namespaceTypeReference);}
     base.Visit(namespaceTypeReference);
 }
예제 #40
0
        internal static string GetSerializedTypeName(this ITypeReference typeReference, EmitContext context, ref bool isAssemblyQualified)
        {
            var                 pooled  = PooledStringBuilder.GetInstance();
            StringBuilder       sb      = pooled.Builder;
            IArrayTypeReference arrType = typeReference as IArrayTypeReference;

            if (arrType != null)
            {
                typeReference = arrType.GetElementType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                if (arrType.IsSZArray)
                {
                    sb.Append("[]");
                }
                else
                {
                    sb.Append('[');
                    if (arrType.Rank == 1)
                    {
                        sb.Append('*');
                    }

                    sb.Append(',', (int)arrType.Rank - 1);

                    sb.Append(']');
                }

                goto done;
            }

            IPointerTypeReference pointer = typeReference as IPointerTypeReference;

            if (pointer != null)
            {
                typeReference = pointer.GetTargetType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                sb.Append('*');
                goto done;
            }

            INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference;

            if (namespaceType != null)
            {
                var name = namespaceType.NamespaceName;
                if (name.Length != 0)
                {
                    sb.Append(name);
                    sb.Append('.');
                }

                sb.Append(GetMangledAndEscapedName(namespaceType));
                goto done;
            }


            if (typeReference.IsTypeSpecification())
            {
                ITypeReference uninstantiatedTypeReference = typeReference.GetUninstantiatedGenericType(context);

                ArrayBuilder <ITypeReference> consolidatedTypeArguments = ArrayBuilder <ITypeReference> .GetInstance();

                typeReference.GetConsolidatedTypeArguments(consolidatedTypeArguments, context);

                bool uninstantiatedTypeIsAssemblyQualified = false;
                sb.Append(GetSerializedTypeName(uninstantiatedTypeReference, context, ref uninstantiatedTypeIsAssemblyQualified));
                sb.Append('[');
                bool first = true;
                foreach (ITypeReference argument in consolidatedTypeArguments)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(',');
                    }

                    bool isAssemQual = true;
                    AppendSerializedTypeName(sb, argument, ref isAssemQual, context);
                }
                consolidatedTypeArguments.Free();

                sb.Append(']');
                goto done;
            }

            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                bool nestedTypeIsAssemblyQualified = false;
                sb.Append(GetSerializedTypeName(nestedType.GetContainingType(context), context, ref nestedTypeIsAssemblyQualified));
                sb.Append('+');
                sb.Append(GetMangledAndEscapedName(nestedType));
                goto done;
            }

            // TODO: error
done:
            if (isAssemblyQualified)
            {
                AppendAssemblyQualifierIfNecessary(sb, UnwrapTypeReference(typeReference, context), out isAssemblyQualified, context);
            }

            return(pooled.ToStringAndFree());
        }
예제 #41
0
 public virtual void Visit(INamespaceTypeReference namespaceTypeReference)
 {
 }
예제 #42
0
        public override void Visit(INamespaceTypeReference namespaceTypeReference)
        {
            if (!this.typeReferenceNeedsToken && namespaceTypeReference.TypeCode(Context) != PrimitiveTypeCode.NotPrimitive)
            {
                return;
            }

            RecordTypeReference(namespaceTypeReference);

            var unit = namespaceTypeReference.GetUnit(Context);

            var assemblyReference = unit as IAssemblyReference;
            if (assemblyReference != null)
            {
                this.Visit(assemblyReference);
            }
            else
            {
                var moduleReference = unit as IModuleReference;
                if (moduleReference != null)
                {
                    // If this is a module from a referenced multi-module assembly,
                    // the assembly should be used as the resolution scope. 
                    assemblyReference = moduleReference.GetContainingAssembly(Context);
                    if (assemblyReference != null && assemblyReference != this.module.AsAssembly)
                    {
                        this.Visit(assemblyReference);
                    }
                    else
                    {
                        this.Visit(moduleReference);
                    }
                }
            }
        }
 public override void Visit(INamespaceTypeReference type)
 {
     base.Visit(type);
     AddAssemblyReference(type.GetAssemblyReference());
 }
예제 #44
0
 /// <summary>
 /// Traverses the namespace type reference.
 /// </summary>
 public void Traverse(INamespaceTypeReference namespaceTypeReference)
 {
     Contract.Requires(namespaceTypeReference != null);
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(namespaceTypeReference)) return;
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(namespaceTypeReference);
       if (this.stopTraversal) return;
       this.TraverseChildren(namespaceTypeReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(namespaceTypeReference);
 }
예제 #45
0
 public override void Visit(INamespaceTypeReference type)
 {
     INamespaceTypeReference typeRef = (INamespaceTypeReference)Util.CanonicalizeType(type);
     // The type can resolve to an external assembly, so we need to check whether we can include the external assembly.
     if (m_implModel.CanInclude(typeRef))
     {
         Visit(Util.ResolveTypeThrowing(typeRef));
     }
 }
예제 #46
0
 /// <summary>
 /// Traverses the children of the namespace type reference.
 /// </summary>
 public virtual void TraverseChildren(INamespaceTypeReference namespaceTypeReference)
 {
     Contract.Requires(namespaceTypeReference != null);
       this.TraverseChildren((ITypeReference)namespaceTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(namespaceTypeReference.ContainingUnitNamespace);
 }
예제 #47
0
 public override void TraverseChildren(INamespaceTypeReference namespaceTypeReference)
 {
     MethodEnter(namespaceTypeReference);
     base.TraverseChildren(namespaceTypeReference);
     MethodExit();
 }
예제 #48
0
 public void Visit(INamespaceTypeReference namespaceTypeReference)
 {
     throw new NotImplementedException();
 }
예제 #49
0
 public override void Visit(INamespaceTypeReference type)
 {
     AddTypeReference(type);
     base.Visit(type);
 }
예제 #50
0
 public override void Visit(INamespaceTypeReference namespaceTypeReference) {
   var assemblyReference = namespaceTypeReference.ContainingUnitNamespace.Unit as IAssemblyReference;
   if (assemblyReference != null) {
     var assembly = this.mapper.GetAssembly(assemblyReference);
     this.result = assembly.GetType(TypeHelper.GetTypeName(namespaceTypeReference, NameFormattingOptions.UseGenericTypeNameSuffix));
     if (this.result == null && namespaceTypeReference.GenericParameterCount > 0)
       this.result = assembly.GetType(TypeHelper.GetTypeName(namespaceTypeReference));
   } else {
     var mod = (IModuleReference)namespaceTypeReference.ContainingUnitNamespace.Unit;
     var module = this.mapper.GetModule(mod);
     this.result = module.GetType(TypeHelper.GetTypeName(namespaceTypeReference, NameFormattingOptions.UseGenericTypeNameSuffix));
     if (this.result == null && namespaceTypeReference.GenericParameterCount > 0)
       this.result = module.GetType(TypeHelper.GetTypeName(namespaceTypeReference));
   }
 }