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

Added min/max operators... #20626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions compiler/src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,11 @@
else
t.value = TOK.leftShift; // <<
}
else if (*p == '?')
{
++p;
t.value = TOK.ltQuestion; // <?

Check warning on line 1154 in compiler/src/dmd/lexer.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/lexer.d#L1153-L1154

Added lines #L1153 - L1154 were not covered by tests
}
else if (*p == ':' && Ccompile)
{
++p;
Expand Down Expand Up @@ -1187,6 +1192,11 @@
else
t.value = TOK.unsignedRightShift; // >>>
}
else if (*p == '?')
{
p++;
t.value = TOK.gtQuestion; // >?

Check warning on line 1198 in compiler/src/dmd/lexer.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/lexer.d#L1197-L1198

Added lines #L1197 - L1198 were not covered by tests
}
else
t.value = TOK.rightShift; // >>
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -9156,6 +9156,14 @@
e = new AST.CatExp(loc, e, e2);
continue;

case TOK.ltQuestion:
case TOK.gtQuestion:
EXP op = token.value == TOK.ltQuestion ? EXP.lessThan : EXP.greaterThan;
nextToken();
auto e2 = parseMulExp();
e = new AST.CondExp(loc, new AST.CmpExp(op, loc, e, e2), e, e2);
continue;

Check warning on line 9165 in compiler/src/dmd/parse.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/parse.d#L9159-L9165

Added lines #L9159 - L9165 were not covered by tests

default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dmd/tokens.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ enum TOK : ubyte
identity,
notIdentity,
is_,
ltQuestion,
gtQuestion,

leftShift,
rightShift,
Expand Down Expand Up @@ -846,6 +848,8 @@ extern (C++) struct Token
TOK.pound: "#",
TOK.arrow: "->",
TOK.colonColon: "::",
TOK.ltQuestion: "<?",
TOK.gtQuestion: ">?",

// For debugging
TOK.error: "error",
Expand Down
Loading