Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer Parsing #1820

Merged
merged 7 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DMCompiler/Compiler/DM/AST/DMAST.ExpressionUnary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public sealed class DMASTPreIncrement(Location location, DMASTExpression express
public sealed class DMASTPreDecrement(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTPostIncrement(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTPostDecrement(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTPointerRef(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTPointerDeref(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTSin(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTCos(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
public sealed class DMASTTan(Location location, DMASTExpression expression) : DMASTUnary(location, expression);
Expand Down
6 changes: 5 additions & 1 deletion DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,9 @@ private void ExpressionTo(out DMASTExpression endRange, out DMASTExpression? ste
TokenType.DM_Exclamation,
TokenType.DM_Tilde,
TokenType.DM_PlusPlus,
TokenType.DM_MinusMinus
TokenType.DM_MinusMinus,
TokenType.DM_And,
TokenType.DM_Star
}, out var unaryToken)) {
Whitespace();
DMASTExpression? expression = ExpressionUnary(isTernaryB);
Expand All @@ -2071,6 +2073,8 @@ private void ExpressionTo(out DMASTExpression endRange, out DMASTExpression? ste
case TokenType.DM_Tilde: return new DMASTBinaryNot(loc, expression);
case TokenType.DM_PlusPlus: return new DMASTPreIncrement(loc, expression);
case TokenType.DM_MinusMinus: return new DMASTPreDecrement(loc, expression);
case TokenType.DM_And: return new DMASTPointerRef(loc, expression);
case TokenType.DM_Star: return new DMASTPointerDeref(loc, expression);
}

Emit(WarningCode.BadToken, loc, $"Problem while handling unary '{unaryToken.PrintableText}'");
Expand Down
4 changes: 4 additions & 0 deletions DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public static DMExpression BuildExpression(DMASTExpression expression, DMObject
return new PreDecrement(preDecrement.Location, BuildExpression(preDecrement.Value, dmObject, proc, inferredPath));
case DMASTPostDecrement postDecrement:
return new PostDecrement(postDecrement.Location, BuildExpression(postDecrement.Value, dmObject, proc, inferredPath));
case DMASTPointerRef pointerRef:
return new PointerRef(pointerRef.Location, BuildExpression(pointerRef.Value, dmObject, proc, inferredPath));
case DMASTPointerDeref pointerDeref:
return new PointerDeref(pointerDeref.Location, BuildExpression(pointerDeref.Value, dmObject, proc, inferredPath));
case DMASTGradient gradient:
return new Gradient(gradient.Location,
new ArgumentList(gradient.Location, dmObject, proc, gradient.Parameters));
Expand Down
28 changes: 28 additions & 0 deletions DMCompiler/DM/Expressions/Unary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,32 @@
proc.Decrement(reference);
}
}

// &x
internal sealed class PointerRef(Location location, DMExpression expr) : AssignmentUnaryOp(location, expr) {

Check warning on line 128 in DMCompiler/DM/Expressions/Unary.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Parameter 'Location location' is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
Fixed Show fixed Hide fixed
ike709 marked this conversation as resolved.
Show resolved Hide resolved
protected override void EmitOp(DMObject dmObject, DMProc proc, DMReference reference, string endLabel) { }

public override void EmitPushValue(DMObject dmObject, DMProc proc) {
Expr.EmitPushValue(dmObject, proc);
DMCompiler.UnimplementedWarning(location, "Pointers are currently unimplemented and identifiers will be treated as normal variables.");
ike709 marked this conversation as resolved.
Show resolved Hide resolved
}

public override DMReference EmitReference(DMObject dmObject, DMProc proc, string endLabel, ShortCircuitMode shortCircuitMode) {
Fixed Show fixed Hide fixed
ike709 marked this conversation as resolved.
Show resolved Hide resolved
return Expr.EmitReference(dmObject, proc, endLabel, shortCircuitMode);
}
}

// *x
internal sealed class PointerDeref(Location location, DMExpression expr) : AssignmentUnaryOp(location, expr) {

Check warning on line 142 in DMCompiler/DM/Expressions/Unary.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Parameter 'Location location' is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
Fixed Show fixed Hide fixed
protected override void EmitOp(DMObject dmObject, DMProc proc, DMReference reference, string endLabel) { }

public override void EmitPushValue(DMObject dmObject, DMProc proc) {
Expr.EmitPushValue(dmObject, proc);
DMCompiler.UnimplementedWarning(location, "Pointers are currently unimplemented and identifiers will be treated as normal variables.");
ike709 marked this conversation as resolved.
Show resolved Hide resolved
}

public override DMReference EmitReference(DMObject dmObject, DMProc proc, string endLabel, ShortCircuitMode shortCircuitMode) {
Fixed Show fixed Hide fixed
ike709 marked this conversation as resolved.
Show resolved Hide resolved
return Expr.EmitReference(dmObject, proc, endLabel, shortCircuitMode);
}
}
}
Loading