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

start declaration resolver and tests #133

Merged
merged 1 commit into from
Jul 7, 2024
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
2 changes: 2 additions & 0 deletions C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ set(CFE_SOURCES
${PROJECT_SOURCE_DIR}/tests/ParserTester_3000_3999.cpp
${PROJECT_SOURCE_DIR}/tests/ReparserTester.h
${PROJECT_SOURCE_DIR}/tests/ReparserTester.cpp
${PROJECT_SOURCE_DIR}/tests/DeclarationResolverTester.h
${PROJECT_SOURCE_DIR}/tests/DeclarationResolverTester.cpp
${PROJECT_SOURCE_DIR}/tests/SemanticModelTester.h
${PROJECT_SOURCE_DIR}/tests/SemanticModelTester.cpp
${PROJECT_SOURCE_DIR}/tests/TestExpectation.h
Expand Down
1 change: 1 addition & 0 deletions C/binder/DeclarationResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SyntaxVisitor::Action DeclarationResolver::visitIdentifierDeclarator(const Ident
NameSpace::OrdinaryIdentifiers);
if (tyDecl) {
// TODO
std::cout << "got it " << std::endl;
}
break;
}
Expand Down
67 changes: 67 additions & 0 deletions C/tests/DeclarationResolverTester.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) 2024 Leandro T. C. Melo <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "DeclarationResolverTester.h"

using namespace psy;
using namespace C;

const std::string DeclarationResolverTester::Name = "DECLARATION-RESOLVER";

void DeclarationResolverTester::testDeclarationResolver()
{
return run<DeclarationResolverTester>(tests_);
}

void DeclarationResolverTester::resolve(std::string text, Expectation X)
{
(static_cast<InternalsTestSuite*>(suite_)->resolve(text, X));
}

void DeclarationResolverTester::case0000(){}
void DeclarationResolverTester::case0001(){}
void DeclarationResolverTester::case0002(){}
void DeclarationResolverTester::case0003(){}
void DeclarationResolverTester::case0004(){}
void DeclarationResolverTester::case0005(){}
void DeclarationResolverTester::case0006(){}
void DeclarationResolverTester::case0007(){}
void DeclarationResolverTester::case0008(){}
void DeclarationResolverTester::case0009(){}
void DeclarationResolverTester::case0010(){}
void DeclarationResolverTester::case0011(){}
void DeclarationResolverTester::case0012(){}
void DeclarationResolverTester::case0013(){}
void DeclarationResolverTester::case0014(){}
void DeclarationResolverTester::case0015(){}
void DeclarationResolverTester::case0016(){}
void DeclarationResolverTester::case0017(){}
void DeclarationResolverTester::case0018(){}
void DeclarationResolverTester::case0019(){}
void DeclarationResolverTester::case0020(){}
void DeclarationResolverTester::case0021(){}
void DeclarationResolverTester::case0022(){}
void DeclarationResolverTester::case0023(){}
void DeclarationResolverTester::case0024(){}
void DeclarationResolverTester::case0025(){}
void DeclarationResolverTester::case0026(){}
void DeclarationResolverTester::case0027(){}
void DeclarationResolverTester::case0028(){}
void DeclarationResolverTester::case0029(){}
123 changes: 123 additions & 0 deletions C/tests/DeclarationResolverTester.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright (c) 2024 Leandro T. C. Melo <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef PSYCHE_C_DECLARATION_RESOLVER_TESTER_H__
#define PSYCHE_C_DECLARATION_RESOLVER_TESTER_H__

#include "Fwds.h"
#include "TestSuite_Internals.h"
#include "tests/Tester.h"

#define TEST_DECLARATION_RESOLVER(Function) TestFunction { &DeclarationResolverTester::Function, #Function }

namespace psy {
namespace C {

class DeclarationResolverTester final : public Tester
{
public:
DeclarationResolverTester(TestSuite* suite)
: Tester(suite)
{}

static const std::string Name;
virtual std::string name() const override { return Name; }

void testDeclarationResolver();

void resolve(std::string text, Expectation X);

using TestFunction = std::pair<std::function<void(DeclarationResolverTester*)>, const char*>;

/*
xxxx
+ 0000-0099 -> multiplication x pointer declaration
*/

void case0000();
void case0001();
void case0002();
void case0003();
void case0004();
void case0005();
void case0006();
void case0007();
void case0008();
void case0009();
void case0010();
void case0011();
void case0012();
void case0013();
void case0014();
void case0015();
void case0016();
void case0017();
void case0018();
void case0019();
void case0020();
void case0021();
void case0022();
void case0023();
void case0024();
void case0025();
void case0026();
void case0027();
void case0028();
void case0029();

std::vector<TestFunction> tests_
{
TEST_DECLARATION_RESOLVER(case0000),
TEST_DECLARATION_RESOLVER(case0001),
TEST_DECLARATION_RESOLVER(case0002),
TEST_DECLARATION_RESOLVER(case0003),
TEST_DECLARATION_RESOLVER(case0004),
TEST_DECLARATION_RESOLVER(case0005),
TEST_DECLARATION_RESOLVER(case0006),
TEST_DECLARATION_RESOLVER(case0007),
TEST_DECLARATION_RESOLVER(case0008),
TEST_DECLARATION_RESOLVER(case0009),
TEST_DECLARATION_RESOLVER(case0010),
TEST_DECLARATION_RESOLVER(case0011),
TEST_DECLARATION_RESOLVER(case0012),
TEST_DECLARATION_RESOLVER(case0013),
TEST_DECLARATION_RESOLVER(case0014),
TEST_DECLARATION_RESOLVER(case0015),
TEST_DECLARATION_RESOLVER(case0016),
TEST_DECLARATION_RESOLVER(case0017),
TEST_DECLARATION_RESOLVER(case0018),
TEST_DECLARATION_RESOLVER(case0019),
TEST_DECLARATION_RESOLVER(case0020),
TEST_DECLARATION_RESOLVER(case0021),
TEST_DECLARATION_RESOLVER(case0022),
TEST_DECLARATION_RESOLVER(case0023),
TEST_DECLARATION_RESOLVER(case0024),
TEST_DECLARATION_RESOLVER(case0025),
TEST_DECLARATION_RESOLVER(case0026),
TEST_DECLARATION_RESOLVER(case0027),
TEST_DECLARATION_RESOLVER(case0028),
TEST_DECLARATION_RESOLVER(case0029),
};
};

} // C
} // psy

#endif
20 changes: 18 additions & 2 deletions C/tests/TestSuite_Internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "BinderTester.h"
#include "ParserTester.h"
#include "ReparserTester.h"
#include "DeclarationResolverTester.h"

#include "../common/infra/Assertions.h"

Expand Down Expand Up @@ -66,16 +67,22 @@ std::tuple<int, int> InternalsTestSuite::testAll()
auto C = std::make_unique<BinderTester>(this);
C->testBinder();

auto D = std::make_unique<DeclarationResolverTester>(this);
D->testDeclarationResolver();

auto res = std::make_tuple(P->totalPassed()
+ B->totalPassed()
+ C->totalPassed(),
+ C->totalPassed()
+ D->totalPassed(),
P->totalFailed()
+ B->totalFailed()
+ C->totalFailed());
+ C->totalFailed()
+ D->totalFailed());

testers_.emplace_back(P.release());
testers_.emplace_back(B.release());
testers_.emplace_back(C.release());
testers_.emplace_back(D.release());

return res;
}
Expand Down Expand Up @@ -776,5 +783,14 @@ void InternalsTestSuite::bind(std::string text, Expectation X)
PSY_EXPECT_TRUE(sameDecl);
PSY_EXPECT_TRUE(symbolMatchesBinding(sameDecl, declSummary));
}

// resolution
// decl
}
}

void InternalsTestSuite::resolve(std::string text, Expectation X)
{
bind(text, X);
}

3 changes: 3 additions & 0 deletions C/tests/TestSuite_Internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class InternalsTestSuite : public TestSuite
friend class ParserTester;
friend class ReparserTester;
friend class BinderTester;
friend class DeclarationResolverTester;

public:
virtual ~InternalsTestSuite();
Expand Down Expand Up @@ -71,6 +72,8 @@ class InternalsTestSuite : public TestSuite

void bind(std::string text, Expectation X = Expectation());

void resolve(std::string text, Expectation X = Expectation());

std::unique_ptr<SyntaxTree> tree_;
std::unique_ptr<Compilation> compilation_;
std::vector<std::unique_ptr<Tester>> testers_;
Expand Down
Loading