diff options
author | Li Jin <dragon-fly@qq.com> | 2020-01-28 15:16:10 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-01-28 15:16:10 +0800 |
commit | 240b1ec4a49128c00a787e6d0928865995b1d02e (patch) | |
tree | 9ae9ffb2969c724c94ed3bb37c7cf4385f75ed9d /src | |
parent | 8e2a3b2a6ebec7b77df4a0678cdd26420d951e84 (diff) | |
download | yuescript-240b1ec4a49128c00a787e6d0928865995b1d02e.tar.gz yuescript-240b1ec4a49128c00a787e6d0928865995b1d02e.tar.bz2 yuescript-240b1ec4a49128c00a787e6d0928865995b1d02e.zip |
fix typo.
Diffstat (limited to 'src')
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 58b3bb0..caa7aaf 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -33,12 +33,12 @@ inline std::string s(std::string_view sv) { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | const char* moonScriptVersion() { | 35 | const char* moonScriptVersion() { |
36 | return "0.5.0"; | 36 | return "0.5.0-r0.1.0"; |
37 | } | 37 | } |
38 | 38 | ||
39 | class MoonCompliler { | 39 | class MoonCompiler { |
40 | public: | 40 | public: |
41 | std::pair<std::string,std::string> complile(const std::string& codes, const MoonConfig& config) { | 41 | std::pair<std::string,std::string> compile(const std::string& codes, const MoonConfig& config) { |
42 | _config = config; | 42 | _config = config; |
43 | try { | 43 | try { |
44 | _input = _converter.from_bytes(codes); | 44 | _input = _converter.from_bytes(codes); |
@@ -107,7 +107,7 @@ private: | |||
107 | std::unordered_map<std::string,std::pair<int,int>> _globals; | 107 | std::unordered_map<std::string,std::pair<int,int>> _globals; |
108 | std::ostringstream _buf; | 108 | std::ostringstream _buf; |
109 | std::ostringstream _joinBuf; | 109 | std::ostringstream _joinBuf; |
110 | std::string _newLine = "\n"; | 110 | const std::string _newLine = "\n"; |
111 | enum class LocalMode { | 111 | enum class LocalMode { |
112 | None = 0, | 112 | None = 0, |
113 | Capital = 1, | 113 | Capital = 1, |
@@ -166,7 +166,7 @@ private: | |||
166 | _scopes.pop_back(); | 166 | _scopes.pop_back(); |
167 | } | 167 | } |
168 | 168 | ||
169 | bool isDefined(const std::string& name) { | 169 | bool isDefined(const std::string& name) const { |
170 | bool isDefined = false; | 170 | bool isDefined = false; |
171 | int mode = int(std::isupper(name[0]) ? ExportMode::Capital : ExportMode::Any); | 171 | int mode = int(std::isupper(name[0]) ? ExportMode::Capital : ExportMode::Any); |
172 | const auto& current = _scopes.back(); | 172 | const auto& current = _scopes.back(); |
@@ -200,7 +200,7 @@ private: | |||
200 | return isDefined; | 200 | return isDefined; |
201 | } | 201 | } |
202 | 202 | ||
203 | bool isSolidDefined(const std::string& name) { | 203 | bool isSolidDefined(const std::string& name) const { |
204 | bool isDefined = false; | 204 | bool isDefined = false; |
205 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { | 205 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { |
206 | auto vars = it->vars.get(); | 206 | auto vars = it->vars.get(); |
@@ -253,7 +253,7 @@ private: | |||
253 | return !defined; | 253 | return !defined; |
254 | } | 254 | } |
255 | 255 | ||
256 | std::string getUnusedName(std::string_view name) { | 256 | std::string getUnusedName(std::string_view name) const { |
257 | int index = 0; | 257 | int index = 0; |
258 | std::string newName; | 258 | std::string newName; |
259 | do { | 259 | do { |
@@ -263,7 +263,7 @@ private: | |||
263 | return newName; | 263 | return newName; |
264 | } | 264 | } |
265 | 265 | ||
266 | const std::string nll(ast_node* node) { | 266 | const std::string nll(ast_node* node) const { |
267 | if (_config.reserveLineNumber) { | 267 | if (_config.reserveLineNumber) { |
268 | return s(" -- "sv) + std::to_string(node->m_begin.m_line) + _newLine; | 268 | return s(" -- "sv) + std::to_string(node->m_begin.m_line) + _newLine; |
269 | } else { | 269 | } else { |
@@ -271,7 +271,7 @@ private: | |||
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | const std::string nlr(ast_node* node) { | 274 | const std::string nlr(ast_node* node) const { |
275 | if (_config.reserveLineNumber) { | 275 | if (_config.reserveLineNumber) { |
276 | return s(" -- "sv) + std::to_string(node->m_end.m_line) + _newLine; | 276 | return s(" -- "sv) + std::to_string(node->m_end.m_line) + _newLine; |
277 | } else { | 277 | } else { |
@@ -287,11 +287,11 @@ private: | |||
287 | _indentOffset--; | 287 | _indentOffset--; |
288 | } | 288 | } |
289 | 289 | ||
290 | std::string indent() { | 290 | std::string indent() const { |
291 | return std::string(_scopes.size() - 1 + _indentOffset, '\t'); | 291 | return std::string(_scopes.size() - 1 + _indentOffset, '\t'); |
292 | } | 292 | } |
293 | 293 | ||
294 | std::string indent(int offset) { | 294 | std::string indent(int offset) const { |
295 | return std::string(_scopes.size() - 1 + _indentOffset + offset, '\t'); | 295 | return std::string(_scopes.size() - 1 + _indentOffset + offset, '\t'); |
296 | } | 296 | } |
297 | 297 | ||
@@ -365,7 +365,7 @@ private: | |||
365 | return nullptr; | 365 | return nullptr; |
366 | } | 366 | } |
367 | 367 | ||
368 | SimpleValue_t* simpleSingleValueFrom(ast_node* expList) { | 368 | SimpleValue_t* simpleSingleValueFrom(ast_node* expList) const { |
369 | auto value = singleValueFrom(expList); | 369 | auto value = singleValueFrom(expList); |
370 | if (value && value->item.is<SimpleValue_t>()) { | 370 | if (value && value->item.is<SimpleValue_t>()) { |
371 | return static_cast<SimpleValue_t*>(value->item.get()); | 371 | return static_cast<SimpleValue_t*>(value->item.get()); |
@@ -373,7 +373,7 @@ private: | |||
373 | return nullptr; | 373 | return nullptr; |
374 | } | 374 | } |
375 | 375 | ||
376 | Value_t* firstValueFrom(ast_node* item) { | 376 | Value_t* firstValueFrom(ast_node* item) const { |
377 | Exp_t* exp = nullptr; | 377 | Exp_t* exp = nullptr; |
378 | if (auto expList = ast_cast<ExpList_t>(item)) { | 378 | if (auto expList = ast_cast<ExpList_t>(item)) { |
379 | if (!expList->exprs.empty()) { | 379 | if (!expList->exprs.empty()) { |
@@ -385,7 +385,7 @@ private: | |||
385 | return exp->value.get(); | 385 | return exp->value.get(); |
386 | } | 386 | } |
387 | 387 | ||
388 | Statement_t* lastStatementFrom(Body_t* body) { | 388 | Statement_t* lastStatementFrom(Body_t* body) const { |
389 | if (auto stmt = body->content.as<Statement_t>()) { | 389 | if (auto stmt = body->content.as<Statement_t>()) { |
390 | return stmt; | 390 | return stmt; |
391 | } else { | 391 | } else { |
@@ -394,7 +394,7 @@ private: | |||
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | Statement_t* lastStatementFrom(Block_t* block) { | 397 | Statement_t* lastStatementFrom(Block_t* block) const { |
398 | const auto& stmts = block->statements.objects(); | 398 | const auto& stmts = block->statements.objects(); |
399 | return stmts.empty() ? nullptr : static_cast<Statement_t*>(stmts.back()); | 399 | return stmts.empty() ? nullptr : static_cast<Statement_t*>(stmts.back()); |
400 | } | 400 | } |
@@ -422,7 +422,7 @@ private: | |||
422 | return result; | 422 | return result; |
423 | } | 423 | } |
424 | 424 | ||
425 | bool isChainValueCall(ChainValue_t* chainValue) { | 425 | bool isChainValueCall(ChainValue_t* chainValue) const { |
426 | return ast_is<InvokeArgs_t, Invoke_t>(chainValue->items.back()); | 426 | return ast_is<InvokeArgs_t, Invoke_t>(chainValue->items.back()); |
427 | } | 427 | } |
428 | 428 | ||
@@ -434,7 +434,7 @@ private: | |||
434 | HasKeyword | 434 | HasKeyword |
435 | }; | 435 | }; |
436 | 436 | ||
437 | ChainType specialChainValue(ChainValue_t* chainValue) { | 437 | ChainType specialChainValue(ChainValue_t* chainValue) const { |
438 | if (ast_is<ColonChainItem_t>(chainValue->items.back())) { | 438 | if (ast_is<ColonChainItem_t>(chainValue->items.back())) { |
439 | return ChainType::EndWithColon; | 439 | return ChainType::EndWithColon; |
440 | } | 440 | } |
@@ -4375,11 +4375,11 @@ private: | |||
4375 | } | 4375 | } |
4376 | }; | 4376 | }; |
4377 | 4377 | ||
4378 | const std::string MoonCompliler::Empty; | 4378 | const std::string MoonCompiler::Empty; |
4379 | 4379 | ||
4380 | std::tuple<std::string,std::string,GlobalVars> moonCompile(const std::string& codes, const MoonConfig& config) { | 4380 | std::tuple<std::string,std::string,GlobalVars> moonCompile(const std::string& codes, const MoonConfig& config) { |
4381 | auto compiler = MoonCompliler{}; | 4381 | auto compiler = MoonCompiler{}; |
4382 | auto result = compiler.complile(codes, config); | 4382 | auto result = compiler.compile(codes, config); |
4383 | auto globals = std::make_unique<std::list<GlobalVar>>(); | 4383 | auto globals = std::make_unique<std::list<GlobalVar>>(); |
4384 | for (const auto& var : compiler.getGlobals()) { | 4384 | for (const auto& var : compiler.getGlobals()) { |
4385 | int line,col; | 4385 | int line,col; |