Sun, 20 Jul 2014 17:25:36 +0300
- massive refactoring
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
133
dbbdb870c835
- changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
2 | Copyright 2012-2014 Teemu Piippo |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | derived from this software without specific prior written permission. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "parser.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "events.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "commands.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "stringTable.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "list.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | #include "lexer.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | #include "dataBuffer.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | #include "expression.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | #define SCOPE(n) (m_scopeStack[m_scopeCursor - n]) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | static const StringList g_validZandronumVersions = {"1.2", "1.3", "2.0"}; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | BotscriptParser::BotscriptParser() : |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | m_isReadOnly (false), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | m_mainBuffer (new DataBuffer), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | m_onenterBuffer (new DataBuffer), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | m_mainLoopBuffer (new DataBuffer), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | m_lexer (new Lexer), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | m_numStates (0), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | m_numEvents (0), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | m_currentMode (PARSERMODE_TopLevel), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | m_isStateSpawnDefined (false), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | m_gotMainLoop (false), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | m_scopeCursor (-1), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | m_isElseAllowed (false), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | m_highestGlobalVarIndex (0), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | m_highestStateVarIndex (0), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | m_zandronumVersion (10200), // 1.2 |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | m_defaultZandronumVersion (true) {} |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | BotscriptParser::~BotscriptParser() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | delete m_lexer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | void BotscriptParser::checkToplevel() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | if (m_currentMode != PARSERMODE_TopLevel) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | error ("%1-statements may only be defined at top level!", getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | void BotscriptParser::checkNotToplevel() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | if (m_currentMode == PARSERMODE_TopLevel) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | error ("%1-statements must not be defined at top level!", getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | // Main compiler code. Begins read of the script file, checks the syntax of it |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | // and writes the data to the object file via Objwriter - which also takes care |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | // of necessary buffering so stuff is written in the correct order. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | void BotscriptParser::parseBotscript (String fileName) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | // Lex and preprocess the file |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | m_lexer->processFile (fileName); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | pushScope(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | while (m_lexer->next()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | // Check if else is potentically valid |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
100 | if (tokenIs (Token::Else) and m_isElseAllowed == false) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | error ("else without preceding if"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
103 | if (tokenIs (Token::Else) == false) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | m_isElseAllowed = false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | switch (m_lexer->token()->type) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
108 | case Token::State: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | parseStateBlock(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
112 | case Token::Event: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | parseEventBlock(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
116 | case Token::Mainloop: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | parseMainloop(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
120 | case Token::Onenter: |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
121 | case Token::Onexit: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | parseOnEnterExit(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
125 | case Token::Var: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | parseVar(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
129 | case Token::If: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | parseIf(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
133 | case Token::Else: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | parseElse(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
137 | case Token::While: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | parseWhileBlock(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
141 | case Token::For: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | parseForBlock(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
145 | case Token::Do: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | parseDoBlock(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
149 | case Token::Switch: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | parseSwitchBlock(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
153 | case Token::Case: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | parseSwitchCase(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
157 | case Token::Default: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | parseSwitchDefault(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
161 | case Token::Break: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | parseBreak(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
165 | case Token::Continue: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | parseContinue(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
169 | case Token::BraceEnd: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | parseBlockEnd(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
173 | case Token::Eventdef: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | parseEventdef(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
177 | case Token::Funcdef: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | parseFuncdef(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
181 | case Token::Semicolon: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
184 | case Token::Using: |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | parseUsing(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | default: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | // Check if it's a command |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | CommandInfo* comm = findCommandByName (getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | if (comm) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | currentBuffer()->mergeAndDestroy (parseCommand (comm)); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
196 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | continue; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | // If nothing else, parse it as a statement |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | m_lexer->skip (-1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | DataBuffer* b = parseStatement(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | if (b == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | m_lexer->next(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | error ("unknown token `%1`", getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | currentBuffer()->mergeAndDestroy (b); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
211 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | // Script file ended. Do some last checks and write the last things to main buffer |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | if (m_currentMode != PARSERMODE_TopLevel) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | error ("script did not end at top level; a `}` is missing somewhere"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | if (isReadOnly() == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | // stateSpawn must be defined! |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | if (m_isStateSpawnDefined == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | error ("script must have a state named `stateSpawn`!"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | if (m_defaultZandronumVersion) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | print ("\n"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | print ("note: use the 'using' directive to define a target Zandronum version\n"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | print ("usage: using zandronum <version>, possible versions: %1\n", g_validZandronumVersions); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | print ("\n"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | // Dump the last state's onenter and mainloop |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | writeMemberBuffers(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | // String table |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | writeStringTable(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | void BotscriptParser::parseStateBlock() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | checkToplevel(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
248 | m_lexer->mustGetNext (Token::String); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | String statename = getTokenString(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | // State name must be a word. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | if (statename.firstIndexOf (" ") != -1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | error ("state name must be a single word, got `%1`", statename); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | // stateSpawn is special - it *must* be defined. If we |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | // encountered it, then mark down that we have it. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | if (statename.toLowercase() == "statespawn") |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | m_isStateSpawnDefined = true; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | // Must end in a colon |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
261 | m_lexer->mustGetNext (Token::Colon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | // write the previous state's onenter and |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | // mainloop buffers to file now |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | if (m_currentState.isEmpty() == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | writeMemberBuffers(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
268 | currentBuffer()->writeDWord (DataHeader::StateName); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | currentBuffer()->writeString (statename); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
270 | currentBuffer()->writeDWord (DataHeader::StateIndex); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | currentBuffer()->writeDWord (m_numStates); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | m_numStates++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | m_currentState = statename; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | m_gotMainLoop = false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | void BotscriptParser::parseEventBlock() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | checkToplevel(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
283 | m_lexer->mustGetNext (Token::String); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | EventDefinition* e = findEventByName (getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | if (e == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | error ("bad event, got `%1`\n", getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
290 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | m_currentMode = PARSERMODE_Event; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
292 | currentBuffer()->writeDWord (DataHeader::Event); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | currentBuffer()->writeDWord (e->number); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | m_numEvents++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | void BotscriptParser::parseMainloop() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | checkToplevel(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
302 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | m_currentMode = PARSERMODE_MainLoop; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
305 | m_mainLoopBuffer->writeDWord (DataHeader::MainLoop); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | void BotscriptParser::parseOnEnterExit() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | checkToplevel(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
313 | bool onenter = (tokenIs (Token::Onenter)); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
314 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | m_currentMode = onenter ? PARSERMODE_Onenter : PARSERMODE_Onexit; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
317 | currentBuffer()->writeDWord (onenter ? DataHeader::OnEnter : DataHeader::OnExit); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | void BotscriptParser::parseVar() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | Variable* var = new Variable; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | var->origin = m_lexer->describeCurrentPosition(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | var->isarray = false; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
327 | bool isconst = m_lexer->next (Token::Const); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
328 | m_lexer->mustGetAnyOf ({Token::Int,Token::Str,Token::Void}); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
329 | |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
330 | DataType vartype = (tokenIs (Token::Int)) ? TYPE_Int |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
331 | : (tokenIs (Token::Str)) ? TYPE_String |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
332 | : TYPE_Bool; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
334 | if (m_lexer->next (Token::Const)) |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
335 | { |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
336 | if (isconst) |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
337 | error ("duplicate const in variable declaration"); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
339 | isconst = true; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
340 | } |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
341 | |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
342 | m_lexer->mustGetNext (Token::DollarSign); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
343 | m_lexer->mustGetNext (Token::Symbol); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | String name = getTokenString(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
346 | if (m_lexer->next (Token::BracketStart)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
348 | m_lexer->mustGetNext (Token::BracketEnd); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | var->isarray = true; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | if (isconst) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
352 | error ("arrays cannot be const"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | for (Variable* var : SCOPE(0).globalVariables + SCOPE(0).localVariables) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
357 | if (var->name == name) |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
358 | { |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | error ("Variable $%1 is already declared on this scope; declared at %2", |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
360 | var->name, var->origin); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
361 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
363 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
364 | var->name = name; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
365 | var->statename = ""; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
366 | var->type = vartype; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
367 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
368 | if (isconst == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | var->writelevel = WRITE_Mutable; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
373 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
374 | m_lexer->mustGetNext (Token::Assign); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | Expression expr (this, m_lexer, vartype); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | // If the expression was constexpr, we know its value and thus |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
378 | // can store it in the variable. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | if (expr.getResult()->isConstexpr()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
380 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | var->writelevel = WRITE_Constexpr; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
382 | var->value = expr.getResult()->value(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
383 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | // TODO: might need a VM-wise oninit for this... |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
387 | error ("const variables must be constexpr (deductible at compile-time)"); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
388 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
389 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
390 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
391 | // Assign an index for the variable if it is not constexpr. Constexpr |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | // variables can simply be substituted out for their value when used |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | // so they need no index. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | if (var->writelevel != WRITE_Constexpr) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
396 | bool isglobal = isInGlobalState(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
397 | var->index = isglobal ? SCOPE(0).globalVarIndexBase++ : SCOPE(0).localVarIndexBase++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
398 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
399 | if ((isglobal == true and var->index >= Limits::MaxGlobalVars) or |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
400 | (isglobal == false and var->index >= Limits::MaxStateVars)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
401 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | error ("too many %1 variables", isglobal ? "global" : "state-local"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
403 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
404 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
405 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
406 | if (isInGlobalState()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | SCOPE(0).globalVariables << var; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
408 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
409 | SCOPE(0).localVariables << var; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
410 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
411 | suggestHighestVarIndex (isInGlobalState(), var->index); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
412 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
413 | print ("Declared %3 variable #%1 $%2\n", var->index, var->name, isInGlobalState() ? "global" : "state-local"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
414 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
415 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
416 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
417 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
418 | void BotscriptParser::parseIf() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
419 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
420 | checkNotToplevel(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
421 | pushScope(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
422 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | // Condition |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
424 | m_lexer->mustGetNext (Token::ParenStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
425 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
426 | // Read the expression and write it. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | DataBuffer* c = parseExpression (TYPE_Int); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
428 | currentBuffer()->mergeAndDestroy (c); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
430 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
431 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
432 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
433 | // Add a mark - to here temporarily - and add a reference to it. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | // Upon a closing brace, the mark will be adjusted. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
435 | ByteMark* mark = currentBuffer()->addMark (""); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
436 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
437 | // Use DataHeader::IfNotGoto - if the expression is not true, we goto the mark |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
438 | // we just defined - and this mark will be at the end of the scope block. |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
439 | currentBuffer()->writeDWord (DataHeader::IfNotGoto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | currentBuffer()->addReference (mark); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
441 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
442 | // Store it |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
443 | SCOPE (0).mark1 = mark; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
444 | SCOPE (0).type = SCOPE_If; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
445 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
446 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
447 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
448 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
449 | void BotscriptParser::parseElse() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
450 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
451 | checkNotToplevel(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
452 | m_lexer->mustGetNext (Token::BraceStart); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
453 | pushScope (true); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
454 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
455 | if (SCOPE (0).type != SCOPE_If) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
456 | error ("else without preceding if"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
457 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
458 | // write down to jump to the end of the else statement |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
459 | // Otherwise we have fall-throughs |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
460 | SCOPE (0).mark2 = currentBuffer()->addMark (""); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
461 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
462 | // Instruction to jump to the end after if block is complete |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
463 | currentBuffer()->writeDWord (DataHeader::Goto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | currentBuffer()->addReference (SCOPE (0).mark2); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
465 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | // Move the ifnot mark here and set type to else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | currentBuffer()->adjustMark (SCOPE (0).mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
468 | SCOPE (0).type = SCOPE_Else; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
469 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
470 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
472 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | void BotscriptParser::parseWhileBlock() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | checkNotToplevel(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | pushScope(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
477 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
478 | // While loops need two marks - one at the start of the loop and one at the |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
479 | // end. The condition is checked at the very start of the loop, if it fails, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
480 | // we use goto to skip to the end of the loop. At the end, we loop back to |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
481 | // the beginning with a go-to statement. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
482 | ByteMark* mark1 = currentBuffer()->addMark (""); // start |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | ByteMark* mark2 = currentBuffer()->addMark (""); // end |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
484 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
485 | // Condition |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
486 | m_lexer->mustGetNext (Token::ParenStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | DataBuffer* expr = parseExpression (TYPE_Int); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
488 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
489 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
490 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
491 | // write condition |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
492 | currentBuffer()->mergeAndDestroy (expr); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
493 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
494 | // Instruction to go to the end if it fails |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
495 | currentBuffer()->writeDWord (DataHeader::IfNotGoto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
496 | currentBuffer()->addReference (mark2); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
498 | // Store the needed stuff |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
499 | SCOPE (0).mark1 = mark1; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
500 | SCOPE (0).mark2 = mark2; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
501 | SCOPE (0).type = SCOPE_While; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
502 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
503 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
504 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
505 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
506 | void BotscriptParser::parseForBlock() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
507 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
508 | checkNotToplevel(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
509 | pushScope(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
510 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
511 | // Initializer |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
512 | m_lexer->mustGetNext (Token::ParenStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
513 | DataBuffer* init = parseStatement(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
514 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
515 | if (init == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
516 | error ("bad statement for initializer of for"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
517 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
518 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
519 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
520 | // Condition |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
521 | DataBuffer* cond = parseExpression (TYPE_Int); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
522 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
523 | if (cond == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
524 | error ("bad statement for condition of for"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
525 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
526 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
527 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
528 | // Incrementor |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
529 | DataBuffer* incr = parseStatement(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
530 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
531 | if (incr == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
532 | error ("bad statement for incrementor of for"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
533 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
534 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
535 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
536 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
537 | // First, write out the initializer |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
538 | currentBuffer()->mergeAndDestroy (init); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
539 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
540 | // Init two marks |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
541 | ByteMark* mark1 = currentBuffer()->addMark (""); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
542 | ByteMark* mark2 = currentBuffer()->addMark (""); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
543 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
544 | // Add the condition |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
545 | currentBuffer()->mergeAndDestroy (cond); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
546 | currentBuffer()->writeDWord (DataHeader::IfNotGoto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
547 | currentBuffer()->addReference (mark2); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
548 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
549 | // Store the marks and incrementor |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
550 | SCOPE (0).mark1 = mark1; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
551 | SCOPE (0).mark2 = mark2; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
552 | SCOPE (0).buffer1 = incr; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
553 | SCOPE (0).type = SCOPE_For; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
554 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
555 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
556 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
557 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
558 | void BotscriptParser::parseDoBlock() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
559 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
560 | checkNotToplevel(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
561 | pushScope(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
562 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
563 | SCOPE (0).mark1 = currentBuffer()->addMark (""); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
564 | SCOPE (0).type = SCOPE_Do; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
565 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
566 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
567 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
568 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
569 | void BotscriptParser::parseSwitchBlock() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
570 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
571 | // This gets a bit tricky. switch is structured in the |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
572 | // bytecode followingly: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
573 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
574 | // (expression) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
575 | // case a: goto casemark1 |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
576 | // case b: goto casemark2 |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
577 | // case c: goto casemark3 |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
578 | // goto mark1 // jump to end if no matches |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
579 | // casemark1: ... |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
580 | // casemark2: ... |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
581 | // casemark3: ... |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
582 | // mark1: // end mark |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
583 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
584 | checkNotToplevel(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
585 | pushScope(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
586 | m_lexer->mustGetNext (Token::ParenStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
587 | currentBuffer()->mergeAndDestroy (parseExpression (TYPE_Int)); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
588 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
589 | m_lexer->mustGetNext (Token::BraceStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
590 | SCOPE (0).type = SCOPE_Switch; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
591 | SCOPE (0).mark1 = currentBuffer()->addMark (""); // end mark |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
592 | SCOPE (0).buffer1 = null; // default header |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
593 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
594 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
595 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
596 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
597 | void BotscriptParser::parseSwitchCase() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
598 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
599 | // case is only allowed inside switch |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
600 | if (SCOPE (0).type != SCOPE_Switch) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
601 | error ("case label outside switch"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
602 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
603 | // Get a literal value for the case block. Zandronum does not support |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
604 | // expressions here. |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
605 | m_lexer->mustGetNext (Token::Number); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
606 | int num = m_lexer->token()->text.toLong(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
607 | m_lexer->mustGetNext (Token::Colon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
608 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
609 | for (const CaseInfo& info : SCOPE(0).cases) |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
610 | { |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
611 | if (info.number == num) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
612 | error ("multiple case %1 labels in one switch", num); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
613 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
614 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
615 | // Write down the expression and case-go-to. This builds |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
616 | // the case tree. The closing event will write the actual |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
617 | // blocks and move the marks appropriately. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
618 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
619 | // AddSwitchCase will add the reference to the mark |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
620 | // for the case block that this heralds, and takes care |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
621 | // of buffering setup and stuff like that. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
622 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
623 | // We null the switch buffer for the case-go-to statement as |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
624 | // we want it all under the switch, not into the case-buffers. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
625 | m_switchBuffer = null; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
626 | currentBuffer()->writeDWord (DataHeader::CaseGoto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
627 | currentBuffer()->writeDWord (num); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
628 | addSwitchCase (null); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
629 | SCOPE (0).casecursor->number = num; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
630 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
631 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
632 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
633 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
634 | void BotscriptParser::parseSwitchDefault() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
635 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
636 | if (SCOPE (0).type != SCOPE_Switch) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
637 | error ("default label outside switch"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
638 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
639 | if (SCOPE (0).buffer1 != null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
640 | error ("multiple default labels in one switch"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
641 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
642 | m_lexer->mustGetNext (Token::Colon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
643 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
644 | // The default header is buffered into buffer1, since |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
645 | // it has to be the last of the case headers |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
646 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
647 | // Since the expression is pushed into the switch |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
648 | // and is only popped when case succeeds, we have |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
649 | // to pop it with DataHeader::Drop manually if we end up in |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
650 | // a default. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
651 | DataBuffer* buf = new DataBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
652 | SCOPE (0).buffer1 = buf; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
653 | buf->writeDWord (DataHeader::Drop); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
654 | buf->writeDWord (DataHeader::Goto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
655 | addSwitchCase (buf); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
656 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
657 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
658 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
659 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
660 | void BotscriptParser::parseBreak() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
661 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
662 | if (m_scopeCursor == 0) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
663 | error ("unexpected `break`"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
664 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
665 | currentBuffer()->writeDWord (DataHeader::Goto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
666 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
667 | // switch and if use mark1 for the closing point, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
668 | // for and while use mark2. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
669 | switch (SCOPE (0).type) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
670 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
671 | case SCOPE_If: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
672 | case SCOPE_Switch: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
673 | currentBuffer()->addReference (SCOPE (0).mark1); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
674 | break; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
675 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
676 | case SCOPE_For: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
677 | case SCOPE_While: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
678 | currentBuffer()->addReference (SCOPE (0).mark2); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
679 | break; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
680 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
681 | default: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
682 | error ("unexpected `break`"); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
683 | break; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
684 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
685 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
686 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
687 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
688 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
689 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
690 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
691 | void BotscriptParser::parseContinue() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
692 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
693 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
694 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
695 | int curs; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
696 | bool found = false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
697 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
698 | // Fall through the scope until we find a loop block |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
699 | for (curs = m_scopeCursor; curs > 0 and !found; curs--) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
700 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
701 | switch (m_scopeStack[curs].type) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
702 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
703 | case SCOPE_For: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
704 | case SCOPE_While: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
705 | case SCOPE_Do: |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
706 | currentBuffer()->writeDWord (DataHeader::Goto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
707 | currentBuffer()->addReference (m_scopeStack[curs].mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
708 | found = true; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
709 | break; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
710 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
711 | default: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
712 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
713 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
714 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
715 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
716 | // No loop blocks |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
717 | if (found == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
718 | error ("`continue`-statement not inside a loop"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
719 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
720 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
721 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
722 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
723 | void BotscriptParser::parseBlockEnd() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
724 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
725 | // Closing brace |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
726 | // If we're in the block stack, we're descending down from it now |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
727 | if (m_scopeCursor > 0) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
728 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
729 | switch (SCOPE (0).type) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
730 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
731 | case SCOPE_If: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
732 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
733 | // Adjust the closing mark. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
734 | currentBuffer()->adjustMark (SCOPE (0).mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
735 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
736 | // We're returning from `if`, thus `else` follow |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
737 | m_isElseAllowed = true; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
738 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
739 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
740 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
741 | case SCOPE_Else: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
742 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
743 | // else instead uses mark1 for itself (so if expression |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
744 | // fails, jump to else), mark2 means end of else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
745 | currentBuffer()->adjustMark (SCOPE (0).mark2); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
746 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
747 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
748 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
749 | case SCOPE_For: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
750 | { // write the incrementor at the end of the loop block |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
751 | currentBuffer()->mergeAndDestroy (SCOPE (0).buffer1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
752 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
753 | case SCOPE_While: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
754 | { // write down the instruction to go back to the start of the loop |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
755 | currentBuffer()->writeDWord (DataHeader::Goto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
756 | currentBuffer()->addReference (SCOPE (0).mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
757 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
758 | // Move the closing mark here since we're at the end of the while loop |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
759 | currentBuffer()->adjustMark (SCOPE (0).mark2); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
760 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
761 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
762 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
763 | case SCOPE_Do: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
764 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
765 | m_lexer->mustGetNext (Token::While); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
766 | m_lexer->mustGetNext (Token::ParenStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
767 | DataBuffer* expr = parseExpression (TYPE_Int); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
768 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
769 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
770 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
771 | // If the condition runs true, go back to the start. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
772 | currentBuffer()->mergeAndDestroy (expr); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
773 | currentBuffer()->writeDWord (DataHeader::IfGoto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
774 | currentBuffer()->addReference (SCOPE (0).mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
775 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
776 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
777 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
778 | case SCOPE_Switch: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
779 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
780 | // Switch closes. Move down to the record buffer of |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
781 | // the lower block. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
782 | if (SCOPE (1).casecursor != SCOPE (1).cases.begin() - 1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
783 | m_switchBuffer = SCOPE (1).casecursor->data; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
784 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
785 | m_switchBuffer = null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
786 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
787 | // If there was a default in the switch, write its header down now. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
788 | // If not, write instruction to jump to the end of switch after |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
789 | // the headers (thus won't fall-through if no case matched) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
790 | if (SCOPE (0).buffer1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
791 | currentBuffer()->mergeAndDestroy (SCOPE (0).buffer1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
792 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
793 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
794 | currentBuffer()->writeDWord (DataHeader::Drop); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
795 | currentBuffer()->writeDWord (DataHeader::Goto); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
796 | currentBuffer()->addReference (SCOPE (0).mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
797 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
798 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
799 | // Go through all of the buffers we |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
800 | // recorded down and write them. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
801 | for (CaseInfo& info : SCOPE (0).cases) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
802 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
803 | currentBuffer()->adjustMark (info.mark); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
804 | currentBuffer()->mergeAndDestroy (info.data); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
805 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
806 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
807 | // Move the closing mark here |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
808 | currentBuffer()->adjustMark (SCOPE (0).mark1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
809 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
810 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
811 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
812 | case SCOPE_Unknown: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
813 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
814 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
815 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
816 | // Descend down the stack |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
817 | m_scopeCursor--; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
818 | return; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
819 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
820 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
821 | int dataheader = (m_currentMode == PARSERMODE_Event) ? DataHeader::EndEvent |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
822 | : (m_currentMode == PARSERMODE_MainLoop) ? DataHeader::EndMainLoop |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
823 | : (m_currentMode == PARSERMODE_Onenter) ? DataHeader::EndOnEnter |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
824 | : (m_currentMode == PARSERMODE_Onexit) ? DataHeader::EndOnExit |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
825 | : -1; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
826 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
827 | if (dataheader == -1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
828 | error ("unexpected `}`"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
829 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
830 | // Data header must be written before mode is changed because |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
831 | // onenter and mainloop go into special buffers, and we want |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
832 | // the closing data headers into said buffers too. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
833 | currentBuffer()->writeDWord (dataheader); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
834 | m_currentMode = PARSERMODE_TopLevel; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
835 | m_lexer->next (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
836 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
837 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
838 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
839 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
840 | void BotscriptParser::parseEventdef() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
841 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
842 | EventDefinition* e = new EventDefinition; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
843 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
844 | m_lexer->mustGetNext (Token::Number); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
845 | e->number = getTokenString().toLong(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
846 | m_lexer->mustGetNext (Token::Colon); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
847 | m_lexer->mustGetNext (Token::Symbol); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
848 | e->name = m_lexer->token()->text; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
849 | m_lexer->mustGetNext (Token::ParenStart); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
850 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
851 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
852 | addEvent (e); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
853 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
854 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
855 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
856 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
857 | void BotscriptParser::parseFuncdef() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
858 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
859 | CommandInfo* comm = new CommandInfo; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
860 | comm->origin = m_lexer->describeCurrentPosition(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
861 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
862 | // Return value |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
863 | m_lexer->mustGetAnyOf ({Token::Int,Token::Void,Token::Bool,Token::Str}); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
864 | comm->returnvalue = getTypeByName (m_lexer->token()->text); // TODO |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
865 | ASSERT_NE (comm->returnvalue, -1); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
866 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
867 | // Number |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
868 | m_lexer->mustGetNext (Token::Number); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
869 | comm->number = m_lexer->token()->text.toLong(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
870 | m_lexer->mustGetNext (Token::Colon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
871 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
872 | // Name |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
873 | m_lexer->mustGetNext (Token::Symbol); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
874 | comm->name = m_lexer->token()->text; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
875 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
876 | // Arguments |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
877 | m_lexer->mustGetNext (Token::ParenStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
878 | comm->minargs = 0; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
879 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
880 | while (m_lexer->peekNextType (Token::ParenEnd) == false) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
881 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
882 | if (comm->args.isEmpty() == false) |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
883 | m_lexer->mustGetNext (Token::Comma); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
884 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
885 | CommandArgument arg; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
886 | m_lexer->mustGetAnyOf ({Token::Int,Token::Bool,Token::Str}); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
887 | DataType type = getTypeByName (m_lexer->token()->text); // TODO |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
888 | ASSERT_NE (type, -1) |
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
889 | ASSERT_NE (type, TYPE_Void) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
890 | arg.type = type; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
891 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
892 | m_lexer->mustGetNext (Token::Symbol); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
893 | arg.name = m_lexer->token()->text; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
894 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
895 | // If this is an optional parameter, we need the default value. |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
896 | if (comm->minargs < comm->args.size() or m_lexer->peekNextType (Token::Assign)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
897 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
898 | m_lexer->mustGetNext (Token::Assign); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
899 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
900 | switch (type) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
901 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
902 | case TYPE_Int: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
903 | case TYPE_Bool: |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
904 | m_lexer->mustGetNext (Token::Number); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
905 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
906 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
907 | case TYPE_String: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
908 | error ("string arguments cannot have default values"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
909 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
910 | case TYPE_Unknown: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
911 | case TYPE_Void: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
912 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
913 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
914 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
915 | arg.defvalue = m_lexer->token()->text.toLong(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
916 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
917 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
918 | comm->minargs++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
919 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
920 | comm->args << arg; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
921 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
922 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
923 | m_lexer->mustGetNext (Token::ParenEnd); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
924 | m_lexer->mustGetNext (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
925 | addCommandDefinition (comm); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
926 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
927 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
928 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
929 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
930 | // Parses a using statement |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
931 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
932 | void BotscriptParser::parseUsing() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
933 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
934 | checkToplevel(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
935 | m_lexer->mustGetSymbol ("zandronum"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
936 | String versionText; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
937 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
938 | while (m_lexer->next() and (m_lexer->tokenType() == Token::Number or m_lexer->tokenType() == Token::Dot)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
939 | versionText += getTokenString(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
940 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
941 | // Note: at this point the lexer's pointing at the token after the version. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
942 | if (versionText.isEmpty()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
943 | error ("expected version string, got `%1`", getTokenString()); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
944 | |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
945 | if (g_validZandronumVersions.contains (versionText) == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
946 | error ("unknown version string `%2`: valid versions: `%1`\n", g_validZandronumVersions, versionText); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
947 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
948 | StringList versionTokens = versionText.split ("."); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
949 | m_zandronumVersion = versionTokens[0].toLong() * 10000 + versionTokens[1].toLong() * 100; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
950 | m_defaultZandronumVersion = false; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
951 | m_lexer->tokenMustBe (Token::Semicolon); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
952 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
953 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
954 | // ============================================================================/ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
955 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
956 | // Parses a command call |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
957 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
958 | DataBuffer* BotscriptParser::parseCommand (CommandInfo* comm) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
959 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
960 | DataBuffer* r = new DataBuffer (64); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
961 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
962 | if (m_currentMode == PARSERMODE_TopLevel and comm->returnvalue == TYPE_Void) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
963 | error ("command call at top level"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
964 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
965 | m_lexer->mustGetNext (Token::ParenStart); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
966 | m_lexer->mustGetNext (Token::Any); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
967 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
968 | int curarg = 0; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
969 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
970 | for (;;) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
971 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
972 | if (tokenIs (Token::ParenEnd)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
973 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
974 | if (curarg < comm->minargs) |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
975 | { |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
976 | error ("too few arguments passed to %1\n\tusage is: %2", |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
977 | comm->name, comm->signature()); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
978 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
979 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
980 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
981 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
982 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
983 | if (curarg >= comm->args.size()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
984 | error ("too many arguments (%3) passed to %1\n\tusage is: %2", |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
985 | comm->name, comm->signature()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
986 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
987 | r->mergeAndDestroy (parseExpression (comm->args[curarg].type, true)); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
988 | m_lexer->mustGetNext (Token::Any); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
989 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
990 | if (curarg < comm->minargs - 1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
991 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
992 | m_lexer->tokenMustBe (Token::Comma); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
993 | m_lexer->mustGetNext (Token::Any); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
994 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
995 | else if (curarg < comm->args.size() - 1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
996 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
997 | // Can continue, but can terminate as well. |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
998 | if (tokenIs (Token::ParenEnd)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
999 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1000 | curarg++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1001 | break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1002 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1003 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1004 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1005 | m_lexer->tokenMustBe (Token::Comma); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1006 | m_lexer->mustGetNext (Token::Any); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1007 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1008 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1009 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1010 | curarg++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1011 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1012 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1013 | // If the script skipped any optional arguments, fill in defaults. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1014 | while (curarg < comm->args.size()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1015 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1016 | r->writeDWord (DataHeader::PushNumber); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1017 | r->writeDWord (comm->args[curarg].defvalue); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1018 | curarg++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1019 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1020 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1021 | r->writeDWord (DataHeader::Command); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1022 | r->writeDWord (comm->number); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1023 | r->writeDWord (comm->args.size()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1024 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1025 | return r; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1026 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1027 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1028 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1029 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1030 | String BotscriptParser::parseFloat() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1031 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1032 | m_lexer->tokenMustBe (Token::Number); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1033 | String floatstring = getTokenString(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1034 | Lexer::TokenInfo tok; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1035 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1036 | // Go after the decimal point |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1037 | if (m_lexer->peekNext (&tok) and tok.type ==Token::Dot) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1038 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1039 | m_lexer->skip(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1040 | m_lexer->mustGetNext (Token::Number); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1041 | floatstring += "."; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1042 | floatstring += getTokenString(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1043 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1044 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1045 | return floatstring; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1046 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1047 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1048 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1049 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1050 | // Parses an assignment operator. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1051 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1052 | AssignmentOperator BotscriptParser::parseAssignmentOperator() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1053 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1054 | const List<Token> tokens = |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1055 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1056 | Token::Assign, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1057 | Token::AddAssign, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1058 | Token::SubAssign, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1059 | Token::MultiplyAssign, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1060 | Token::DivideAssign, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1061 | Token::ModulusAssign, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1062 | Token::DoublePlus, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1063 | Token::DoubleMinus, |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1064 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1065 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1066 | m_lexer->mustGetAnyOf (tokens); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1067 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1068 | switch (m_lexer->tokenType()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1069 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1070 | case Token::Assign: return ASSIGNOP_Assign; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1071 | case Token::AddAssign: return ASSIGNOP_Add; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1072 | case Token::SubAssign: return ASSIGNOP_Subtract; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1073 | case Token::MultiplyAssign: return ASSIGNOP_Multiply; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1074 | case Token::DivideAssign: return ASSIGNOP_Divide; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1075 | case Token::ModulusAssign: return ASSIGNOP_Modulus; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1076 | case Token::DoublePlus: return ASSIGNOP_Increase; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1077 | case Token::DoubleMinus: return ASSIGNOP_Decrease; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1078 | default: break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1079 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1080 | |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
1081 | error ("WTF bad operator token %1", m_lexer->describeToken (m_lexer->token())); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1082 | return (AssignmentOperator) 0; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1083 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1084 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1085 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1086 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1087 | struct AssignmentDataHeaderInfo |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1088 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1089 | AssignmentOperator op; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1090 | DataHeader local; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1091 | DataHeader global; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1092 | DataHeader array; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1093 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1094 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1095 | const AssignmentDataHeaderInfo gAssignmentDataHeaders[] = |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1096 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1097 | { ASSIGNOP_Assign, DataHeader::AssignLocalVar, DataHeader::AssignGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1098 | DataHeader::AssignGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1099 | { ASSIGNOP_Add, DataHeader::AddLocalVar, DataHeader::AddGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1100 | DataHeader::AddGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1101 | { ASSIGNOP_Subtract, DataHeader::SubtractLocalVar, DataHeader::SubtractGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1102 | DataHeader::SubtractGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1103 | { ASSIGNOP_Multiply, DataHeader::MultiplyLocalVar, DataHeader::MultiplyGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1104 | DataHeader::MultiplyGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1105 | { ASSIGNOP_Divide, DataHeader::DivideLocalVar, DataHeader::DivideGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1106 | DataHeader::DivideGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1107 | { ASSIGNOP_Modulus, DataHeader::ModLocalVar, DataHeader::ModGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1108 | DataHeader::ModGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1109 | { ASSIGNOP_Increase, DataHeader::IncreaseLocalVar, DataHeader::IncreaseGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1110 | DataHeader::IncreaseGlobalArray }, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1111 | { ASSIGNOP_Decrease, DataHeader::DecreaseLocalVar, DataHeader::DecreaseGlobalVar, |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1112 | DataHeader::DecreaseGlobalArray }, |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1113 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1114 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1115 | DataHeader BotscriptParser::getAssigmentDataHeader (AssignmentOperator op, Variable* var) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1116 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1117 | for (const auto& a : gAssignmentDataHeaders) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1118 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1119 | if (a.op != op) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1120 | continue; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1121 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1122 | if (var->isarray) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1123 | return a.array; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1124 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1125 | if (var->isGlobal()) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1126 | return a.global; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1127 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1128 | return a.local; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1129 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1130 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1131 | error ("WTF: couldn't find data header for operator #%1", op); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1132 | return (DataHeader) 0; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1133 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1134 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1135 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1136 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1137 | // Parses an assignment. An assignment starts with a variable name, followed |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1138 | // by an assignment operator, followed by an expression value. Expects current |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1139 | // token to be the name of the variable, and expects the variable to be given. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1140 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1141 | DataBuffer* BotscriptParser::parseAssignment (Variable* var) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1142 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1143 | DataBuffer* retbuf = new DataBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1144 | DataBuffer* arrayindex = null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1145 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1146 | if (var->writelevel != WRITE_Mutable) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1147 | error ("cannot alter read-only variable $%1", var->name); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1148 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1149 | if (var->isarray) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1150 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1151 | m_lexer->mustGetNext (Token::BracketStart); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1152 | Expression expr (this, m_lexer, TYPE_Int); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1153 | expr.getResult()->convertToBuffer(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1154 | arrayindex = expr.getResult()->buffer()->clone(); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1155 | m_lexer->mustGetNext (Token::BracketEnd); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1156 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1157 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1158 | // Get an operator |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1159 | AssignmentOperator oper = parseAssignmentOperator(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1160 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1161 | if (m_currentMode == PARSERMODE_TopLevel) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1162 | error ("can't alter variables at top level"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1163 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1164 | if (var->isarray) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1165 | retbuf->mergeAndDestroy (arrayindex); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1166 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1167 | // Parse the right operand |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1168 | if (oper != ASSIGNOP_Increase and oper != ASSIGNOP_Decrease) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1169 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1170 | DataBuffer* expr = parseExpression (var->type); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1171 | retbuf->mergeAndDestroy (expr); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1172 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1173 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1174 | #if 0 |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1175 | // <<= and >>= do not have data headers. Solution: expand them. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1176 | // a <<= b -> a = a << b |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1177 | // a >>= b -> a = a >> b |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1178 | retbuf->WriteDWord (var->IsGlobal() ? DataHeader::PushGlobalVar : DataHeader::PushLocalVar); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1179 | retbuf->WriteDWord (var->index); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1180 | retbuf->MergeAndDestroy (expr); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1181 | retbuf->WriteDWord ((oper == OPER_ASSIGNLEFTSHIFT) ? DataHeader::LeftShift : |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1182 | DataHeader::RightShift); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1183 | retbuf->WriteDWord (var->IsGlobal() ? DataHeader::AssignGlobalVar : DataHeader::AssignLocalVar); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1184 | retbuf->WriteDWord (var->index); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1185 | #endif |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1186 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1187 | DataHeader dh = getAssigmentDataHeader (oper, var); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1188 | retbuf->writeDWord (dh); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1189 | retbuf->writeDWord (var->index); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1190 | return retbuf; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1191 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1192 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1193 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1194 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1195 | void BotscriptParser::pushScope (bool noreset) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1196 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1197 | m_scopeCursor++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1198 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1199 | if (m_scopeStack.size() < m_scopeCursor + 1) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1200 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1201 | ScopeInfo newscope; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1202 | m_scopeStack << newscope; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1203 | noreset = false; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1204 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1205 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1206 | if (not noreset) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1207 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1208 | ScopeInfo* info = &SCOPE (0); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1209 | info->type = SCOPE_Unknown; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1210 | info->mark1 = null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1211 | info->mark2 = null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1212 | info->buffer1 = null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1213 | info->cases.clear(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1214 | info->casecursor = info->cases.begin() - 1; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1215 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1216 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1217 | // Reset variable stuff in any case |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1218 | SCOPE(0).globalVarIndexBase = (m_scopeCursor == 0) ? 0 : SCOPE(1).globalVarIndexBase; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1219 | SCOPE(0).localVarIndexBase = (m_scopeCursor == 0) ? 0 : SCOPE(1).localVarIndexBase; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1220 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1221 | for (Variable* var : SCOPE(0).globalVariables + SCOPE(0).localVariables) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1222 | delete var; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1223 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1224 | SCOPE(0).localVariables.clear(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1225 | SCOPE(0).globalVariables.clear(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1226 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1227 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1228 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1229 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1230 | DataBuffer* BotscriptParser::parseExpression (DataType reqtype, bool fromhere) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1231 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1232 | // hehe |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1233 | if (fromhere) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1234 | m_lexer->skip (-1); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1235 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1236 | Expression expr (this, m_lexer, reqtype); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1237 | expr.getResult()->convertToBuffer(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1238 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1239 | // The buffer will be destroyed once the function ends so we need to |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1240 | // clone it now. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1241 | return expr.getResult()->buffer()->clone(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1242 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1243 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1244 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1245 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1246 | DataBuffer* BotscriptParser::parseStatement() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1247 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1248 | // If it's a variable, expect assignment. |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1249 | if (m_lexer->next (Token::DollarSign)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1250 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1251 | m_lexer->mustGetNext (Token::Symbol); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1252 | Variable* var = findVariable (getTokenString()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1253 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1254 | if (var == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1255 | error ("unknown variable $%1", var->name); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1256 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1257 | return parseAssignment (var); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1258 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1259 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1260 | return null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1261 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1262 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1263 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1264 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1265 | void BotscriptParser::addSwitchCase (DataBuffer* casebuffer) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1266 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1267 | ScopeInfo* info = &SCOPE (0); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1268 | CaseInfo casedata; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1269 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1270 | // Init a mark for the case buffer |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1271 | ByteMark* casemark = currentBuffer()->addMark (""); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1272 | casedata.mark = casemark; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1273 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1274 | // Add a reference to the mark. "case" and "default" both |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1275 | // add the necessary bytecode before the reference. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1276 | if (casebuffer != null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1277 | casebuffer->addReference (casemark); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1278 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1279 | currentBuffer()->addReference (casemark); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1280 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1281 | // Init a buffer for the case block and tell the object |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1282 | // writer to record all written data to it. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1283 | casedata.data = m_switchBuffer = new DataBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1284 | SCOPE(0).cases << casedata; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1285 | info->casecursor++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1286 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1287 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1288 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1289 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1290 | bool BotscriptParser::tokenIs (Token a) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1291 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1292 | return (m_lexer->tokenType() == a); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1293 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1294 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1295 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1296 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1297 | String BotscriptParser::getTokenString() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1298 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1299 | return m_lexer->token()->text; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1300 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1301 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1302 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1303 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1304 | String BotscriptParser::describePosition() const |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1305 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1306 | Lexer::TokenInfo* tok = m_lexer->token(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1307 | return tok->file + ":" + String (tok->line) + ":" + String (tok->column); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1308 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1309 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1310 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1311 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1312 | DataBuffer* BotscriptParser::currentBuffer() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1313 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1314 | if (m_switchBuffer != null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1315 | return m_switchBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1316 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1317 | if (m_currentMode == PARSERMODE_MainLoop) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1318 | return m_mainLoopBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1319 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1320 | if (m_currentMode == PARSERMODE_Onenter) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1321 | return m_onenterBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1322 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1323 | return m_mainBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1324 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1325 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1326 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1327 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1328 | void BotscriptParser::writeMemberBuffers() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1329 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1330 | // If there was no mainloop defined, write a dummy one now. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1331 | if (m_gotMainLoop == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1332 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1333 | m_mainLoopBuffer->writeDWord (DataHeader::MainLoop); |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1334 | m_mainLoopBuffer->writeDWord (DataHeader::EndMainLoop); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1335 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1336 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1337 | // Write the onenter and mainloop buffers, in that order in particular. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1338 | for (DataBuffer** bufp : List<DataBuffer**> ({&m_onenterBuffer, &m_mainLoopBuffer})) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1339 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1340 | currentBuffer()->mergeAndDestroy (*bufp); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1341 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1342 | // Clear the buffer afterwards for potential next state |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1343 | *bufp = new DataBuffer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1344 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1345 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1346 | // Next state definitely has no mainloop yet |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1347 | m_gotMainLoop = false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1348 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1349 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1350 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1351 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1352 | // Write string table |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1353 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1354 | void BotscriptParser::writeStringTable() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1355 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1356 | int stringcount = countStringsInTable(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1357 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1358 | if (stringcount == 0) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1359 | return; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1360 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1361 | // Write header |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1362 | m_mainBuffer->writeDWord (DataHeader::StringList); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1363 | m_mainBuffer->writeDWord (stringcount); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1364 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1365 | // Write all strings |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1366 | for (int i = 0; i < stringcount; i++) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1367 | m_mainBuffer->writeString (getStringTable()[i]); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1368 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1369 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1370 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1371 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1372 | // Write the compiled bytecode to a file |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1373 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1374 | void BotscriptParser::writeToFile (String outfile) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1375 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1376 | FILE* fp = fopen (outfile, "wb"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1377 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1378 | if (fp == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1379 | error ("couldn't open %1 for writing: %2", outfile, strerror (errno)); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1380 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1381 | // First, resolve references |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1382 | for (MarkReference* ref : m_mainBuffer->references()) |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1383 | { |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1384 | for (int i = 0; i < 4; ++i) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1385 | m_mainBuffer->buffer()[ref->pos + i] = (ref->target->pos >> (8 * i)) & 0xFF; |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
1386 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1387 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1388 | // Then, dump the main buffer to the file |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1389 | fwrite (m_mainBuffer->buffer(), 1, m_mainBuffer->writtenSize(), fp); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1390 | print ("-- %1 byte%s1 written to %2\n", m_mainBuffer->writtenSize(), outfile); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1391 | fclose (fp); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1392 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1393 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1394 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1395 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1396 | // Attempt to find the variable by the given name. Looks from current scope |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1397 | // downwards. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1398 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1399 | Variable* BotscriptParser::findVariable (const String& name) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1400 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1401 | for (int i = m_scopeCursor; i >= 0; --i) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1402 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1403 | for (Variable* var : m_scopeStack[i].globalVariables + m_scopeStack[i].localVariables) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1404 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1405 | if (var->name == name) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1406 | return var; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1407 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1408 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1409 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1410 | return null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1411 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1412 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1413 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1414 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1415 | // Is the parser currently in global state (i.e. not in any specific state)? |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1416 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1417 | bool BotscriptParser::isInGlobalState() const |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1418 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1419 | return m_currentState.isEmpty(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1420 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1421 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1422 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1423 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1424 | void BotscriptParser::suggestHighestVarIndex (bool global, int index) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1425 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1426 | if (global) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1427 | m_highestGlobalVarIndex = max (m_highestGlobalVarIndex, index); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1428 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1429 | m_highestStateVarIndex = max (m_highestStateVarIndex, index); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1430 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1431 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1432 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1433 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1434 | int BotscriptParser::getHighestVarIndex (bool global) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1435 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1436 | if (global) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1437 | return m_highestGlobalVarIndex; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1438 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1439 | return m_highestStateVarIndex; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1440 | } |