|
|
|
@ -16,17 +16,15 @@
@@ -16,17 +16,15 @@
|
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
|
using ICSharpCode.Decompiler.CSharp.Syntax; |
|
|
|
|
using ICSharpCode.Decompiler.Semantics; |
|
|
|
|
using ICSharpCode.Decompiler.TypeSystem; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.Decompiler.CSharp.Transforms |
|
|
|
|
{ |
|
|
|
|
public class IntroduceUnsafeModifier : DepthFirstAstVisitor<bool>, IAstTransform |
|
|
|
|
{ |
|
|
|
|
public static readonly object PointerArithmeticAnnotation = new PointerArithmetic(); |
|
|
|
|
|
|
|
|
|
sealed class PointerArithmetic {} |
|
|
|
|
|
|
|
|
|
public void Run(AstNode compilationUnit, TransformContext context) |
|
|
|
|
{ |
|
|
|
|
compilationUnit.AcceptVisitor(this); |
|
|
|
@ -67,8 +65,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -67,8 +65,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
{ |
|
|
|
|
bool result = base.VisitUnaryOperatorExpression(unaryOperatorExpression); |
|
|
|
|
if (unaryOperatorExpression.Operator == UnaryOperatorType.Dereference) { |
|
|
|
|
BinaryOperatorExpression bop = unaryOperatorExpression.Expression as BinaryOperatorExpression; |
|
|
|
|
if (bop != null && bop.Operator == BinaryOperatorType.Add && bop.Annotation<PointerArithmetic>() != null) { |
|
|
|
|
var bop = unaryOperatorExpression.Expression as BinaryOperatorExpression; |
|
|
|
|
if (bop != null && bop.Operator == BinaryOperatorType.Add |
|
|
|
|
&& bop.GetResolveResult() is OperatorResolveResult orr |
|
|
|
|
&& orr.Operands.FirstOrDefault()?.Type.Kind == TypeKind.Pointer) |
|
|
|
|
{ |
|
|
|
|
// transform "*(ptr + int)" to "ptr[int]"
|
|
|
|
|
IndexerExpression indexer = new IndexerExpression(); |
|
|
|
|
indexer.Target = bop.Left.Detach(); |
|
|
|
|