Skip to content

Commit dde8dad

Browse files
committedDec 30, 2024
Add CompilerContext class
·
v0.13.3v0.13.0
1 parent e8d2abe commit dde8dad

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed
 

‎CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ if (LIBSCRATCHCPP_USE_LLVM)
7474
target_sources(scratchcpp
7575
PUBLIC
7676
include/scratchcpp/dev/compiler.h
77+
include/scratchcpp/dev/compilercontext.h
7778
include/scratchcpp/dev/compilervalue.h
7879
include/scratchcpp/dev/compilerconstant.h
7980
include/scratchcpp/dev/compilerlocalvariable.h
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include "../global.h"
6+
#include "../spimpl.h"
7+
8+
namespace libscratchcpp
9+
{
10+
11+
class IEngine;
12+
class Target;
13+
class CompilerContextPrivate;
14+
15+
/*! \brief The CompilerContext represents a context for a specific target which is used with the Compiler class. */
16+
class LIBSCRATCHCPP_EXPORT CompilerContext
17+
{
18+
public:
19+
CompilerContext(IEngine *engine, Target *target);
20+
CompilerContext(const CompilerContext &) = delete;
21+
virtual ~CompilerContext() { }
22+
23+
IEngine *engine() const;
24+
Target *target() const;
25+
26+
private:
27+
spimpl::unique_impl_ptr<CompilerContextPrivate> impl;
28+
};
29+
30+
} // namespace libscratchcpp

‎src/dev/engine/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ target_sources(scratchcpp
33
compiler.cpp
44
compiler_p.cpp
55
compiler_p.h
6+
compilercontext.cpp
7+
compilercontext_p.cpp
8+
compilercontext_p.h
69
compilervalue.cpp
710
compilervalue_p.cpp
811
compilervalue_p.h

‎src/dev/engine/compilercontext.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include <scratchcpp/dev/compilercontext.h>
4+
5+
#include "compilercontext_p.h"
6+
7+
using namespace libscratchcpp;
8+
9+
/*! Constructs CompilerContext. */
10+
CompilerContext::CompilerContext(IEngine *engine, Target *target) :
11+
impl(spimpl::make_unique_impl<CompilerContextPrivate>(engine, target))
12+
{
13+
}
14+
15+
/*! Returns the engine of the project. */
16+
IEngine *CompilerContext::engine() const
17+
{
18+
return impl->engine;
19+
}
20+
21+
/*! Returns the target of this context. */
22+
Target *CompilerContext::target() const
23+
{
24+
return impl->target;
25+
}

‎src/dev/engine/compilercontext_p.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "compilercontext_p.h"
4+
5+
using namespace libscratchcpp;
6+
7+
CompilerContextPrivate::CompilerContextPrivate(IEngine *engine, Target *target) :
8+
engine(engine),
9+
target(target)
10+
{
11+
}

‎src/dev/engine/compilercontext_p.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class IEngine;
9+
class Target;
10+
11+
struct CompilerContextPrivate
12+
{
13+
CompilerContextPrivate(IEngine *engine, Target *target);
14+
15+
IEngine *engine = nullptr;
16+
Target *target = nullptr;
17+
};
18+
19+
} // namespace libscratchcpp

‎test/dev/compiler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_executable(
22
compiler_test
33
compiler_test.cpp
4+
compilercontext_test.cpp
45
compilervalue_test.cpp
56
compilerconstant_test.cpp
67
compilerlocalvariable_test.cpp
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <scratchcpp/dev/compilercontext.h>
2+
#include <enginemock.h>
3+
#include <targetmock.h>
4+
5+
using namespace libscratchcpp;
6+
7+
TEST(CompilerContextTest, Constructors)
8+
{
9+
EngineMock engine;
10+
TargetMock target;
11+
CompilerContext ctx(&engine, &target);
12+
ASSERT_EQ(ctx.engine(), &engine);
13+
ASSERT_EQ(ctx.target(), &target);
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.