Skip to content

Commit

Permalink
Fix error with base type resoltion
Browse files Browse the repository at this point in the history
Fix error that prevented syntax API from generating syntax tree for a type when its base type is not available. Now in this case it inserts "UnknownType" instead of type name, and continues to generate syntax.
  • Loading branch information
MSDN-WhiteKnight committed Mar 29, 2021
1 parent 6706616 commit 09dd6db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
17 changes: 15 additions & 2 deletions CilTools.BytecodeAnalysis/Syntax/SyntaxNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,23 @@ public static IEnumerable<SyntaxNode> GetTypeDefSyntax(Type t)
content.Add(new GenericSyntax(Environment.NewLine));

//base type
if ((t.IsClass || t.IsValueType) && t.BaseType!=null)
if (!t.IsInterface && t.BaseType!=null)
{
content.Add(new KeywordSyntax(String.Empty, "extends", " ", KeywordKind.Other));
content.Add(new MemberRefSyntax(CilAnalysis.GetTypeFullNameSyntax(t.BaseType).ToArray(), t.BaseType));

try
{
content.Add(new MemberRefSyntax(CilAnalysis.GetTypeFullNameSyntax(t.BaseType).ToArray(), t.BaseType));
}
catch (TypeLoadException ex)
{
//handle error when base type is not available
content.Add(new IdentifierSyntax(String.Empty, "UnknownType", String.Empty, false, null));

Diagnostics.OnError(
t, new CilErrorEventArgs(ex, "Failed to read base type for: "+ t.Name)
);
}
content.Add(new GenericSyntax(Environment.NewLine));
}

Expand Down
19 changes: 15 additions & 4 deletions CilView/UI.Controls/CilBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,20 @@ public ObservableCollection<MethodBase> NavigateToType(Type t)
{
if (t == null) return new ObservableCollection<MethodBase>();

CilBrowserPage page = new CilBrowserPage(t, Navigated);
page.Title = "Type: " + t.Name;
frameContent.Navigate(page);
string contenttext = String.Empty;

try
{
CilBrowserPage page = new CilBrowserPage(t, Navigated);
page.Title = "Type: " + t.Name;
frameContent.Navigate(page);
contenttext = page.ContentText;
}
catch (TypeLoadException ex)
{
ErrorHandler.Current.Error(ex);
frameContent.Navigate(String.Empty);
}

//display method list in left pane
ObservableCollection<MethodBase> methods = AssemblySource.LoadMethods(t);
Expand All @@ -146,7 +157,7 @@ public ObservableCollection<MethodBase> NavigateToType(Type t)

this.current_method = null;
this.current_type = t;
this.text = page.ContentText;
this.text = contenttext;

//make sure content is visible
ExpandContentPane();
Expand Down

0 comments on commit 09dd6db

Please sign in to comment.