Browse Source

Lock access to DefaultProjectContent.ReferencedContents - can be modified by main thread and solution loading thread.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1477 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
515b955432
  1. 16
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  2. 2
      src/Libraries/NRefactory/Project/Src/Output/CodeDOM/CodeDOMOutputVisitor.cs
  3. 30
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  4. 2
      src/Libraries/NRefactory/Project/Src/Parser/AST/TypeReference.cs
  5. 20
      src/Libraries/NRefactory/Test/General/UnitTest.cs
  6. 13
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  7. 31
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  8. 40
      src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs
  9. 25
      src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs
  10. 8
      src/Main/Base/Project/Src/Services/ParserService/ReflectionProjectContent.cs

16
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -999,7 +999,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Indent(); outputFormatter.Indent();
} }
OutputModifier(localVariableDeclaration.Modifier); OutputModifier(localVariableDeclaration.Modifier);
nodeTracker.TrackedVisit(localVariableDeclaration.GetTypeForVariable(i), data); nodeTracker.TrackedVisit(localVariableDeclaration.GetTypeForVariable(i) ?? new TypeReference("object"), data);
outputFormatter.Space(); outputFormatter.Space();
nodeTracker.TrackedVisit(v, data); nodeTracker.TrackedVisit(v, data);
outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.PrintToken(Tokens.Semicolon);
@ -1303,9 +1303,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (doLoopStatement.ConditionType == ConditionType.Until) { if (doLoopStatement.ConditionType == ConditionType.Until) {
outputFormatter.PrintToken(Tokens.Not); outputFormatter.PrintToken(Tokens.Not);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
} }
nodeTracker.TrackedVisit(doLoopStatement.Condition, null); if (doLoopStatement.Condition.IsNull) {
outputFormatter.PrintToken(Tokens.True);
} else {
nodeTracker.TrackedVisit(doLoopStatement.Condition, null);
}
if (doLoopStatement.ConditionType == ConditionType.Until) {
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
@ -1321,11 +1330,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Do); outputFormatter.PrintToken(Tokens.Do);
} }
++outputFormatter.IndentationLevel;
WriteEmbeddedStatement(doLoopStatement.EmbeddedStatement); WriteEmbeddedStatement(doLoopStatement.EmbeddedStatement);
--outputFormatter.IndentationLevel;
if (doLoopStatement.ConditionPosition == ConditionPosition.End) { if (doLoopStatement.ConditionPosition == ConditionPosition.End) {
outputFormatter.Indent();
PrintLoopCheck(doLoopStatement); PrintLoopCheck(doLoopStatement);
outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine(); outputFormatter.NewLine();

2
src/Libraries/NRefactory/Project/Src/Output/CodeDOM/CodeDOMOutputVisitor.cs

@ -287,7 +287,7 @@ namespace ICSharpCode.NRefactory.Parser
CodeVariableDeclarationStatement declStmt = null; CodeVariableDeclarationStatement declStmt = null;
for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) { for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) {
CodeTypeReference type = ConvType(localVariableDeclaration.GetTypeForVariable(i)); CodeTypeReference type = ConvType(localVariableDeclaration.GetTypeForVariable(i) ?? new TypeReference("object"));
VariableDeclaration var = (VariableDeclaration)localVariableDeclaration.Variables[i]; VariableDeclaration var = (VariableDeclaration)localVariableDeclaration.Variables[i];
if (!var.Initializer.IsNull) { if (!var.Initializer.IsNull) {
declStmt = new CodeVariableDeclarationStatement(type, declStmt = new CodeVariableDeclarationStatement(type,

30
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -488,6 +488,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (fieldDeclaration.Modifier == Modifier.None) { if (fieldDeclaration.Modifier == Modifier.None) {
outputFormatter.PrintToken(Tokens.Private); outputFormatter.PrintToken(Tokens.Private);
outputFormatter.Space(); outputFormatter.Space();
} else if (fieldDeclaration.Modifier == Modifier.Dim) {
outputFormatter.PrintToken(Tokens.Dim);
outputFormatter.Space();
} else { } else {
OutputModifier(fieldDeclaration.Modifier); OutputModifier(fieldDeclaration.Modifier);
} }
@ -503,13 +506,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(VariableDeclaration variableDeclaration, object data) public object Visit(VariableDeclaration variableDeclaration, object data)
{ {
outputFormatter.PrintIdentifier(variableDeclaration.Name); outputFormatter.PrintIdentifier(variableDeclaration.Name);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
if (variableDeclaration.TypeReference.IsNull && currentVariableType != null) { if (variableDeclaration.TypeReference.IsNull) {
nodeTracker.TrackedVisit(currentVariableType, data); if (currentVariableType != null && !currentVariableType.IsNull) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(currentVariableType, data);
}
} else { } else {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(variableDeclaration.TypeReference, data); nodeTracker.TrackedVisit(variableDeclaration.TypeReference, data);
} }
@ -1440,6 +1448,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
exitTokenStack.Push(Tokens.Select); exitTokenStack.Push(Tokens.Select);
outputFormatter.PrintToken(Tokens.Select); outputFormatter.PrintToken(Tokens.Select);
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Case);
outputFormatter.Space();
nodeTracker.TrackedVisit(switchStatement.SwitchExpression, data); nodeTracker.TrackedVisit(switchStatement.SwitchExpression, data);
outputFormatter.NewLine(); outputFormatter.NewLine();
++outputFormatter.IndentationLevel; ++outputFormatter.IndentationLevel;
@ -1596,15 +1606,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
PrintIndentedBlock(doLoopStatement.EmbeddedStatement); PrintIndentedBlock(doLoopStatement.EmbeddedStatement);
outputFormatter.Indent(); outputFormatter.Indent();
if (doLoopStatement.ConditionType == ConditionType.While) { outputFormatter.PrintToken(Tokens.Loop);
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.While);
} else {
outputFormatter.PrintToken(Tokens.Loop);
}
if (doLoopStatement.ConditionPosition == ConditionPosition.End) { if (doLoopStatement.ConditionPosition == ConditionPosition.End && !doLoopStatement.Condition.IsNull) {
outputFormatter.Space(); outputFormatter.Space();
switch (doLoopStatement.ConditionType) { switch (doLoopStatement.ConditionType) {
case ConditionType.While: case ConditionType.While:

2
src/Libraries/NRefactory/Project/Src/Parser/AST/TypeReference.cs

@ -306,7 +306,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
} }
public override object AcceptVisitor(IAstVisitor visitor, object data) public override object AcceptVisitor(IAstVisitor visitor, object data)
{ {
return data; return null;
} }
public static NullTypeReference Instance { public static NullTypeReference Instance {
get { get {

20
src/Libraries/NRefactory/Test/General/UnitTest.cs

@ -29,11 +29,29 @@ namespace ICSharpCode.NRefactory.Tests
} }
} }
[Test]
public void TestUnitTests()
{
Type[] allTypes = typeof(StructuralTest).Assembly.GetTypes();
foreach (Type type in allTypes) {
if (type.GetCustomAttributes(typeof(TestFixtureAttribute), true).Length > 0) {
foreach (MethodInfo m in type.GetMethods()) {
if (m.IsPublic && m.ReturnType == typeof(void) && m.GetParameters().Length == 0) {
if (m.GetCustomAttributes(typeof(TestAttribute), true).Length == 0) {
Assert.Fail(type.Name + "." + m.Name + " should have the [Test] attribute!");
}
}
}
}
}
}
// [Test] // [Test]
// public void TestAcceptVisitorMethods() // public void TestAcceptVisitorMethods()
// { // {
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); // Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
// //
// foreach (Type type in allTypes) { // foreach (Type type in allTypes) {
// if (type.IsClass && !type.IsAbstract && type.GetInterface(typeof(INode).FullName) != null) { // if (type.IsClass && !type.IsAbstract && type.GetInterface(typeof(INode).FullName) != null) {
// MethodInfo methodInfo = type.GetMethod("AcceptVisitor", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); // MethodInfo methodInfo = type.GetMethod("AcceptVisitor", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

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

@ -299,5 +299,18 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"for (long l = 10; l >= 0; l += -1) {\n" + "for (long l = 10; l >= 0; l += -1) {\n" +
"}"); "}");
} }
[Test]
public void DoLoop()
{
TestStatement("Do \n Loop",
"do {\n" +
"}\n" +
"while (true);");
TestStatement("Do \n Loop Until i = 10000",
"do {\n" +
"}\n" +
"while (!(i == 10000));");
}
} }
} }

31
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -135,6 +135,37 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"Next"); "Next");
} }
[Test]
public void DoLoop()
{
TestStatement("Do\n" +
"Loop");
TestStatement("Do\n" +
"Loop While Not (i = 10)");
}
[Test]
public void SelectCase()
{
TestStatement(@"Select Case i
Case 0
Case 1 To 4
Case Else
End Select");
}
[Test]
public void UntypedVariable()
{
TestStatement("Dim x = 0");
}
[Test]
public void UntypedField()
{
TestTypeMember("Dim x = 0");
}
[Test] [Test]
public void Assignment() public void Assignment()
{ {

40
src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs

@ -190,10 +190,12 @@ namespace ICSharpCode.Core
if (desc != null) { if (desc != null) {
return desc; return desc;
} }
foreach (IProjectContent referencedContent in referencedContents) { lock (referencedContents) {
desc = referencedContent.XmlDoc.GetDocumentation(memberTag); foreach (IProjectContent referencedContent in referencedContents) {
if (desc != null) { desc = referencedContent.XmlDoc.GetDocumentation(memberTag);
return desc; if (desc != null) {
return desc;
}
} }
} }
return null; return null;
@ -543,13 +545,15 @@ namespace ICSharpCode.Core
// Search in references: // Search in references:
if (lookInReferences) { if (lookInReferences) {
foreach (IProjectContent content in referencedContents) { lock (referencedContents) {
IClass contentClass = content.GetClass(typeName, typeParameterCount, language, false); foreach (IProjectContent content in referencedContents) {
if (contentClass != null) { IClass contentClass = content.GetClass(typeName, typeParameterCount, language, false);
if (contentClass.TypeParameters.Count == typeParameterCount) { if (contentClass != null) {
return contentClass; if (contentClass.TypeParameters.Count == typeParameterCount) {
} else { return contentClass;
c = contentClass; } else {
c = contentClass;
}
} }
} }
} }
@ -598,8 +602,10 @@ namespace ICSharpCode.Core
} }
if (lookInReferences) { if (lookInReferences) {
foreach (IProjectContent content in referencedContents) { lock (referencedContents) {
content.AddNamespaceContents(list, nameSpace, language, false); foreach (IProjectContent content in referencedContents) {
content.AddNamespaceContents(list, nameSpace, language, false);
}
} }
} }
@ -665,9 +671,11 @@ namespace ICSharpCode.Core
} }
if (lookInReferences) { if (lookInReferences) {
foreach (IProjectContent content in referencedContents) { lock (referencedContents) {
if (content.NamespaceExists(name, language, false)) { foreach (IProjectContent content in referencedContents) {
return true; if (content.NamespaceExists(name, language, false)) {
return true;
}
} }
} }
} }

25
src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs

@ -74,7 +74,11 @@ namespace ICSharpCode.Core
void UpdateReferenceInterDependencies() void UpdateReferenceInterDependencies()
{ {
// Use ToArray because the collection could be modified inside the loop // Use ToArray because the collection could be modified inside the loop
foreach (IProjectContent referencedContent in this.referencedContents.ToArray()) { IProjectContent[] referencedContents;
lock (this.referencedContents) {
referencedContents = this.referencedContents.ToArray();
}
foreach (IProjectContent referencedContent in referencedContents) {
if (referencedContent is ReflectionProjectContent) { if (referencedContent is ReflectionProjectContent) {
((ReflectionProjectContent)referencedContent).InitializeReferences(); ((ReflectionProjectContent)referencedContent).InitializeReferences();
} }
@ -86,7 +90,9 @@ namespace ICSharpCode.Core
try { try {
IProjectContent referencedContent = ProjectContentRegistry.GetProjectContentForReference(reference); IProjectContent referencedContent = ProjectContentRegistry.GetProjectContentForReference(reference);
if (referencedContent != null) { if (referencedContent != null) {
ReferencedContents.Add(referencedContent); lock (this.referencedContents) {
this.referencedContents.Add(referencedContent);
}
} }
if (updateInterDependencies) { if (updateInterDependencies) {
UpdateReferenceInterDependencies(); UpdateReferenceInterDependencies();
@ -130,7 +136,9 @@ namespace ICSharpCode.Core
try { try {
IProjectContent referencedContent = ProjectContentRegistry.GetExistingProjectContentForReference(reference); IProjectContent referencedContent = ProjectContentRegistry.GetExistingProjectContentForReference(reference);
if (referencedContent != null) { if (referencedContent != null) {
ReferencedContents.Remove(referencedContent); lock (ReferencedContents) {
ReferencedContents.Remove(referencedContent);
}
OnReferencedContentsChanged(EventArgs.Empty); OnReferencedContentsChanged(EventArgs.Empty);
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -192,7 +200,12 @@ namespace ICSharpCode.Core
try { try {
StatusBarService.ProgressMonitor.TaskName = "Parsing " + project.Name + "..."; StatusBarService.ProgressMonitor.TaskName = "Parsing " + project.Name + "...";
foreach (IProjectContent referencedContent in ReferencedContents) { IProjectContent[] referencedContents;
lock (this.referencedContents) {
referencedContents = this.referencedContents.ToArray();
}
foreach (IProjectContent referencedContent in referencedContents) {
if (referencedContent is ReflectionProjectContent) { if (referencedContent is ReflectionProjectContent) {
((ReflectionProjectContent)referencedContent).InitializeReferences(); ((ReflectionProjectContent)referencedContent).InitializeReferences();
} }
@ -222,10 +235,10 @@ namespace ICSharpCode.Core
initializing = false; initializing = false;
base.Dispose(); base.Dispose();
} }
void OnEndBuild(object source, EventArgs e) void OnEndBuild(object source, EventArgs e)
{ {
AddComReferences(); AddComReferences();
} }
void AddComReferences() void AddComReferences()

8
src/Main/Base/Project/Src/Services/ParserService/ReflectionProjectContent.cs

@ -129,7 +129,9 @@ namespace ICSharpCode.SharpDevelop.Dom
IProjectContent content = ProjectContentRegistry.GetExistingProjectContent((AssemblyName)missingNames[i]); IProjectContent content = ProjectContentRegistry.GetExistingProjectContent((AssemblyName)missingNames[i]);
if (content != null) { if (content != null) {
changed = true; changed = true;
ReferencedContents.Add(content); lock (ReferencedContents) {
ReferencedContents.Add(content);
}
missingNames.RemoveAt(i--); missingNames.RemoveAt(i--);
} }
} }
@ -146,7 +148,9 @@ namespace ICSharpCode.SharpDevelop.Dom
IProjectContent content = ProjectContentRegistry.GetExistingProjectContent(name); IProjectContent content = ProjectContentRegistry.GetExistingProjectContent(name);
if (content != null) { if (content != null) {
changed = true; changed = true;
ReferencedContents.Add(content); lock (ReferencedContents) {
ReferencedContents.Add(content);
}
} else { } else {
if (missingNames == null) if (missingNames == null)
missingNames = new ArrayList(); missingNames = new ArrayList();

Loading…
Cancel
Save