MCPcopy Create free account
hub / github.com/albertodemichelis/squirrel / Statement

Method Statement

squirrel/sqcompiler.cpp:209–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207 }
208 }
209 void Statement(bool closeframe = true)
210 {
211 _fs->AddLineInfos(_lex._currentline, _lineinfo);
212 switch(_token){
213 case _SC(';'): Lex(); break;
214 case TK_IF: IfStatement(); break;
215 case TK_WHILE: WhileStatement(); break;
216 case TK_DO: DoWhileStatement(); break;
217 case TK_FOR: ForStatement(); break;
218 case TK_FOREACH: ForEachStatement(); break;
219 case TK_SWITCH: SwitchStatement(); break;
220 case TK_LOCAL: LocalDeclStatement(); break;
221 case TK_RETURN:
222 case TK_YIELD: {
223 SQOpcode op;
224 if(_token == TK_RETURN) {
225 op = _OP_RETURN;
226 }
227 else {
228 op = _OP_YIELD;
229 _fs->_bgenerator = true;
230 }
231 Lex();
232 if(!IsEndOfStatement()) {
233 SQInteger retexp = _fs->GetCurrentPos()+1;
234 CommaExpr();
235 if(op == _OP_RETURN && _fs->_traps > 0)
236 _fs->AddInstruction(_OP_POPTRAP, _fs->_traps, 0);
237 _fs->_returnexp = retexp;
238 _fs->AddInstruction(op, 1, _fs->PopTarget(),_fs->GetStackSize());
239 }
240 else{
241 if(op == _OP_RETURN && _fs->_traps > 0)
242 _fs->AddInstruction(_OP_POPTRAP, _fs->_traps ,0);
243 _fs->_returnexp = -1;
244 _fs->AddInstruction(op, 0xFF,0,_fs->GetStackSize());
245 }
246 break;}
247 case TK_BREAK:
248 if(_fs->_breaktargets.size() <= 0)Error(_SC("'break' has to be in a loop block"));
249 if(_fs->_breaktargets.top() > 0){
250 _fs->AddInstruction(_OP_POPTRAP, _fs->_breaktargets.top(), 0);
251 }
252 RESOLVE_OUTERS();
253 _fs->AddInstruction(_OP_JMP, 0, -1234);
254 _fs->_unresolvedbreaks.push_back(_fs->GetCurrentPos());
255 Lex();
256 break;
257 case TK_CONTINUE:
258 if(_fs->_continuetargets.size() <= 0)Error(_SC("'continue' has to be in a loop block"));
259 if(_fs->_continuetargets.top() > 0) {
260 _fs->AddInstruction(_OP_POPTRAP, _fs->_continuetargets.top(), 0);
261 }
262 RESOLVE_OUTERS();
263 _fs->AddInstruction(_OP_JMP, 0, -1234);
264 _fs->_unresolvedcontinues.push_back(_fs->GetCurrentPos());
265 Lex();
266 break;

Callers

nothing calls this directly

Calls 11

AddLineInfosMethod · 0.80
GetCurrentPosMethod · 0.80
PopTargetMethod · 0.80
GetStackSizeMethod · 0.80
sizeMethod · 0.80
DiscardTargetMethod · 0.80
SnoozeOptMethod · 0.80
SQObjectPtrClass · 0.70
AddInstructionMethod · 0.45
NewSlotMethod · 0.45
NullMethod · 0.45

Tested by

no test coverage detected