Skip to content
This repository
Browse code

Add C# resolve visitor.

  • Loading branch information...
commit a7e253e3eab8b8759ddf6ec0c32386723a2787fc 1 parent 9b04350
Daniel Grunwald dgrunwald authored
68 ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
... ... @@ -0,0 +1,68 @@
  1 +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2 +// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
  3 +
  4 +using System;
  5 +using System.Linq;
  6 +using NUnit.Framework;
  7 +
  8 +namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
  9 +{
  10 + [TestFixture, Ignore]
  11 + public class AttributeSectionTests
  12 + {
  13 + [Test, Ignore]
  14 + public void GlobalAttributeCSharp()
  15 + {
  16 + string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
  17 +[someprefix::DesignerGenerated()]
  18 +public class Form1 {
  19 +}";
  20 + // TODO This test checks that [global] attributes are incorrectly applies to the following type???
  21 +
  22 + //TypeDeclaration decl = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
  23 + //Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes.First().Attributes.Single().Name);
  24 + //Assert.AreEqual("someprefix.DesignerGenerated", decl.Attributes.Last().Attributes.Single().Name);
  25 + }
  26 +
  27 + [Test]
  28 + public void AssemblyAttributeCSharp()
  29 + {
  30 + string program = @"[assembly: System.Attribute()]";
  31 + AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
  32 + Assert.AreEqual(new DomLocation(1, 1), decl.StartLocation);
  33 + Assert.AreEqual("assembly", decl.AttributeTarget);
  34 + }
  35 +
  36 + [Test]
  37 + public void AssemblyAttributeCSharpWithNamedArguments()
  38 + {
  39 + string program = @"[assembly: Foo(1, namedArg: 2, prop = 3)]";
  40 + AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
  41 + Assert.AreEqual("assembly", decl.AttributeTarget);
  42 + var a = decl.Attributes.Single();
  43 + Assert.AreEqual("Foo", a.Name);
  44 + Assert.AreEqual(3, a.Arguments.Count());
  45 +
  46 + // TODO: check arguments
  47 + }
  48 +
  49 + [Test]
  50 + public void ModuleAttributeCSharp()
  51 + {
  52 + string program = @"[module: System.Attribute()]";
  53 + AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
  54 + Assert.AreEqual(new DomLocation(1, 1), decl.StartLocation);
  55 + Assert.AreEqual("module", decl.AttributeTarget);
  56 + }
  57 +
  58 + [Test]
  59 + public void TypeAttributeCSharp()
  60 + {
  61 + string program = @"[type: System.Attribute()] class Test {}";
  62 + TypeDeclaration type = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
  63 + AttributeSection decl = type.Attributes.Single();
  64 + Assert.AreEqual(new DomLocation(1, 1), decl.StartLocation);
  65 + Assert.AreEqual("type", decl.AttributeTarget);
  66 + }
  67 + }
  68 +}
17 ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
@@ -13,6 +13,23 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
13 13 /// </summary>
14 14 public class ParseUtilCSharp
15 15 {
  16 + public static T ParseGlobal<T>(string code, bool expectErrors = false) where T : INode
  17 + {
  18 + CSharpParser parser = new CSharpParser();
  19 + CompilationUnit cu = parser.Parse(new StringReader(code));
  20 +
  21 + // TODO check for parser errors
  22 + /*if (expectErrors)
  23 + Assert.IsTrue(parser.Errors.ErrorOutput.Length > 0, "There were errors expected, but parser finished without errors.");
  24 + else
  25 + Assert.AreEqual("", parser.Errors.ErrorOutput);*/
  26 +
  27 + INode node = cu.Children.Single();
  28 + Type type = typeof(T);
  29 + Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, node));
  30 + return (T)node;
  31 + }
  32 +
16 33 public static T ParseStatement<T>(string stmt, bool expectErrors = false) where T : INode
17 34 {
18 35 Assert.Ignore("ParseExpression not yet implemented");
2  ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
@@ -84,6 +84,7 @@
84 84 <Compile Include="CSharp\Parser\Expression\TypeOfExpressionTests.cs" />
85 85 <Compile Include="CSharp\Parser\Expression\TypeReferenceExpressionTests.cs" />
86 86 <Compile Include="CSharp\Parser\Expression\UnaryOperatorExpressionTests.cs" />
  87 + <Compile Include="CSharp\Parser\GeneralScope\AttributeSectionTests.cs" />
87 88 <Compile Include="CSharp\Parser\ParseUtil.cs" />
88 89 <Compile Include="CSharp\Resolver\BinaryOperatorTests.cs" />
89 90 <Compile Include="CSharp\Resolver\CastTests.cs" />
@@ -117,6 +118,7 @@
117 118 </ItemGroup>
118 119 <ItemGroup>
119 120 <Folder Include="CSharp\Parser\Expression" />
  121 + <Folder Include="CSharp\Parser\GeneralScope" />
120 122 </ItemGroup>
121 123 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
122 124 </Project>
4 ...rpCode.NRefactory/CSharp/Dom/AbtractDomVisitor.cs → ...pCode.NRefactory/CSharp/Dom/AbstractDomVisitor.cs
... ... @@ -1,4 +1,4 @@
1   -//
  1 +//
2 2 // IDomVisitor.cs
3 3 //
4 4 // Author:
@@ -28,7 +28,7 @@
28 28
29 29 namespace ICSharpCode.NRefactory.CSharp
30 30 {
31   - public abstract class AbtractDomVisitor<T, S> : IDomVisitor<T, S>
  31 + public abstract class AbstractDomVisitor<T, S> : IDomVisitor<T, S>
32 32 {
33 33 protected S VisitChildren (INode node, T data)
34 34 {
10 ICSharpCode.NRefactory/CSharp/Dom/DomLocation.cs
... ... @@ -1,4 +1,4 @@
1   -//
  1 +//
2 2 // DomLocation.cs
3 3 //
4 4 // Author:
@@ -63,14 +63,16 @@ public DomLocation (int line, int column) : this ()
63 63
64 64 public override bool Equals (object other)
65 65 {
66   - if (!(other is DomLocation))
  66 + if (!(other is DomLocation))
67 67 return false;
68 68 return (DomLocation)other == this;
69 69 }
70 70
71 71 public override int GetHashCode ()
72 72 {
73   - return Line + Column * 5000;
  73 + unchecked {
  74 + return Line + Column * 5000;
  75 + }
74 76 }
75 77
76 78 public bool Equals (DomLocation other)
@@ -97,7 +99,7 @@ public static DomLocation FromInvariantString (string invariantString)
97 99 if (invariantString.ToUpper () == "EMPTY")
98 100 return DomLocation.Empty;
99 101 string[] splits = invariantString.Split (',', '/');
100   - if (splits.Length == 2)
  102 + if (splits.Length == 2)
101 103 return new DomLocation (Int32.Parse (splits[0]), Int32.Parse (splits[1]));
102 104 return DomLocation.Empty;
103 105 }
12 ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
@@ -2259,12 +2259,12 @@ public CompilationUnit Parse (TextReader reader)
2259 2259 {
2260 2260 // TODO: can we optimize this to avoid the text->stream->text roundtrip?
2261 2261 using (MemoryStream stream = new MemoryStream ()) {
2262   - using (StreamWriter w = new StreamWriter(stream, Encoding.UTF8)) {
2263   - char[] buffer = new char[2048];
2264   - int read;
2265   - while ((read = reader.ReadBlock(buffer, 0, buffer.Length)) > 0)
2266   - w.Write(buffer, 0, read);
2267   - }
  2262 + StreamWriter w = new StreamWriter(stream, Encoding.UTF8);
  2263 + char[] buffer = new char[2048];
  2264 + int read;
  2265 + while ((read = reader.ReadBlock(buffer, 0, buffer.Length)) > 0)
  2266 + w.Write(buffer, 0, read);
  2267 + w.Flush(); // we can't close the StreamWriter because that would also close the MemoryStream
2268 2268 stream.Position = 0;
2269 2269 return Parse(stream);
2270 2270 }
85 ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
@@ -19,6 +19,7 @@ public class CSharpResolver
19 19 {
20 20 static readonly ResolveResult ErrorResult = new ErrorResolveResult(SharedTypes.UnknownType);
21 21 static readonly ResolveResult DynamicResult = new ResolveResult(SharedTypes.Dynamic);
  22 + static readonly ResolveResult NullResult = new ResolveResult(SharedTypes.Null);
22 23
23 24 readonly ITypeResolveContext context;
24 25
@@ -33,6 +34,13 @@ public CSharpResolver(ITypeResolveContext context)
33 34
34 35 #region Properties
35 36 /// <summary>
  37 + /// Gets the type resolve context used by the resolver.
  38 + /// </summary>
  39 + public ITypeResolveContext Context {
  40 + get { return context; }
  41 + }
  42 +
  43 + /// <summary>
36 44 /// Gets/Sets whether the current context is <c>checked</c>.
37 45 /// </summary>
38 46 public bool CheckForOverflow { get; set; }
@@ -1555,6 +1563,11 @@ public ResolveResult ResolveInvocation(ResolveResult target, ResolveResult[] arg
1555 1563 return ErrorResult;
1556 1564 }
1557 1565
  1566 + public ResolveResult ResolveIndexer(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)
  1567 + {
  1568 + throw new NotImplementedException();
  1569 + }
  1570 +
1558 1571 static List<DefaultParameter> CreateParameters(ResolveResult[] arguments, string[] argumentNames)
1559 1572 {
1560 1573 List<DefaultParameter> list = new List<DefaultParameter>();
@@ -1653,5 +1666,77 @@ public ResolveResult ResolveSizeOf(IType type)
1653 1666 return new ConstantResolveResult(int32, size);
1654 1667 }
1655 1668 #endregion
  1669 +
  1670 + #region This/Base
  1671 + /// <summary>
  1672 + /// Resolves 'this'.
  1673 + /// </summary>
  1674 + public ResolveResult ResolveThisReference()
  1675 + {
  1676 + ITypeDefinition t = CurrentTypeDefinition;
  1677 + if (t != null) {
  1678 + return new ResolveResult(t);
  1679 + }
  1680 + return ErrorResult;
  1681 + }
  1682 +
  1683 + /// <summary>
  1684 + /// Resolves 'base'.
  1685 + /// </summary>
  1686 + public ResolveResult ResolveBaseReference()
  1687 + {
  1688 + ITypeDefinition t = CurrentTypeDefinition;
  1689 + if (t != null) {
  1690 + foreach (IType baseType in t.GetBaseTypes(context)) {
  1691 + ITypeDefinition baseTypeDef = baseType.GetDefinition();
  1692 + if (baseTypeDef != null && baseTypeDef.ClassType != ClassType.Interface) {
  1693 + return new ResolveResult(baseType);
  1694 + }
  1695 + }
  1696 + }
  1697 + return ErrorResult;
  1698 + }
  1699 + #endregion
  1700 +
  1701 + #region ResolveConditional
  1702 + public ResolveResult ResolveConditional(ResolveResult trueExpression, ResolveResult falseExpression)
  1703 + {
  1704 + // C# 4.0 spec §7.14: Conditional operator
  1705 + Conversions c = new Conversions(context);
  1706 + bool isValid;
  1707 + IType resultType;
  1708 + if (HasType(trueExpression) && HasType(falseExpression)) {
  1709 + bool t2f = c.ImplicitConversion(trueExpression.Type, falseExpression.Type);
  1710 + bool f2t = c.ImplicitConversion(falseExpression.Type, trueExpression.Type);
  1711 + resultType = (f2t && !t2f) ? falseExpression.Type : trueExpression.Type;
  1712 + isValid = (t2f != f2t) || (t2f && f2t && c.IdentityConversion(trueExpression.Type, falseExpression.Type));
  1713 + } else if (HasType(trueExpression)) {
  1714 + resultType = trueExpression.Type;
  1715 + isValid = c.ImplicitConversion(falseExpression, resultType);
  1716 + } else if (HasType(falseExpression)) {
  1717 + resultType = falseExpression.Type;
  1718 + isValid = c.ImplicitConversion(trueExpression, resultType);
  1719 + } else {
  1720 + return ErrorResult;
  1721 + }
  1722 + return isValid ? new ResolveResult(resultType) : new ErrorResolveResult(resultType);
  1723 + }
  1724 +
  1725 + bool HasType(ResolveResult r)
  1726 + {
  1727 + return r.Type != SharedTypes.UnknownType && r.Type != SharedTypes.Null;
  1728 + }
  1729 + #endregion
  1730 +
  1731 + public ResolveResult ResolvePrimitive(object value)
  1732 + {
  1733 + if (value == null) {
  1734 + return NullResult;
  1735 + } else {
  1736 + TypeCode typeCode = Type.GetTypeCode(value.GetType());
  1737 + IType type = typeCode.ToTypeReference().Resolve(context);
  1738 + return new ConstantResolveResult(type, value);
  1739 + }
  1740 + }
1656 1741 }
1657 1742 }
272 ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs
... ... @@ -0,0 +1,272 @@
  1 +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2 +// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
  3 +
  4 +using System;
  5 +using System.Collections.Generic;
  6 +using System.Linq;
  7 +using ICSharpCode.NRefactory.TypeSystem;
  8 +using ICSharpCode.NRefactory.TypeSystem.Implementation;
  9 +
  10 +namespace ICSharpCode.NRefactory.CSharp.Resolver
  11 +{
  12 + /// <summary>
  13 + /// Traverses the DOM and resolves every expression.
  14 + /// </summary>
  15 + public class ResolveVisitor : AbstractDomVisitor<object, ResolveResult>
  16 + {
  17 + static readonly ResolveResult errorResult = new ErrorResolveResult(SharedTypes.UnknownType);
  18 + readonly CSharpResolver resolver;
  19 + readonly Dictionary<INode, ResolveResult> cache = new Dictionary<INode, ResolveResult>();
  20 +
  21 + /// <summary>
  22 + /// Set this property to false to skip resolving all sub expressions.
  23 + /// </summary>
  24 + public bool FullyResolveSubExpressions { get; set; }
  25 +
  26 + public ResolveVisitor(CSharpResolver resolver)
  27 + {
  28 + if (resolver == null)
  29 + throw new ArgumentNullException("resolver");
  30 + this.resolver = resolver;
  31 + this.FullyResolveSubExpressions = true;
  32 + }
  33 +
  34 + public ResolveResult Resolve(INode node)
  35 + {
  36 + ResolveResult result;
  37 + if (!cache.TryGetValue(node, out result)) {
  38 + result = cache[node] = node.AcceptVisitor(this, null) ?? errorResult;
  39 + }
  40 + return result;
  41 + }
  42 +
  43 + #region Checked / Unchecked
  44 + public override ResolveResult VisitCheckedExpression(CheckedExpression checkedExpression, object data)
  45 + {
  46 + bool oldCheckForOverflow = resolver.CheckForOverflow;
  47 + try {
  48 + resolver.CheckForOverflow = true;
  49 + return checkedExpression.Expression.AcceptVisitor(this, data);
  50 + } finally {
  51 + resolver.CheckForOverflow = oldCheckForOverflow;
  52 + }
  53 + }
  54 +
  55 + public override ResolveResult VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data)
  56 + {
  57 + bool oldCheckForOverflow = resolver.CheckForOverflow;
  58 + try {
  59 + resolver.CheckForOverflow = false;
  60 + return uncheckedExpression.Expression.AcceptVisitor(this, data);
  61 + } finally {
  62 + resolver.CheckForOverflow = oldCheckForOverflow;
  63 + }
  64 + }
  65 +
  66 + public override ResolveResult VisitCheckedStatement(CheckedStatement checkedStatement, object data)
  67 + {
  68 + bool oldCheckForOverflow = resolver.CheckForOverflow;
  69 + try {
  70 + resolver.CheckForOverflow = true;
  71 + return base.VisitCheckedStatement(checkedStatement, data);
  72 + } finally {
  73 + resolver.CheckForOverflow = oldCheckForOverflow;
  74 + }
  75 + }
  76 +
  77 + public override ResolveResult VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data)
  78 + {
  79 + bool oldCheckForOverflow = resolver.CheckForOverflow;
  80 + try {
  81 + resolver.CheckForOverflow = true;
  82 + return base.VisitUncheckedStatement(uncheckedStatement, data);
  83 + } finally {
  84 + resolver.CheckForOverflow = oldCheckForOverflow;
  85 + }
  86 + }
  87 + #endregion
  88 +
  89 + static bool IsTargetOfInvocation(INode node)
  90 + {
  91 + InvocationExpression ie = node.Parent as InvocationExpression;
  92 + return ie != null && ie.Target == node;
  93 + }
  94 +
  95 + IType ResolveType(INode node)
  96 + {
  97 + return SharedTypes.UnknownType;
  98 + }
  99 +
  100 + public override ResolveResult VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
  101 + {
  102 + throw new NotImplementedException();
  103 + }
  104 +
  105 + public override ResolveResult VisitArgListExpression(ArgListExpression argListExpression, object data)
  106 + {
  107 + return new ResolveResult(resolver.Context.GetClass(typeof(RuntimeArgumentHandle)) ?? SharedTypes.UnknownType);
  108 + }
  109 +
  110 + public override ResolveResult VisitArrayObjectCreateExpression(ArrayObjectCreateExpression arrayObjectCreateExpression, object data)
  111 + {
  112 + throw new NotImplementedException();
  113 + }
  114 +
  115 + public override ResolveResult VisitAsExpression(AsExpression asExpression, object data)
  116 + {
  117 + if (FullyResolveSubExpressions)
  118 + Resolve(asExpression.Expression);
  119 + return new ResolveResult(ResolveType(asExpression.TypeReference));
  120 + }
  121 +
  122 + public override ResolveResult VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
  123 + {
  124 + ResolveResult left = Resolve(assignmentExpression.Left);
  125 + if (FullyResolveSubExpressions) {
  126 + Resolve(assignmentExpression.Right);
  127 + }
  128 + return new ResolveResult(left.Type);
  129 + }
  130 +
  131 + public override ResolveResult VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data)
  132 + {
  133 + return resolver.ResolveBaseReference();
  134 + }
  135 +
  136 + public override ResolveResult VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
  137 + {
  138 + ResolveResult left = Resolve(binaryOperatorExpression.Left);
  139 + ResolveResult right = Resolve(binaryOperatorExpression.Right);
  140 + return resolver.ResolveBinaryOperator(binaryOperatorExpression.BinaryOperatorType, left, right);
  141 + }
  142 +
  143 + public override ResolveResult VisitCastExpression(CastExpression castExpression, object data)
  144 + {
  145 + return resolver.ResolveCast(ResolveType(castExpression.CastTo), Resolve(castExpression.Expression));
  146 + }
  147 +
  148 + public override ResolveResult VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
  149 + {
  150 + if (FullyResolveSubExpressions)
  151 + Resolve(conditionalExpression.Condition);
  152 + return resolver.ResolveConditional(Resolve(conditionalExpression.TrueExpression),
  153 + Resolve(conditionalExpression.FalseExpression));
  154 + }
  155 +
  156 + public override ResolveResult VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data)
  157 + {
  158 + return new ConstantResolveResult(ResolveType(defaultValueExpression.TypeReference), null);
  159 + }
  160 +
  161 + public override ResolveResult VisitDirectionExpression(DirectionExpression directionExpression, object data)
  162 + {
  163 + ResolveResult rr = Resolve(directionExpression.Expression);
  164 + return new ResolveResult(new ByReferenceType(rr.Type));
  165 + }
  166 +
  167 + public override ResolveResult VisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
  168 + {
  169 + // TODO: type arguments?
  170 + return resolver.ResolveSimpleName(identifierExpression.Identifier.Name, null,
  171 + IsTargetOfInvocation(identifierExpression));
  172 + }
  173 +
  174 + public override ResolveResult VisitIndexerExpression(IndexerExpression indexerExpression, object data)
  175 + {
  176 + ResolveResult target = Resolve(indexerExpression.Target);
  177 + // TODO: add support for named arguments
  178 + var argumentExpressions = indexerExpression.Arguments.ToList();
  179 + ResolveResult[] arguments = new ResolveResult[argumentExpressions.Count];
  180 + for (int i = 0; i < arguments.Length; i++) {
  181 + arguments[i] = Resolve(argumentExpressions[i]);
  182 + }
  183 + return resolver.ResolveIndexer(target, arguments);
  184 + }
  185 +
  186 + public override ResolveResult VisitInvocationExpression(InvocationExpression invocationExpression, object data)
  187 + {
  188 + ResolveResult target = Resolve(invocationExpression.Target);
  189 + // TODO: add support for named arguments
  190 + var argumentExpressions = invocationExpression.Arguments.ToList();
  191 + ResolveResult[] arguments = new ResolveResult[argumentExpressions.Count];
  192 + for (int i = 0; i < arguments.Length; i++) {
  193 + arguments[i] = Resolve(argumentExpressions[i]);
  194 + }
  195 + return resolver.ResolveInvocation(target, arguments);
  196 + }
  197 +
  198 + public override ResolveResult VisitIsExpression(IsExpression isExpression, object data)
  199 + {
  200 + if (FullyResolveSubExpressions)
  201 + ResolveType(isExpression.TypeReference);
  202 + return new ResolveResult(TypeCode.Boolean.ToTypeReference().Resolve(resolver.Context));
  203 + }
  204 +
  205 + public override ResolveResult VisitLambdaExpression(LambdaExpression lambdaExpression, object data)
  206 + {
  207 + throw new NotImplementedException();
  208 + }
  209 +
  210 + public override ResolveResult VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
  211 + {
  212 + throw new NotImplementedException();
  213 + }
  214 +
  215 + public override ResolveResult VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, object data)
  216 + {
  217 + return resolver.ResolvePrimitive(null);
  218 + }
  219 +
  220 + public override ResolveResult VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
  221 + {
  222 + throw new NotImplementedException();
  223 + }
  224 +
  225 + public override ResolveResult VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
  226 + {
  227 + return Resolve(parenthesizedExpression.Expression);
  228 + }
  229 +
  230 + public override ResolveResult VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data)
  231 + {
  232 + throw new NotImplementedException();
  233 + }
  234 +
  235 + public override ResolveResult VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
  236 + {
  237 + return resolver.ResolvePrimitive(primitiveExpression.Value);
  238 + }
  239 +
  240 + public override ResolveResult VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data)
  241 + {
  242 + return resolver.ResolveSizeOf(ResolveType(sizeOfExpression.Type));
  243 + }
  244 +
  245 + public override ResolveResult VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data)
  246 + {
  247 + if (FullyResolveSubExpressions)
  248 + Resolve(stackAllocExpression.CountExpression);
  249 + return new ResolveResult(new PointerType(ResolveType(stackAllocExpression.Type)));
  250 + }
  251 +
  252 + public override ResolveResult VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
  253 + {
  254 + return resolver.ResolveThisReference();
  255 + }
  256 +
  257 + static readonly GetClassTypeReference systemType = new GetClassTypeReference("System.Type", 0);
  258 +
  259 + public override ResolveResult VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data)
  260 + {
  261 + if (FullyResolveSubExpressions)
  262 + ResolveType(typeOfExpression.Type);
  263 + return new ResolveResult(systemType.Resolve(resolver.Context));
  264 + }
  265 +
  266 + public override ResolveResult VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
  267 + {
  268 + ResolveResult expr = Resolve(unaryOperatorExpression.Expression);
  269 + return resolver.ResolveUnaryOperator(unaryOperatorExpression.UnaryOperatorType, expr);
  270 + }
  271 + }
  272 +}
3  ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
@@ -56,7 +56,7 @@
56 56 </ItemGroup>
57 57 <ItemGroup>
58 58 <Compile Include="CSharp\Dom\AbstractNode.cs" />
59   - <Compile Include="CSharp\Dom\AbtractDomVisitor.cs" />
  59 + <Compile Include="CSharp\Dom\AbstractDomVisitor.cs" />
60 60 <Compile Include="CSharp\Dom\CompilationUnit.cs" />
61 61 <Compile Include="CSharp\Dom\CSharpModifierToken.cs" />
62 62 <Compile Include="CSharp\Dom\CSharpTokenNode.cs" />
@@ -167,6 +167,7 @@
167 167 <Compile Include="CSharp\Resolver\OverloadResolution.cs" />
168 168 <Compile Include="CSharp\Resolver\OverloadResolutionErrors.cs" />
169 169 <Compile Include="CSharp\Resolver\ResolveResult.cs" />
  170 + <Compile Include="CSharp\Resolver\ResolveVisitor.cs" />
170 171 <Compile Include="CSharp\Resolver\SimpleTypeOrNamespaceReference.cs" />
171 172 <Compile Include="CSharp\Resolver\TypeInference.cs" />
172 173 <Compile Include="CSharp\Resolver\TypeResolveResult.cs" />

0 comments on commit a7e253e

Please sign in to comment.
Something went wrong with that request. Please try again.