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

Method ParseTableOrClass

squirrel/sqcompiler.cpp:968–1036  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

966 }
967 }
968 void ParseTableOrClass(SQInteger separator,SQInteger terminator)
969 {
970 SQInteger tpos = _fs->GetCurrentPos(),nkeys = 0;
971 while(_token != terminator) {
972 bool hasattrs = false;
973 bool isstatic = false;
974 //check if is an attribute
975 if(separator == ';') {
976 if(_token == TK_ATTR_OPEN) {
977 _fs->AddInstruction(_OP_NEWOBJ, _fs->PushTarget(),0,NOT_TABLE); Lex();
978 ParseTableOrClass(',',TK_ATTR_CLOSE);
979 hasattrs = true;
980 }
981 if(_token == TK_STATIC) {
982 isstatic = true;
983 Lex();
984 }
985 }
986 switch(_token) {
987 case TK_FUNCTION:
988 case TK_CONSTRUCTOR:{
989 SQInteger tk = _token;
990 Lex();
991 SQObject id = tk == TK_FUNCTION ? Expect(TK_IDENTIFIER) : _fs->CreateString(_SC("constructor"));
992 _fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(id));
993 SQInteger boundtarget = 0xFF;
994 if (_token == _SC('[')) {
995 boundtarget = ParseBindEnv();
996 }
997 Expect(_SC('('));
998
999 CreateFunction(id, boundtarget);
1000 _fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, boundtarget);
1001 }
1002 break;
1003 case _SC('['):
1004 Lex(); CommaExpr(); Expect(_SC(']'));
1005 Expect(_SC('=')); Expression();
1006 break;
1007 case TK_STRING_LITERAL: //JSON
1008 if(separator == ',') { //only works for tables
1009 _fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(Expect(TK_STRING_LITERAL)));
1010 Expect(_SC(':')); Expression();
1011 break;
1012 }
1013 default :
1014 _fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(Expect(TK_IDENTIFIER)));
1015 Expect(_SC('=')); Expression();
1016 }
1017 if(_token == separator) Lex();//optional comma/semicolon
1018 nkeys++;
1019 SQInteger val = _fs->PopTarget();
1020 SQInteger key = _fs->PopTarget();
1021 SQInteger attrs = hasattrs ? _fs->PopTarget():-1;
1022 ((void)attrs);
1023 assert((hasattrs && (attrs == key-1)) || !hasattrs);
1024 unsigned char flags = (hasattrs?NEW_SLOT_ATTRIBUTES_FLAG:0)|(isstatic?NEW_SLOT_STATIC_FLAG:0);
1025 SQInteger table = _fs->TopTarget(); //<<BECAUSE OF THIS NO COMMON EMIT FUNC IS POSSIBLE

Callers

nothing calls this directly

Calls 9

GetCurrentPosMethod · 0.80
PushTargetMethod · 0.80
CreateStringMethod · 0.80
GetConstantMethod · 0.80
sizeMethod · 0.80
PopTargetMethod · 0.80
TopTargetMethod · 0.80
SetInstructionParamMethod · 0.80
AddInstructionMethod · 0.45

Tested by

no test coverage detected