File tree Expand file tree Collapse file tree 8 files changed +128
-0
lines changed
Expand file tree Collapse file tree 8 files changed +128
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ if (LIBSCRATCHCPP_USE_LLVM)
7272 target_sources (scratchcpp
7373 PUBLIC
7474 include /scratchcpp/dev/compiler.h
75+ include /scratchcpp/dev/compilervalue.h
7576 include /scratchcpp/dev/executablecode.h
7677 include /scratchcpp/dev/executioncontext.h
7778 )
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include " compiler.h"
6+
7+ namespace libscratchcpp
8+ {
9+
10+ class CompilerValuePrivate ;
11+
12+ /* ! \brief The CompilerValue class represents a local value in compiled code. */
13+ class LIBSCRATCHCPP_EXPORT CompilerValue
14+ {
15+ public:
16+ CompilerValue (Compiler::StaticType type);
17+ CompilerValue (const CompilerValue &) = delete ;
18+ virtual ~CompilerValue () { }
19+
20+ Compiler::StaticType type () const ;
21+ void setType (Compiler::StaticType type);
22+
23+ virtual bool isConst () const { return false ; };
24+
25+ private:
26+ spimpl::unique_impl_ptr<CompilerValuePrivate> impl;
27+ };
28+
29+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ target_sources(scratchcpp
33 compiler.cpp
44 compiler_p.cpp
55 compiler_p.h
6+ compilervalue.cpp
7+ compilervalue_p.cpp
8+ compilervalue_p.h
69 executioncontext.cpp
710 executioncontext_p.cpp
811 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/compilervalue.h>
4+
5+ #include " compilervalue_p.h"
6+
7+ using namespace libscratchcpp ;
8+
9+ /* ! Constructs CompilerValue. */
10+ CompilerValue::CompilerValue (Compiler::StaticType type) :
11+ impl(spimpl::make_unique_impl<CompilerValuePrivate>(type))
12+ {
13+ }
14+
15+ /* ! Returns the type of this value. */
16+ Compiler::StaticType CompilerValue::type () const
17+ {
18+ return impl->type ;
19+ }
20+
21+ /* ! Sets the type of this value. */
22+ void CompilerValue::setType (Compiler::StaticType type)
23+ {
24+ impl->type = type;
25+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " compilervalue_p.h"
4+
5+ using namespace libscratchcpp ;
6+
7+ CompilerValuePrivate::CompilerValuePrivate (Compiler::StaticType type) :
8+ type(type)
9+ {
10+ }
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/dev/compiler.h>
6+
7+ namespace libscratchcpp
8+ {
9+
10+ struct CompilerValuePrivate
11+ {
12+ CompilerValuePrivate (Compiler::StaticType type);
13+
14+ Compiler::StaticType type = Compiler::StaticType::Unknown;
15+ };
16+
17+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change 11add_executable (
22 compiler_test
33 compiler_test.cpp
4+ compilervalue_test.cpp
45)
56
67target_link_libraries (
Original file line number Diff line number Diff line change 1+ #include < scratchcpp/dev/compilervalue.h>
2+ #include < gtest/gtest.h>
3+
4+ using namespace libscratchcpp ;
5+
6+ TEST (CompilerValueTest, Constructors)
7+ {
8+ {
9+ CompilerValue v (Compiler::StaticType::Number);
10+ ASSERT_EQ (v.type (), Compiler::StaticType::Number);
11+ }
12+
13+ {
14+ CompilerValue v (Compiler::StaticType::String);
15+ ASSERT_EQ (v.type (), Compiler::StaticType::String);
16+ }
17+
18+ {
19+ CompilerValue v (Compiler::StaticType::Unknown);
20+ ASSERT_EQ (v.type (), Compiler::StaticType::Unknown);
21+ }
22+ }
23+
24+ TEST (CompilerValueTest, Type)
25+ {
26+ CompilerValue v (Compiler::StaticType::Unknown);
27+
28+ v.setType (Compiler::StaticType::String);
29+ ASSERT_EQ (v.type (), Compiler::StaticType::String);
30+
31+ v.setType (Compiler::StaticType::Bool);
32+ ASSERT_EQ (v.type (), Compiler::StaticType::Bool);
33+
34+ v.setType (Compiler::StaticType::Unknown);
35+ ASSERT_EQ (v.type (), Compiler::StaticType::Unknown);
36+ }
37+
38+ TEST (CompilerValueTest, IsConst)
39+ {
40+ CompilerValue v (Compiler::StaticType::Unknown);
41+ ASSERT_FALSE (v.isConst ());
42+ }
You can’t perform that action at this time.
0 commit comments