MCPcopy Create free account
hub / github.com/SWI-Prolog/packages-jpl / getSubstsLoop

Method getSubstsLoop

src/main/java/org/jpl7/Term.java:1240–1279  ·  view source on GitHub ↗
(Map<String, Term> varnames_to_Terms, Map<term_t, Variable> vars_to_Vars, Term[] args)

Source from the content-addressed store, hash-verified

1238 }
1239
1240 protected static void getSubstsLoop(Map<String, Term> varnames_to_Terms, Map<term_t, Variable> vars_to_Vars, Term[] args) {
1241 GetSubstsTask top = (args.length > 0 ? new GetSubstsTask(0, args, null) : null); // prime the stack
1242 while (top != null) {
1243 GetSubstsTask task = top;
1244 Term t = task.args[task.n];
1245 if (task.n+1 < task.args.length) { // there are further args to scan
1246 task.n++; // update this recurrent task for next arg and leave it on the stack
1247 } else {
1248 top = top.prev; // pop this now-completed recurrent task
1249 }
1250 switch (t.type()) {
1251 case Prolog.VARIABLE:
1252 Variable v = (Variable) t;
1253 if (v.tellThem() && varnames_to_Terms.get(v.name) == null) {
1254 varnames_to_Terms.put(v.name, Term.getTerm(vars_to_Vars, v.term_));
1255 }
1256 break;
1257 case Prolog.COMPOUND:
1258 case Prolog.LIST_PAIR:
1259 if (t.args().length > 0) { // this Compound has at least one arg
1260 top = new GetSubstsTask(0, t.args(), top);
1261 } else {
1262 // zero-arity Compound; no subterms to traverse
1263 }
1264 break;
1265 case Prolog.ATOM:
1266 case Prolog.BLOB:
1267 case Prolog.DICT:
1268 case Prolog.FLOAT:
1269 case Prolog.INTEGER:
1270 case Prolog.JREF:
1271 case Prolog.LIST_NIL:
1272 case Prolog.RATIONAL:
1273 case Prolog.STRING:
1274 break; // nothing to do for these term types
1275 default: // should never happen
1276 throw new JPLException("unknown term type=" + t.type());
1277 }
1278 }
1279 }
1280
1281}

Callers 1

getSubstsMethod · 0.95

Calls 5

typeMethod · 0.95
tellThemMethod · 0.95
getTermMethod · 0.95
argsMethod · 0.95
putMethod · 0.80

Tested by

no test coverage detected