Browse Source

Fixed SD2-1286: Nested With statements result in stack overflow

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2331 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
8620427755
  1. 34
      src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesCommand.cs
  2. 14
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  3. 34
      src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs
  4. 26
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs

34
src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesCommand.cs

@ -38,6 +38,8 @@ namespace ICSharpCode.FiletypeRegisterer { @@ -38,6 +38,8 @@ namespace ICSharpCode.FiletypeRegisterer {
return openCommand.StartsWith(mainExe) || openCommand.StartsWith('"' + mainExe);
}
const string explorerFileExts = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts";
public static bool IsRegisteredFileType(string extension)
{
try {
@ -48,18 +50,32 @@ namespace ICSharpCode.FiletypeRegisterer { @@ -48,18 +50,32 @@ namespace ICSharpCode.FiletypeRegisterer {
} catch (System.Security.SecurityException) {
// registry access might be denied
}
try {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(explorerFileExts + "\\." + extension)) {
if (key != null)
return true;
}
} catch (System.Security.SecurityException) {
// registry access might be denied
}
return false;
}
static string GetOpenCommand(string extension)
{
try {
string clsKeyName;
using (RegistryKey extKey = Registry.ClassesRoot.OpenSubKey("." + extension)) {
string clsKeyName = null;
using (RegistryKey extKey = Registry.CurrentUser.OpenSubKey(explorerFileExts + "\\." + extension)) {
if (extKey != null)
clsKeyName = (string)extKey.GetValue("", "");
else
return null;
clsKeyName = (string)extKey.GetValue("Progid", "");
}
if (clsKeyName == null) {
using (RegistryKey extKey = Registry.ClassesRoot.OpenSubKey("." + extension)) {
if (extKey != null)
clsKeyName = (string)extKey.GetValue("", "");
else
return null;
}
}
using (RegistryKey cmdKey = Registry.ClassesRoot.OpenSubKey(clsKeyName + "\\shell\\open\\command")) {
if (cmdKey != null)
@ -97,6 +113,14 @@ namespace ICSharpCode.FiletypeRegisterer { @@ -97,6 +113,14 @@ namespace ICSharpCode.FiletypeRegisterer {
extKey.SetValue("", "SD." + extension + "file");
extKey.Close();
try {
extKey = Registry.CurrentUser.OpenSubKey(explorerFileExts + "\\." + extension, true);
if (extKey != null) {
extKey.DeleteValue("Progid");
extKey.Close();
}
} catch {}
clsKey = rootKey.CreateSubKey("SD." + extension + "file");

14
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -24,7 +24,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -24,7 +24,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
CSharpOutputFormatter outputFormatter;
PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions();
NodeTracker nodeTracker;
Stack<WithStatement> withExpressionStack = new Stack<WithStatement>();
bool printFullSystemType;
public string Text {
@ -876,7 +875,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -876,7 +875,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.BeginBrace(braceStyle);
foreach (Statement stmt in blockStatement.Children) {
outputFormatter.Indent();
nodeTracker.TrackedVisit(stmt, null);
if (stmt is BlockStatement) {
nodeTracker.TrackedVisit(stmt, BraceStyle.EndOfLine);
} else {
nodeTracker.TrackedVisit(stmt, null);
}
if (!outputFormatter.LastCharacterIsNewLine)
outputFormatter.NewLine();
}
@ -1462,9 +1465,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1462,9 +1465,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitWithStatement(WithStatement withStatement, object data)
{
withExpressionStack.Push(withStatement);
nodeTracker.TrackedVisit(withStatement.Body, BraceStyle.EndOfLine);
withExpressionStack.Pop();
NotSupported(withStatement);
return null;
}
@ -2321,9 +2322,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2321,9 +2322,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
{
Expression target = fieldReferenceExpression.TargetObject;
if (target.IsNull && withExpressionStack.Count > 0) {
target = ((WithStatement)withExpressionStack.Peek()).Expression;
}
if (target is BinaryOperatorExpression || target is CastExpression) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);

34
src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs

@ -67,6 +67,40 @@ namespace ICSharpCode.NRefactory.Visitors @@ -67,6 +67,40 @@ namespace ICSharpCode.NRefactory.Visitors
return null;
}
public override object VisitWithStatement(WithStatement withStatement, object data)
{
withStatement.Body.AcceptVisitor(new ReplaceWithAccessTransformer(withStatement.Expression), data);
base.VisitWithStatement(withStatement, data);
ReplaceCurrentNode(withStatement.Body);
return null;
}
sealed class ReplaceWithAccessTransformer : AbstractAstTransformer
{
readonly Expression replaceWith;
public ReplaceWithAccessTransformer(Expression replaceWith)
{
this.replaceWith = replaceWith;
}
public override object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
{
if (fieldReferenceExpression.TargetObject.IsNull) {
fieldReferenceExpression.TargetObject = replaceWith;
return null;
} else {
return base.VisitFieldReferenceExpression(fieldReferenceExpression, data);
}
}
public override object VisitWithStatement(WithStatement withStatement, object data)
{
// do not visit the body of the WithStatement
return withStatement.Expression.AcceptVisitor(this, data);
}
}
static bool IsTypeLevel(INode node)
{
return node is MethodDeclaration || node is PropertyDeclaration || node is EventDeclaration

26
src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs

@ -552,6 +552,32 @@ static int static_Test2_j = 0;"); @@ -552,6 +552,32 @@ static int static_Test2_j = 0;");
"{\n\tEjes.AddLine(p1, p2);\n}");
}
[Test]
public void NestedWithStatements()
{
TestStatement(
"With tb1\n" +
" With .Font\n" +
" .Italic = True\n" +
" End With\n" +
"End With",
"{\n\t{\n\t\ttb1.Font.Italic = true;\n\t}\n}");
}
[Test]
public void NestedWithStatements2()
{
TestStatement(
"With tb1\n" +
" With .Something.Font\n" +
" .Italic = True\n" +
" End With\n" +
"End With",
"{\n\t{\n\t\ttb1.Something.Font.Italic = true;\n\t}\n}");
}
[Test]
public void StructureWithImplicitPublicField()
{

Loading…
Cancel
Save