Track parent values as we resolve

In this patch, it's just to indent the debug output nicely.
This commit is contained in:
Havoc Pennington 2014-07-04 23:44:54 -04:00
parent 7994e02c71
commit 66d21576b1

View File

@ -29,20 +29,24 @@ final class ResolveContext {
// resolution fails. // resolution fails.
final private List<SubstitutionExpression> expressionTrace; final private List<SubstitutionExpression> expressionTrace;
ResolveContext(ResolveSource source, ResolveMemos memos, ConfigResolveOptions options, // This is used for tracing and debugging.
Path restrictToChild, List<SubstitutionExpression> expressionTrace) { final private List<AbstractConfigValue> treeStack;
ResolveContext(ResolveSource source, ResolveMemos memos, ConfigResolveOptions options, Path restrictToChild,
List<SubstitutionExpression> expressionTrace, List<AbstractConfigValue> treeStack) {
this.source = source; this.source = source;
this.memos = memos; this.memos = memos;
this.options = options; this.options = options;
this.restrictToChild = restrictToChild; this.restrictToChild = restrictToChild;
this.expressionTrace = expressionTrace; this.expressionTrace = expressionTrace;
this.treeStack = treeStack;
} }
ResolveContext(AbstractConfigObject root, ConfigResolveOptions options, Path restrictToChild) { ResolveContext(AbstractConfigObject root, ConfigResolveOptions options, Path restrictToChild) {
// LinkedHashSet keeps the traversal order which is at least useful // LinkedHashSet keeps the traversal order which is at least useful
// in error messages if nothing else // in error messages if nothing else
this(new ResolveSource(root), new ResolveMemos(), options, restrictToChild, this(new ResolveSource(root), new ResolveMemos(), options, restrictToChild,
new ArrayList<SubstitutionExpression>()); new ArrayList<SubstitutionExpression>(), new ArrayList<AbstractConfigValue>());
if (ConfigImpl.traceSubstitutionsEnabled()) if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace("ResolveContext at root " + root + " restrict to child " + restrictToChild); ConfigImpl.trace("ResolveContext at root " + root + " restrict to child " + restrictToChild);
} }
@ -67,7 +71,7 @@ final class ResolveContext {
if (restrictTo == restrictToChild) if (restrictTo == restrictToChild)
return this; return this;
else else
return new ResolveContext(source, memos, options, restrictTo, expressionTrace); return new ResolveContext(source, memos, options, restrictTo, expressionTrace, treeStack);
} }
ResolveContext unrestricted() { ResolveContext unrestricted() {
@ -98,14 +102,32 @@ final class ResolveContext {
return sb.toString(); return sb.toString();
} }
void stack(AbstractConfigValue value) {
treeStack.add(value);
}
void unstack() {
treeStack.remove(treeStack.size() - 1);
}
int depth() { int depth() {
return expressionTrace.size(); return treeStack.size();
} }
AbstractConfigValue resolve(AbstractConfigValue original) throws NotPossibleToResolve { AbstractConfigValue resolve(AbstractConfigValue original) throws NotPossibleToResolve {
if (ConfigImpl.traceSubstitutionsEnabled()) if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace(depth(), "resolving " + original); ConfigImpl.trace(depth(), "resolving " + original);
AbstractConfigValue resolved;
stack(original);
try {
resolved = realResolve(original);
} finally {
unstack();
}
return resolved;
}
private AbstractConfigValue realResolve(AbstractConfigValue original) throws NotPossibleToResolve {
// a fully-resolved (no restrictToChild) object can satisfy a // a fully-resolved (no restrictToChild) object can satisfy a
// request for a restricted object, so always check that first. // request for a restricted object, so always check that first.
final MemoKey fullKey = new MemoKey(original, null); final MemoKey fullKey = new MemoKey(original, null);