public bool mustInlineMethod(IMethodDefinition method)
        {
            if (PhoneFeedbackToggled)
            {
                // FEEDBACK TODO this may be too coarse
                // top level inlined methods are feedback relevant ones. For now, this is basically everything that has EventArgs as parameters
                if (isMethodInputHandlerOrFeedbackOverride(method))
                {
                    return(true);
                }
            }

            if (PhoneNavigationToggled)
            {
                // NAVIGATION TODO this may be too coarse
                // for now, assume any method in a PhoneApplicationPage is potentially interesting to navigation inlining
                ITypeReference methodContainer = method.ContainingType;
                if (PhoneTypeHelper.isPhoneApplicationClass(methodContainer, host) || PhoneTypeHelper.isPhoneApplicationPageClass(methodContainer, host))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static bool isPhoneApplicationPageClass(this ITypeReference typeRef, IMetadataHost host)
        {
            Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;
            IAssemblyReference phoneAssembly = PhoneTypeHelper.getPhoneAssemblyReference(host);
            ITypeReference     phoneApplicationPageTypeRef = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Controls", "PhoneApplicationPage");

            return(typeRef.isClass(phoneApplicationPageTypeRef));
        }
        public static bool isPhoneApplicationClass(this ITypeReference typeRef, IMetadataHost host)
        {
            Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;
            IAssemblyReference systemAssembly             = PhoneTypeHelper.getSystemWindowsAssemblyReference(host);
            ITypeReference     applicationClass           = platform.CreateReference(systemAssembly, "System", "Windows", "Application");

            return(typeRef.isClass(applicationClass));
        }
        public bool isMethodInputHandlerOrFeedbackOverride(IMethodDefinition method)
        {
            // FEEDBACK TODO: This is extremely coarse. There must be quite a few non-UI routed/non-routed events
            Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;;
            IAssemblyReference coreAssembly  = PhoneTypeHelper.getCoreAssemblyReference(host);
            ITypeReference     eventArgsType = platform.CreateReference(coreAssembly, "System", "EventArgs");

            foreach (IParameterDefinition paramDef in method.Parameters)
            {
                if (paramDef.Type.isClass(eventArgsType))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
 public override void TraverseChildren(IMethodDefinition method)
 {
     this.methodTraversed = method;
     if (method.IsConstructor && PhoneTypeHelper.isPhoneApplicationClass(typeTraversed, host))
     {
         navigationCallers.Add(method);
         string           mainPageUri = PhoneCodeHelper.instance().PhonePlugin.getMainPageXAML();
         SourceMethodBody sourceBody  = method.Body as SourceMethodBody;
         if (sourceBody != null)
         {
             BlockStatement bodyBlock = sourceBody.Block as BlockStatement;
             if (bodyBlock != null)
             {
                 Assignment uriInitAssign = new Assignment()
                 {
                     Source = new CompileTimeConstant()
                     {
                         Type  = host.PlatformType.SystemString,
                         Value = UriHelper.getURIBase(mainPageUri),
                     },
                     Type   = host.PlatformType.SystemString,
                     Target = new TargetExpression()
                     {
                         Type = host.PlatformType.SystemString,
                         // TODO unify code for current uri fieldreference
                         Definition = new FieldReference()
                         {
                             ContainingType = PhoneCodeHelper.instance().getMainAppTypeReference(),
                             IsStatic       = true,
                             Type           = host.PlatformType.SystemString,
                             Name           = host.NameTable.GetNameFor(PhoneCodeHelper.IL_CURRENT_NAVIGATION_URI_VARIABLE),
                             InternFactory  = host.InternFactory,
                         },
                     },
                 };
                 Statement uriInitStmt = new ExpressionStatement()
                 {
                     Expression = uriInitAssign,
                 };
                 bodyBlock.Statements.Insert(0, uriInitStmt);
             }
         }
     }
     base.TraverseChildren(method);
 }
Beispiel #6
0
        public PhoneNavigationCodeTraverser(MetadataReaderHost host, IEnumerable <IAssemblyReference> assemblies) : base()
        {
            this.host = host;
            List <IAssembly> assembliesTraversed = new List <IAssembly>();

            foreach (IAssemblyReference asmRef in assemblies)
            {
                assembliesTraversed.Add(asmRef.ResolvedAssembly);
            }

            Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType;

            // TODO obtain version, culture and signature data dynamically
            IAssemblyReference assembly = PhoneTypeHelper.getPhoneAssemblyReference(host);

            // TODO determine the needed types dynamically
            navigationSvcType = platform.CreateReference(assembly, "System", "Windows", "Navigation", "NavigationService");

            assembly            = PhoneTypeHelper.getSystemAssemblyReference(host);
            cancelEventArgsType = platform.CreateReference(assembly, "System", "ComponentModel", "CancelEventArgs");
            navigationCallers   = new HashSet <IMethodReference>();
        }
        private void initializeKnownUIChangers()
        {
            PHONE_UI_CHANGER_METHODS = new Dictionary <string, string[]>();
            IAssemblyReference systemAssembly    = PhoneTypeHelper.getSystemAssemblyReference(host);
            IAssemblyReference systemWinAssembly = PhoneTypeHelper.getSystemWindowsAssemblyReference(host);
            IAssemblyReference phoneAssembly     = PhoneTypeHelper.getPhoneAssemblyReference(host);

            ITypeReference textBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "TextBox");

            PHONE_UI_CHANGER_METHODS[textBoxType.ToString()] =
                new string[] { "set_BaselineOffset", "set_CaretBrush", "set_FontSource", "set_HorizontalScrollBarVisibility", "set_IsReadOnly", "set_LineHeight",
                               "set_LineStackingStrategy", "set_MaxLength", "set_SelectedText", "set_SelectionBackground", "set_SelectionForeground", "set_SelectionLength",
                               "set_SelectionStart", "set_Text", "set_TextAlignment", "set_TextWrapping", "set_VerticalScrollBarVisibility", "set_Watermark", };

            ITypeReference textBlockType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "TextBlock");

            PHONE_UI_CHANGER_METHODS[textBlockType.ToString()] =
                new string[] { "set_BaselineOffset", "set_FontFamily", "set_FontSize", "set_FontSource", "set_FontStretch", "set_FontStyle", "set_FontWeight", "set_Foreground",
                               "set_CharacterSpacing", "set_LineHeight", "set_LineStackingStrategy", "set_Padding", "set_Text", "set_TextAlignment", "set_TextDecorations",
                               "set_TextTrimming", "set_TextWrapping", };

            ITypeReference uiElementType = platform.CreateReference(systemAssembly, "System", "Windows", "UIElement");

            PHONE_UI_CHANGER_METHODS[uiElementType.ToString()] =
                new string[] { "set_Clip", "set_Opacity", "set_OpacityMask", "set_Projection", "set_RenderTransform",
                               "set_RenderTransformOrigin", "set_Visibility", "Arrange", "InvalidateArrange", "InvalidateMeasure", "SetValue", "ClearValue", // Set/ClearValue are quite unsafe
                               "UpdateLayout", "Measure", };

            ITypeReference frameworkElementType = platform.CreateReference(systemAssembly, "System", "Windows", "FrameworkElement");

            PHONE_UI_CHANGER_METHODS[frameworkElementType.ToString()] =
                new string[] { "set_FlowDirection", "set_Height", "set_HorizontalAlignment", "set_Language", "set_Margin", "set_MaxHeight", "set_MaxWidth",
                               "set_MinHeight", "set_MinWidth", "set_Style", "set_VerticalAlignment", "set_Width", "set_Cursor", };

            ITypeReference borderType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Border");

            PHONE_UI_CHANGER_METHODS[borderType.ToString()] =
                new string[] { "set_Background", "set_BorderBrush", "set_BorderThickness", "set_CornerRadius", "set_Padding", };

            ITypeReference controlType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Control");

            PHONE_UI_CHANGER_METHODS[controlType.ToString()] =
                new string[] { "set_Background", "set_BorderBrush", "set_BorderThickness", "set_CharacterSpacing", "set_FontFamily", "set_FontSize", "set_FontStretch",
                               "set_FontStyle", "set_FontWeight", "set_Foreground", "set_HorizontalContentAlignment", "set_IsEnabled", "set_Padding", "set_VerticalContentAlignment", };

            ITypeReference contentControlType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ContentControl");

            PHONE_UI_CHANGER_METHODS[contentControlType.ToString()] = new string[] { "set_Content", };

            ITypeReference panelType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Panel");

            PHONE_UI_CHANGER_METHODS[panelType.ToString()] = new string[] { "set_Background", };

            ITypeReference canvasType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Canvas");

            PHONE_UI_CHANGER_METHODS[canvasType.ToString()] = new string[] { "set_Left", "set_Top", "set_ZIndex", };

            ITypeReference toggleButtonType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Primitives", "ToggleButton");

            PHONE_UI_CHANGER_METHODS[toggleButtonType.ToString()] = new string[] { "set_IsChecked", };

            ITypeReference gridType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Grid");

            PHONE_UI_CHANGER_METHODS[gridType.ToString()] = new string[] { "set_ShowGridLines", "set_Column", "set_ColumnSpan", "set_Row", "set_RowSpan", };

            ITypeReference imageType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Image");

            PHONE_UI_CHANGER_METHODS[imageType.ToString()] = new string[] { "set_Source", "set_Stretch", };

            ITypeReference inkPresenterType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "InkPresenter");

            PHONE_UI_CHANGER_METHODS[inkPresenterType.ToString()] = new string[] { "set_Strokes", };

            ITypeReference itemsControlType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ItemsControl");

            PHONE_UI_CHANGER_METHODS[itemsControlType.ToString()] = new string[] { "set_DisplayMemberPath", "set_ItemsSource", "set_ItemTemplate", };

            ITypeReference selectorType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Primitives", "Selector");

            PHONE_UI_CHANGER_METHODS[selectorType.ToString()] =
                new string[] { "set_SelectedIndex", "set_SelectedItem", "set_SelectedValue", "set_SelectedValuePath", };

            ITypeReference listBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ListBox");

            PHONE_UI_CHANGER_METHODS[listBoxType.ToString()] = new string[] { "set_ItemContainerStyle", };

            ITypeReference passwordBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "PasswordBox");

            PHONE_UI_CHANGER_METHODS[passwordBoxType.ToString()] =
                new string[] { "set_CaretBrush", "set_FontSource", "set_MaxLength", "set_Password", "set_PasswordChar",
                               "set_SelectionBackground", "set_SelectionForeground", };

            ITypeReference rangeBaseType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Primitives", "RangeBase");

            PHONE_UI_CHANGER_METHODS[rangeBaseType.ToString()] = new string[] { "set_LargeChange", "set_Maximum", "set_Minimum", "set_SmallChange", "set_Value", };

            ITypeReference progressBarType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "ProgressBar");

            PHONE_UI_CHANGER_METHODS[progressBarType.ToString()] = new string[] { "set_IsIndeterminate", };

            ITypeReference sliderType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "Slider");

            PHONE_UI_CHANGER_METHODS[sliderType.ToString()] = new string[] { "set_IsDirectionReversed", "set_Orientation", };

            ITypeReference stackPanelType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "StackPanel");

            PHONE_UI_CHANGER_METHODS[stackPanelType.ToString()] = new string[] { "set_Orientation", };

            ITypeReference richTextBoxType = platform.CreateReference(systemAssembly, "System", "Windows", "Controls", "RichTextBox");

            PHONE_UI_CHANGER_METHODS[richTextBoxType.ToString()] =
                new string[] { "set_BaselineOffset", "set_CaretBrush", "set_HorizontalScrollBartVisibility", "set_LineHeight", "set_LineStackingStrategy",
                               "set_TextAlignment", "set_TextWrapping", "set_VerticalScrollBarVisibility", "set_Xaml", };

            ITypeReference webBrowserTaskType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Tasks", "WebBrowserTask");

            PHONE_UI_CHANGER_METHODS[webBrowserTaskType.ToString()] = new string[] { "Show", };

            ITypeReference appBarIconButtonType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarIconButton");

            PHONE_UI_CHANGER_METHODS[appBarIconButtonType.ToString()] = new string[] { "set_IsEnabled", "set_IconUri", "set_Text", };

            ITypeReference appBarMenuItemType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarMenuItem");

            PHONE_UI_CHANGER_METHODS[appBarMenuItemType.ToString()] = new string[] { "set_IsEnabled", "set_Text", };

            ITypeReference emailComposeTaskType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Tasks", "EmailComposeTask");

            PHONE_UI_CHANGER_METHODS[emailComposeTaskType.ToString()] = new string[] { "Show", };

            ITypeReference scaleTransformType = platform.CreateReference(systemWinAssembly, "System", "Windows", "Media", "ScaleTransform");

            PHONE_UI_CHANGER_METHODS[scaleTransformType.ToString()] = new string[] { "set_CenterX", "set_CenterY", "set_ScaleX", "set_ScaleY", };
        }