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

parse more c++ expression alternatives #296

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11419,4 +11419,78 @@ public void testParameterPackExpansions_array() throws Exception {
helper.assertVariableValue("val1", 4);
helper.assertVariableValue("val2", 8);
}

// template <typename T>
// inline constexpr bool V = true;
//
// template<typename T> bool f() {
// return V<T> + V<T>;
// }
public void testBinaryExpressionWithVariableTemplateVsPlusUnaryExpression() throws Exception {
parseAndCheckBindings();
}

// template <typename T>
// inline constexpr bool V = true;
//
// template<typename T> bool f() {
// return V<T> || V<T>;
// }
public void testBinaryExpressionWithVariableTemplate() throws Exception {
parseAndCheckBindings();
}

// template <typename T>
// inline constexpr bool V = true;
//
// template<typename T> bool f() {
// return V<T> && V<T>; // can be parsed as V < T > &&V<T>
// }
public void testBinaryExpressionWithVariableTemplateAmbiguousLabelReference() throws Exception {
parseAndCheckBindings();
}

// template <typename T>
// inline constexpr bool W = true;
// template <typename T>
// inline constexpr bool X = true;
// template <typename T>
// inline constexpr bool Y = true;
// template <typename T>
// inline constexpr bool Z = true;
//
// template<typename T> bool f() {
// return W<T> && X<T> && Y<T> && Z<T>; // can be parsed as (W) < (T) > (&&X<T>) ...
// }
public void testBinaryExpressionWithVariableTemplateDeep() throws Exception {
parseAndCheckBindings();
}

// constexpr int factorial(int n) {
// return n < 2 ? 1 : n * factorial(n - 1);
// }
//
// int f();
//
// template <int>
// class A {
// template <int> class Waldo {
// static void f();
// };
// };
//
// template <>
// class A<120> {
// public:
// static int Waldo;
// };
//
// int main() {
// // This requires constexpr evaluation to find that return type of factorial(5) is int
// // to decide if A<int>::Waldo is a template
// A<factorial(5)>::Waldo<0>::f();
// }
public void testBinaryExpressionWithVariableTemplate_bug497931_comment8() throws Exception {
parseAndCheckBindings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,14 @@ private int endsTemplateIDInBinaryExpression() {
case IToken.tLPAREN: // 'ft<int>(args)' or 'c<1 && 2 > (x+y)'
return AMBIGUOUS_TEMPLATE_ID;

// Start of unary expression
// Can be start of unary expression or binary expression with a template-id
case IToken.tMINUS:
case IToken.tPLUS:
case IToken.tAMPER:
case IToken.tSTAR:
case IToken.tAND:
return AMBIGUOUS_TEMPLATE_ID;

case IToken.tNOT:
case IToken.tBITCOMPLEMENT:
case IToken.tINCR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ public void closeVariants(int offset, BinaryOperator lastOperator) {

public Variant selectFallback() {
// Search for an open variant, with a small right offset and a large left offset
Variant best = null;
for (BranchPoint p = fFirst; p != null; p = p.getNext()) {
Variant best = null;
for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) {
if (v.getTargetOperator() == null) {
if (best == null || v.fRightOffset < best.fRightOffset) {
best = v;
}
}
}
if (best != null) {
remove(best);
return best;
}
}
if (best != null) {
remove(best);
return best;
}
return null;
}
Expand Down