Warning: session_start(): open(/var/lib/php/sessions/sess_f35b2si9s72hltbfo7tbs1ogk3, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass CodeSafetyChecker {
// general data
SS identifierSafetyMap;
bool identifiersStartingWithDollarAreSafe;
// data for code currently tested
S code;
Set identifiers;
LS unknownIdentifiers;
LS tags;
void init {
if (identifierSafetyMap == null)
identifierSafetyMap = codeAnalysis_identifierSafetyMap();
}
run {
init();
LS tok = tok_inStringEvals(code);
tok_inStringEvals(tok);
identifiers = tok_allIdentifiersWithoutColonEquals(tok);
unknownIdentifiers = new L;
Set tags = treeSet();
for (S id : identifiers) {
S tag;
if (identifiersStartingWithDollarAreSafe && startsWith(id, "$"))
tag = "safe";
else
tag = or2(mapGet(identifierSafetyMap, id), "?");
if (eq(tag, "?"))
unknownIdentifiers.add(id);
tags.addAll(tokSplitAtComma(tag));
}
this.tags = simplifySafetyTags(tags);
if (empty(this.tags)) this.tags.add("safe");
}
S checkCode(S code) {
this.code = code;
run();
ret joinWithComma(tags);
}
S verbalCheckResult(S code) {
checkCode(code);
ret verbalCheckResult();
}
S verbalCheckResult() {
S safety = joinWithComma(tags);
if (neq(safety, "safe") && nempty(unknownIdentifiers))
safety += ". Unknown identifiers: " + joinWithComma(unknownIdentifiers);
ret safety;
}
void markSafe(S... ids) {
init();
putMultipleKeys(identifierSafetyMap, asList(ids), "safe");
}
bool isSafe() {
ret eq(tags, ll("safe"));
}
}