File tree Expand file tree Collapse file tree 8 files changed +109
-0
lines changed Expand file tree Collapse file tree 8 files changed +109
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ if (LIBSCRATCHCPP_USE_LLVM)
73
73
PUBLIC
74
74
include /scratchcpp/dev/compiler.h
75
75
include /scratchcpp/dev/compilervalue.h
76
+ include /scratchcpp/dev/compilerconstant.h
76
77
include /scratchcpp/dev/executablecode.h
77
78
include /scratchcpp/dev/executioncontext.h
78
79
)
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include " compilervalue.h"
6
+
7
+ namespace libscratchcpp
8
+ {
9
+
10
+ class CompilerConstantPrivate ;
11
+
12
+ /* ! \brief The CompilerConstant class represents a constant value in compiled code. */
13
+ class LIBSCRATCHCPP_EXPORT CompilerConstant : public CompilerValue
14
+ {
15
+ public:
16
+ CompilerConstant (Compiler::StaticType type, const Value &value);
17
+ CompilerConstant (const CompilerConstant &) = delete ;
18
+
19
+ bool isConst () const override final { return true ; };
20
+
21
+ const Value &value () const ;
22
+
23
+ private:
24
+ spimpl::unique_impl_ptr<CompilerConstantPrivate> impl;
25
+ };
26
+
27
+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ target_sources(scratchcpp
6
6
compilervalue.cpp
7
7
compilervalue_p.cpp
8
8
compilervalue_p.h
9
+ compilerconstant.cpp
10
+ compilerconstant_p.cpp
11
+ compilerconstant_p.h
9
12
executioncontext.cpp
10
13
executioncontext_p.cpp
11
14
executioncontext_p.h
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #include < scratchcpp/dev/compilerconstant.h>
4
+
5
+ #include " compilerconstant_p.h"
6
+
7
+ using namespace libscratchcpp ;
8
+
9
+ /* ! Constructs CompilerConstant. */
10
+ CompilerConstant::CompilerConstant (Compiler::StaticType type, const Value &value) :
11
+ CompilerValue(type),
12
+ impl(spimpl::make_unique_impl<CompilerConstantPrivate>(value))
13
+ {
14
+ }
15
+
16
+ /* ! Returns the constant value. */
17
+ const Value &CompilerConstant::value () const
18
+ {
19
+ return impl->value ;
20
+ }
Original file line number Diff line number Diff line change
1
+ #include " compilerconstant_p.h"
2
+
3
+ using namespace libscratchcpp ;
4
+
5
+ CompilerConstantPrivate::CompilerConstantPrivate (const Value &value) :
6
+ value(value)
7
+ {
8
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include < scratchcpp/value.h>
6
+
7
+ namespace libscratchcpp
8
+ {
9
+
10
+ struct CompilerConstantPrivate
11
+ {
12
+ CompilerConstantPrivate (const Value &value);
13
+
14
+ Value value;
15
+ };
16
+
17
+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ add_executable(
2
2
compiler_test
3
3
compiler_test.cpp
4
4
compilervalue_test.cpp
5
+ compilerconstant_test.cpp
5
6
)
6
7
7
8
target_link_libraries (
Original file line number Diff line number Diff line change
1
+ #include < scratchcpp/dev/compilerconstant.h>
2
+ #include < scratchcpp/value.h>
3
+ #include < gtest/gtest.h>
4
+
5
+ using namespace libscratchcpp ;
6
+
7
+ TEST (CompilerConstantTest, Constructors)
8
+ {
9
+ {
10
+ CompilerConstant v (Compiler::StaticType::Number, 5 );
11
+ ASSERT_EQ (v.type (), Compiler::StaticType::Number);
12
+ ASSERT_EQ (v.value (), 5 );
13
+ }
14
+
15
+ {
16
+ CompilerConstant v (Compiler::StaticType::String, " test" );
17
+ ASSERT_EQ (v.type (), Compiler::StaticType::String);
18
+ ASSERT_EQ (v.value (), " test" );
19
+ }
20
+
21
+ {
22
+ CompilerConstant v (Compiler::StaticType::Unknown, true );
23
+ ASSERT_EQ (v.type (), Compiler::StaticType::Unknown);
24
+ ASSERT_EQ (v.value (), true );
25
+ }
26
+ }
27
+
28
+ TEST (CompilerConstantTest, IsConst)
29
+ {
30
+ CompilerConstant v (Compiler::StaticType::Unknown, Value ());
31
+ ASSERT_TRUE (v.isConst ());
32
+ }
You can’t perform that action at this time.
0 commit comments