Merge pull request #1470 from Microsoft/flagAggregation

Make utility method names clearer.
This commit is contained in:
CyrusNajmabadi 2014-12-12 15:50:03 -08:00
commit fbfb94f776
2 changed files with 14 additions and 13 deletions

View file

@ -325,14 +325,12 @@ module ts {
// Context flags computed by aggregating child flags upwards.
// If this node, or any of it's children (transitively) contain an error.
// Used during incremental parsing to determine if this node or any of its children had an
// error. Computed only once and then cached.
ThisNodeOrAnySubNodesHasError = 1 << 5,
// Used during incremental parsing to determine if we need to visit this node to see if
// any of its children had an error. Once we compute that once, we can set this bit on the
// node to know that we never have to do it again. From that point on, we can just check
// the node directly for 'ContainsError'.
HasComputedThisNodeOrAnySubNodesHasError = 1 << 6
// Used to know if we've computed data from children and cached it in this node.
HasAggregatedChildData = 1 << 6
}
export interface Node extends TextRange {

View file

@ -62,31 +62,34 @@ module ts {
return node.end - node.pos;
}
export function hasFlag(val: number, flag: number): boolean {
function hasFlag(val: number, flag: number): boolean {
return (val & flag) !== 0;
}
// Returns true if this node contains a parse error anywhere underneath it.
export function containsParseError(node: Node): boolean {
if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError)) {
aggregateChildData(node);
return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError);
}
function aggregateChildData(node: Node): void {
if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasAggregatedChildData)) {
// A node is considered to contain a parse error if:
// a) the parser explicitly marked that it had an error
// b) any of it's children reported that it had an error.
var val = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) ||
var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) ||
forEachChild(node, containsParseError);
// If so, mark ourselves accordingly.
if (val) {
if (thisNodeOrAnySubNodesHasError) {
node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError;
}
// Also mark that we've propogated the child information to this node. This way we can
// always consult the bit directly on this node without needing to check its children
// again.
node.parserContextFlags |= ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError;
node.parserContextFlags |= ParserContextFlags.HasAggregatedChildData;
}
return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError);
}
export function getSourceFileOfNode(node: Node): SourceFile {