Skip to content

Commit 02df0da

Browse files
committed
CppCodeBuilder: Return stubs instead of null pointers
1 parent 1c5c5eb commit 02df0da

2 files changed

Lines changed: 55 additions & 47 deletions

File tree

‎src/engine/internal/codegen/cpp/cppcodebuilder.cpp‎

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
#include <scratchcpp/compilerlocalvariable.h>
4+
35
#include "cppcodebuilder.h"
6+
#include "cppexecutablecode.h"
47
#include "cppconstant.h"
58
#include "../typeutils.h"
69

@@ -15,22 +18,22 @@ CppCodeBuilder::CppCodeBuilder(CppCompilerContext *ctx, BlockPrototype *procedur
1518

1619
std::shared_ptr<ExecutableCode> CppCodeBuilder::build()
1720
{
18-
return nullptr;
21+
return std::make_shared<CppExecutableCode>(m_ctx);
1922
}
2023

2124
CompilerValue *CppCodeBuilder::addFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
2225
{
23-
return nullptr;
26+
return addConstValue(Value());
2427
}
2528

2629
CompilerValue *CppCodeBuilder::addTargetFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
2730
{
28-
return nullptr;
31+
return addConstValue(Value());
2932
}
3033

3134
CompilerValue *CppCodeBuilder::addFunctionCallWithCtx(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
3235
{
33-
return nullptr;
36+
return addConstValue(Value());
3437
}
3538

3639
CompilerConstant *CppCodeBuilder::addConstValue(const Value &value)
@@ -42,217 +45,221 @@ CompilerConstant *CppCodeBuilder::addConstValue(const Value &value)
4245

4346
CompilerValue *CppCodeBuilder::addStringChar(CompilerValue *string, CompilerValue *index)
4447
{
45-
return nullptr;
48+
return addConstValue(Value());
4649
}
4750

4851
CompilerValue *CppCodeBuilder::addStringLength(CompilerValue *string)
4952
{
50-
return nullptr;
53+
return addConstValue(Value());
5154
}
5255

5356
CompilerValue *CppCodeBuilder::addLoopIndex()
5457
{
55-
return nullptr;
58+
return addConstValue(Value());
5659
}
5760

5861
CompilerValue *CppCodeBuilder::addLocalVariableValue(CompilerLocalVariable *variable)
5962
{
60-
return nullptr;
63+
return addConstValue(Value());
6164
}
6265

6366
CompilerValue *CppCodeBuilder::addVariableValue(Variable *variable)
6467
{
65-
return nullptr;
68+
return addConstValue(Value());
6669
}
6770

6871
CompilerValue *CppCodeBuilder::addListContents(List *list)
6972
{
70-
return nullptr;
73+
return addConstValue(Value());
7174
}
7275

7376
CompilerValue *CppCodeBuilder::addListItem(List *list, CompilerValue *index)
7477
{
75-
return nullptr;
78+
return addConstValue(Value());
7679
}
7780

7881
CompilerValue *CppCodeBuilder::addListItemIndex(List *list, CompilerValue *item)
7982
{
80-
return nullptr;
83+
return addConstValue(Value());
8184
}
8285

8386
CompilerValue *CppCodeBuilder::addListContains(List *list, CompilerValue *item)
8487
{
85-
return nullptr;
88+
return addConstValue(Value());
8689
}
8790

8891
CompilerValue *CppCodeBuilder::addListSize(List *list)
8992
{
90-
return nullptr;
93+
return addConstValue(Value());
9194
}
9295

9396
CompilerValue *CppCodeBuilder::addProcedureArgument(const std::string &name)
9497
{
95-
return nullptr;
98+
return addConstValue(Value());
9699
}
97100

98101
CompilerValue *CppCodeBuilder::createAdd(CompilerValue *operand1, CompilerValue *operand2)
99102
{
100-
return nullptr;
103+
return addConstValue(Value());
101104
}
102105

103106
CompilerValue *CppCodeBuilder::createSub(CompilerValue *operand1, CompilerValue *operand2)
104107
{
105-
return nullptr;
108+
return addConstValue(Value());
106109
}
107110

108111
CompilerValue *CppCodeBuilder::createMul(CompilerValue *operand1, CompilerValue *operand2)
109112
{
110-
return nullptr;
113+
return addConstValue(Value());
111114
}
112115

113116
CompilerValue *CppCodeBuilder::createDiv(CompilerValue *operand1, CompilerValue *operand2)
114117
{
115-
return nullptr;
118+
return addConstValue(Value());
116119
}
117120

118121
CompilerValue *CppCodeBuilder::createRandom(CompilerValue *from, CompilerValue *to)
119122
{
120-
return nullptr;
123+
return addConstValue(Value());
121124
}
122125

123126
CompilerValue *CppCodeBuilder::createRandomInt(CompilerValue *from, CompilerValue *to)
124127
{
125-
return nullptr;
128+
return addConstValue(Value());
126129
}
127130

128131
CompilerValue *CppCodeBuilder::createCmpEQ(CompilerValue *operand1, CompilerValue *operand2)
129132
{
130-
return nullptr;
133+
return addConstValue(Value());
131134
}
132135

133136
CompilerValue *CppCodeBuilder::createCmpGT(CompilerValue *operand1, CompilerValue *operand2)
134137
{
135-
return nullptr;
138+
return addConstValue(Value());
136139
}
137140

138141
CompilerValue *CppCodeBuilder::createCmpLT(CompilerValue *operand1, CompilerValue *operand2)
139142
{
140-
return nullptr;
143+
return addConstValue(Value());
141144
}
142145

143146
CompilerValue *CppCodeBuilder::createStrCmpEQ(CompilerValue *string1, CompilerValue *string2, bool caseSensitive)
144147
{
145-
return nullptr;
148+
return addConstValue(Value());
146149
}
147150

148151
CompilerValue *CppCodeBuilder::createAnd(CompilerValue *operand1, CompilerValue *operand2)
149152
{
150-
return nullptr;
153+
return addConstValue(Value());
151154
}
152155

153156
CompilerValue *CppCodeBuilder::createOr(CompilerValue *operand1, CompilerValue *operand2)
154157
{
155-
return nullptr;
158+
return addConstValue(Value());
156159
}
157160

158161
CompilerValue *CppCodeBuilder::createNot(CompilerValue *operand)
159162
{
160-
return nullptr;
163+
return addConstValue(Value());
161164
}
162165

163166
CompilerValue *CppCodeBuilder::createMod(CompilerValue *num1, CompilerValue *num2)
164167
{
165-
return nullptr;
168+
return addConstValue(Value());
166169
}
167170

168171
CompilerValue *CppCodeBuilder::createRound(CompilerValue *num)
169172
{
170-
return nullptr;
173+
return addConstValue(Value());
171174
}
172175

173176
CompilerValue *CppCodeBuilder::createAbs(CompilerValue *num)
174177
{
175-
return nullptr;
178+
return addConstValue(Value());
176179
}
177180

178181
CompilerValue *CppCodeBuilder::createFloor(CompilerValue *num)
179182
{
180-
return nullptr;
183+
return addConstValue(Value());
181184
}
182185

183186
CompilerValue *CppCodeBuilder::createCeil(CompilerValue *num)
184187
{
185-
return nullptr;
188+
return addConstValue(Value());
186189
}
187190

188191
CompilerValue *CppCodeBuilder::createSqrt(CompilerValue *num)
189192
{
190-
return nullptr;
193+
return addConstValue(Value());
191194
}
192195

193196
CompilerValue *CppCodeBuilder::createSin(CompilerValue *num)
194197
{
195-
return nullptr;
198+
return addConstValue(Value());
196199
}
197200

198201
CompilerValue *CppCodeBuilder::createCos(CompilerValue *num)
199202
{
200-
return nullptr;
203+
return addConstValue(Value());
201204
}
202205

203206
CompilerValue *CppCodeBuilder::createTan(CompilerValue *num)
204207
{
205-
return nullptr;
208+
return addConstValue(Value());
206209
}
207210

208211
CompilerValue *CppCodeBuilder::createAsin(CompilerValue *num)
209212
{
210-
return nullptr;
213+
return addConstValue(Value());
211214
}
212215

213216
CompilerValue *CppCodeBuilder::createAcos(CompilerValue *num)
214217
{
215-
return nullptr;
218+
return addConstValue(Value());
216219
}
217220

218221
CompilerValue *CppCodeBuilder::createAtan(CompilerValue *num)
219222
{
220-
return nullptr;
223+
return addConstValue(Value());
221224
}
222225

223226
CompilerValue *CppCodeBuilder::createLn(CompilerValue *num)
224227
{
225-
return nullptr;
228+
return addConstValue(Value());
226229
}
227230

228231
CompilerValue *CppCodeBuilder::createLog10(CompilerValue *num)
229232
{
230-
return nullptr;
233+
return addConstValue(Value());
231234
}
232235

233236
CompilerValue *CppCodeBuilder::createExp(CompilerValue *num)
234237
{
235-
return nullptr;
238+
return addConstValue(Value());
236239
}
237240

238241
CompilerValue *CppCodeBuilder::createExp10(CompilerValue *num)
239242
{
240-
return nullptr;
243+
return addConstValue(Value());
241244
}
242245

243246
CompilerValue *CppCodeBuilder::createStringConcat(CompilerValue *string1, CompilerValue *string2)
244247
{
245-
return nullptr;
248+
return addConstValue(Value());
246249
}
247250

248251
CompilerValue *CppCodeBuilder::createSelect(CompilerValue *cond, CompilerValue *trueValue, CompilerValue *falseValue, Compiler::StaticType valueType)
249252
{
250-
return nullptr;
253+
return addConstValue(Value());
251254
}
252255

253256
CompilerLocalVariable *CppCodeBuilder::createLocalVariable(Compiler::StaticType type)
254257
{
255-
return nullptr;
258+
// TODO: Complete this
259+
CompilerValue *ptr = addConstValue(Value());
260+
auto var = std::make_shared<CompilerLocalVariable>(ptr);
261+
m_localVars.push_back(var);
262+
return var.get();
256263
}
257264

258265
void CppCodeBuilder::createLocalVariableWrite(CompilerLocalVariable *variable, CompilerValue *value)

‎src/engine/internal/codegen/cpp/cppcodebuilder.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class CppCodeBuilder : public ICodeBuilder
113113
Compiler::CodeType m_codeType = Compiler::CodeType::Script;
114114

115115
std::vector<std::shared_ptr<CppValue>> m_values;
116+
std::vector<std::shared_ptr<CompilerLocalVariable>> m_localVars;
116117
};
117118

118119
} // namespace libscratchcpp

0 commit comments

Comments
 (0)