@@ -38,6 +38,11 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3838#include " debug.h"
3939#include " param.h"
4040
41+ #include " statemnt.h"
42+ #include " license.h"
43+ #include " scriptpt.h"
44+ #include " newobj.h"
45+
4146// SN-2014-09-05: [[ Bug 13378 ]] Include the definition of MCServerScript
4247#ifdef _SERVER
4348#include " srvscript.h"
@@ -1222,6 +1227,168 @@ void MCExecContext::SetTheResultToBool(bool p_bool)
12221227 MCresult -> sets (MCU_btos (p_bool));
12231228}
12241229
1230+ // SN-2015-06-03: [[ Bug 11277 ]] Refactor MCExecPoint update
1231+ void MCExecContext::deletestatements (MCStatement* p_statements)
1232+ {
1233+ while (p_statements != NULL )
1234+ {
1235+ MCStatement *tsptr = p_statements;
1236+ p_statements = p_statements->getnext ();
1237+ delete tsptr;
1238+ }
1239+ }
1240+
1241+ void MCExecContext::eval (MCExecContext &ctxt, MCStringRef p_expression, MCValueRef &r_value)
1242+ {
1243+ MCScriptPoint sp (ctxt, p_expression);
1244+ // SN-2015-06-03: [[ Bug 11277 ]] When we are out of handler, then it simply
1245+ // sets the ScriptPoint handler to NULL (same as post-constructor state).
1246+ sp.sethandler (ctxt . GetHandler ());
1247+ MCExpression *exp = NULL ;
1248+ Symbol_type type;
1249+
1250+ if (sp.parseexp (False, True, &exp) == PS_NORMAL && sp.next (type) == PS_EOF)
1251+ ctxt . EvalExprAsValueRef (exp, EE_HANDLER_BADEXP, r_value);
1252+ else
1253+ ctxt . Throw ();
1254+
1255+ delete exp;
1256+ }
1257+
1258+ void MCExecContext::eval_ctxt (MCExecContext &ctxt, MCStringRef p_expression, MCExecValue& r_value)
1259+ {
1260+ MCScriptPoint sp (ctxt, p_expression);
1261+ // SN-2015-06-03: [[ Bug 11277 ]] When we are out of handler, then it simply
1262+ // sets the ScriptPoint handler to NULL (same as post-constructor state).
1263+ sp.sethandler (ctxt . GetHandler ());
1264+ MCExpression *exp = NULL ;
1265+ Symbol_type type;
1266+
1267+ if (sp.parseexp (False, True, &exp) == PS_NORMAL && sp.next (type) == PS_EOF)
1268+ ctxt . EvaluateExpression (exp, EE_HANDLER_BADEXP, r_value);
1269+ else
1270+ ctxt . Throw ();
1271+
1272+ delete exp;
1273+ }
1274+
1275+ void MCExecContext::doscript (MCExecContext &ctxt, MCStringRef p_script, uinteger_t p_line, uinteger_t p_pos)
1276+ {
1277+ MCScriptPoint sp (ctxt, p_script);
1278+ MCStatement *curstatement = NULL ;
1279+ MCStatement *statements = NULL ;
1280+ MCStatement *newstatement = NULL ;
1281+ Symbol_type type;
1282+ const LT *te;
1283+ Exec_stat stat = ES_NORMAL;
1284+ Boolean oldexplicit = MCexplicitvariables;
1285+ MCexplicitvariables = False;
1286+ uint4 count = 0 ;
1287+ sp.setline (p_line - 1 );
1288+ while (stat == ES_NORMAL)
1289+ {
1290+ switch (sp.next (type))
1291+ {
1292+ case PS_NORMAL:
1293+ if (type == ST_ID)
1294+ if (sp.lookup (SP_COMMAND, te) != PS_NORMAL)
1295+ newstatement = new MCComref (sp.gettoken_nameref ());
1296+ else
1297+ {
1298+ if (te->type != TT_STATEMENT)
1299+ {
1300+ MCeerror->add (EE_DO_NOTCOMMAND, p_line, p_pos, sp.gettoken_stringref ());
1301+ stat = ES_ERROR;
1302+ }
1303+ else
1304+ newstatement = MCN_new_statement (te->which );
1305+ }
1306+ else
1307+ {
1308+ MCeerror->add (EE_DO_NOCOMMAND, p_line, p_pos, sp.gettoken_stringref ());
1309+ stat = ES_ERROR;
1310+ }
1311+ if (stat == ES_NORMAL)
1312+ {
1313+ if (curstatement == NULL )
1314+ statements = curstatement = newstatement;
1315+ else
1316+ {
1317+ curstatement->setnext (newstatement);
1318+ curstatement = newstatement;
1319+ }
1320+ if (curstatement->parse (sp) != PS_NORMAL)
1321+ {
1322+ MCeerror->add (EE_DO_BADCOMMAND, p_line, p_pos, p_script);
1323+ stat = ES_ERROR;
1324+ }
1325+ count += curstatement->linecount ();
1326+ }
1327+ break ;
1328+ case PS_EOL:
1329+ if (sp.skip_eol () != PS_NORMAL)
1330+ {
1331+ MCeerror->add (EE_DO_BADLINE, p_line, p_pos, p_script);
1332+ stat = ES_ERROR;
1333+ }
1334+ break ;
1335+ case PS_EOF:
1336+ stat = ES_PASS;
1337+ break ;
1338+ default :
1339+ stat = ES_ERROR;
1340+ }
1341+ }
1342+ MCexplicitvariables = oldexplicit;
1343+
1344+ if (MClicenseparameters . do_limit > 0 && count >= MClicenseparameters . do_limit)
1345+ {
1346+ MCeerror -> add (EE_DO_NOTLICENSED, p_line, p_pos, p_script);
1347+ stat = ES_ERROR;
1348+ }
1349+
1350+ if (stat == ES_ERROR)
1351+ {
1352+ deletestatements (statements);
1353+ ctxt.Throw ();
1354+ return ;
1355+ }
1356+
1357+ MCExecContext ctxt2 (ctxt);
1358+ while (statements != NULL )
1359+ {
1360+ statements->exec_ctxt (ctxt2);
1361+ Exec_stat stat = ctxt2 . GetExecStat ();
1362+ if (stat == ES_ERROR)
1363+ {
1364+ deletestatements (statements);
1365+ MCeerror->add (EE_DO_BADEXEC, p_line, p_pos, p_script);
1366+ ctxt.Throw ();
1367+ return ;
1368+ }
1369+ if (MCexitall || stat != ES_NORMAL)
1370+ {
1371+ deletestatements (statements);
1372+ if (stat == ES_ERROR)
1373+ ctxt.Throw ();
1374+ return ;
1375+ }
1376+ else
1377+ {
1378+ MCStatement *tsptr = statements;
1379+ statements = statements->getnext ();
1380+ delete tsptr;
1381+ }
1382+ }
1383+ if (MCscreen->abortkey ())
1384+ {
1385+ MCeerror->add (EE_DO_ABORT, p_line, p_pos);
1386+ ctxt.Throw ();
1387+ return ;
1388+ }
1389+ return ;
1390+ }
1391+
12251392// //////////////////////////////////////////////////////////////////////////////
12261393
12271394static bool MCPropertyFormatUIntList (uinteger_t *p_list, uindex_t p_count, char_t p_delimiter, MCStringRef& r_string)
0 commit comments