MCPcopy Create free account
hub / github.com/antlr/codebuff / setDefaultArguments

Method setDefaultArguments

output/java/1.4.19/Interpreter.java:1266–1301  ·  view source on GitHub ↗

Set any default argument values that were not set by the invoking template or by ST#add directly. Note that the default values may be templates. The evaluation context is the invokedST template itself so template default arguments can see other arguments.

(STWriter out, InstanceScope scope)

Source from the content-addressed store, hash-verified

1264 */
1265
1266 public void setDefaultArguments(STWriter out, InstanceScope scope) {
1267 final ST invokedST = scope.st;
1268 if ( invokedST.impl.formalArguments==null || invokedST.impl.numberOfArgsWithDefaultValues==0) {
1269 return;
1270 }
1271 for (FormalArgument arg : invokedST.impl.formalArguments.values()) {
1272 // if no value for attribute and default arg, inject default arg into self
1273 if ( invokedST.locals[arg.index]!= ST.EMPTY_ATTR || arg.defaultValueToken==null ) {
1274 continue;
1275 }
1276 //System.out.println("setting def arg "+arg.name+" to "+arg.defaultValueToken);
1277 if ( arg.defaultValueToken.getType()== GroupParser.ANONYMOUS_TEMPLATE ) {
1278 CompiledST code = arg.compiledDefaultValue;
1279 if ( code==null ) {
1280 code = new CompiledST();
1281 }
1282 ST defaultArgST = group.createStringTemplateInternally(code);
1283 defaultArgST.groupThatCreatedThisInstance = group;
1284 // If default arg is template with single expression
1285 // wrapped in parens, x={<(...)>}, then eval to string
1286 // rather than setting x to the template for later
1287 // eval.
1288 String defArgTemplate = arg.defaultValueToken.getText();
1289 if ( defArgTemplate.startsWith("{"+group.delimiterStartChar+"(") && defArgTemplate.endsWith(")"+group.delimiterStopChar+"}") ) {
1290 invokedST.rawSetAttribute(arg.name,
1291 toString(out, new InstanceScope(scope, invokedST), defaultArgST));
1292 }
1293 else {
1294 invokedST.rawSetAttribute(arg.name, defaultArgST);
1295 }
1296 }
1297 else {
1298 invokedST.rawSetAttribute(arg.name, arg.defaultValue);
1299 }
1300 }
1301 }
1302
1303 /**
1304 * If an instance of <i>x</i> is enclosed in a <i>y</i> which is in a

Callers 1

execMethod · 0.95

Calls 6

rawSetAttributeMethod · 0.95
toStringMethod · 0.95
valuesMethod · 0.65
getTextMethod · 0.65
getTypeMethod · 0.45

Tested by

no test coverage detected