-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c98aae4
commit b25f204
Showing
11 changed files
with
1,096 additions
and
7 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
...t.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/FoldExpressionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Igor V. Kovalenko. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Igor V. Kovalenko - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.core.parser.tests.ast2.cxx17; | ||
|
||
import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; | ||
|
||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; | ||
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; | ||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; | ||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; | ||
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTestBase; | ||
|
||
/** | ||
* AST tests for C++17 fold expressions. | ||
*/ | ||
public class FoldExpressionTests extends AST2CPPTestBase { | ||
// using size_t = decltype(sizeof(int)); | ||
// | ||
// template<typename T> struct X { | ||
// static constexpr size_t g(const T& arg) noexcept { return sizeof(arg); } | ||
// }; | ||
// | ||
// template<typename... Pack> | ||
// constexpr size_t f1(const Pack&... pack) { return (... + X<Pack>::g(pack)); } | ||
// template<typename... Pack> | ||
// constexpr size_t f2(const Pack&... pack) { return (0 + ... + X<Pack>::g(pack)); } | ||
// template<typename... Pack> | ||
// constexpr size_t f3(const Pack&... pack) { return (X<Pack>::g(pack) + ...); } | ||
// template<typename... Pack> | ||
// constexpr size_t f4(const Pack&... pack) { return (X<Pack>::g(pack) + ... + 0); } | ||
// | ||
// static constexpr auto val1 = f1(1, 2., "1"); | ||
// static constexpr auto val2 = f2(1, 2., "12"); | ||
// static constexpr auto val3 = f3(1, 2., "123"); | ||
// static constexpr auto val4 = f4(1, 2., "1234"); | ||
public void testFoldExpression1() throws Exception { | ||
parseAndCheckBindings(); | ||
BindingAssertionHelper helper = getAssertionHelper(); | ||
helper.assertVariableValue("val1", 14); | ||
helper.assertVariableValue("val2", 15); | ||
helper.assertVariableValue("val3", 16); | ||
helper.assertVariableValue("val4", 17); | ||
} | ||
|
||
// template<typename... Pack> | ||
// constexpr bool f1(const Pack&... pack) { return (... && pack); } | ||
// template<typename... Pack> | ||
// constexpr bool f2(const Pack&... pack) { return (pack && ...); } | ||
// template<typename... Pack> | ||
// constexpr bool f3(const Pack&... pack) { return (... || pack); } | ||
// template<typename... Pack> | ||
// constexpr bool f4(const Pack&... pack) { return (pack || ...); } | ||
// | ||
// static constexpr auto val1 = f1(); | ||
// static constexpr auto val21 = f2(false); | ||
// static constexpr auto val22 = f2(true); | ||
// static constexpr auto val3 = f3(); | ||
// static constexpr auto val41 = f4(false); | ||
// static constexpr auto val42 = f4(true); | ||
public void testFoldExpression2() throws Exception { | ||
parseAndCheckBindings(); | ||
BindingAssertionHelper helper = getAssertionHelper(); | ||
helper.assertVariableValue("val1", 1); | ||
helper.assertVariableValue("val21", 0); | ||
helper.assertVariableValue("val22", 1); | ||
helper.assertVariableValue("val3", 0); | ||
helper.assertVariableValue("val41", 0); | ||
helper.assertVariableValue("val42", 1); | ||
} | ||
|
||
// template <typename CharT> | ||
// struct ostream { | ||
// template <typename T> | ||
// ostream& operator<<(T); | ||
// | ||
// ostream& operator<<(ostream&(*)(ostream&)); | ||
// }; | ||
// | ||
// template <typename CharT> | ||
// ostream<CharT>& endl(ostream<CharT>&); | ||
// | ||
// template <typename... T> | ||
// void sum(T... vals) { | ||
// ostream<char> out; | ||
// out << (... + vals) << endl; | ||
// } | ||
public void testFoldExpressionInBinaryExpression() throws Exception { | ||
parseAndCheckBindings(); | ||
} | ||
|
||
// template<typename... T> | ||
// void sum(T... vals) { | ||
// bar(... + vals); | ||
// } | ||
public void testFoldExpressionRecognition1() throws Exception { | ||
final String code = getAboveComment(); | ||
IASTTranslationUnit tu = parse(code, CPP, ScannerKind.STD, false); | ||
ICPPASTTemplateDeclaration tdef = getDeclaration(tu, 0); | ||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration(); | ||
IASTProblemStatement p1 = getStatement(fdef, 0); | ||
} | ||
|
||
// template<typename... T> | ||
// void sum(T... vals) { | ||
// ... + vals; | ||
// } | ||
public void testFoldExpressionRecognition2() throws Exception { | ||
final String code = getAboveComment(); | ||
IASTTranslationUnit tu = parse(code, CPP, ScannerKind.STD, false); | ||
ICPPASTTemplateDeclaration tdef = getDeclaration(tu, 0); | ||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration(); | ||
IASTProblemStatement p1 = getStatement(fdef, 0); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFoldExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Igor V. Kovalenko. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Igor V. Kovalenko - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.core.dom.ast.cpp; | ||
|
||
/** | ||
* Fold expression, introduced in C++17. | ||
* | ||
* @since 8.0 | ||
* @noextend This interface is not intended to be extended by clients. | ||
* @noimplement This interface is not intended to be implemented by clients. | ||
*/ | ||
|
||
public interface ICPPASTFoldExpression extends ICPPASTExpression { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.