Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ast): Rename location to loc in AST #664

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Location } from "./lexer";

export class BrsError extends Error {
constructor(message: string, readonly location: Location) {
constructor(message: string, readonly loc: Location) {
super(message);
}

Expand All @@ -13,7 +13,7 @@ export class BrsError extends Error {
* @see BrsError#format
*/
format() {
return BrsError.format(this.message, this.location);
return BrsError.format(this.message, this.loc);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/coverage/CoverageCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export class CoverageCollector {
let statements = await this.parseFn(scripts);

statements.forEach((statement) => {
let file = this.files.get(statement.location.file);
let file = this.files.get(statement.loc.file);
if (file) {
file.execute(statement);
}
});
}

logHit(statement: Expr.Expression | Stmt.Statement) {
let file = this.files.get(statement.location.file);
let file = this.files.get(statement.loc.file);
if (file) {
file.logHit(statement);
}
Expand Down
59 changes: 29 additions & 30 deletions src/coverage/FileCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
* @param statement statement for which to generate a key.
*/
getStatementKey(statement: Expr.Expression | Stmt.Statement) {
let { start, end } = statement.location;
let { start, end } = statement.loc;
let kind = isStatement(statement) ? "stmt" : "expr";
return `${kind}:${statement.type}:${start.line},${start.column}-${end.line},${end.column}`;
}
Expand Down Expand Up @@ -80,16 +80,16 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
let thenBranchCoverage = this.get(statement.thenBranch);
if (thenBranchCoverage) {
locations.push({
...statement.location,
end: statement.condition.location.end,
...statement.loc,
end: statement.condition.loc.end,
});
branchHits.push(thenBranchCoverage.hits);
}

// the condition is a statement as well as a branch, so put it in the statement map
let ifCondition = this.get(statement.condition);
if (ifCondition) {
coverageSummary.statementMap[`${key}.if`] = statement.condition.location;
coverageSummary.statementMap[`${key}.if`] = statement.condition.loc;
coverageSummary.s[`${key}.if`] = ifCondition.hits;
}

Expand All @@ -99,17 +99,17 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
if (elseIfCoverage) {
// the condition is a statement as well as a branch, so put it in the statement map
coverageSummary.statementMap[`${key}.elseif-${index}`] =
branch.condition.location;
branch.condition.loc;
coverageSummary.s[`${key}.elseif-${index}`] = elseIfCoverage.hits;

// add to the list of branches
let elseIfBlock = this.get(branch.thenBranch);
if (elseIfBlock) {
// use the tokens as the start for the branch rather than the condition
let start =
statement.tokens.elseIfs?.[index].location.start ||
branch.condition.location.start;
locations.push({ ...branch.condition.location, start });
statement.tokens.elseIfs?.[index].loc.start ||
branch.condition.loc.start;
locations.push({ ...branch.condition.loc, start });
branchHits.push(elseIfBlock.hits);
}
}
Expand All @@ -121,18 +121,17 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
if (elseCoverage) {
// use the tokens as the start rather than the condition
let start =
statement.tokens.else?.location.start ||
statement.elseBranch.location.start;
locations.push({ ...statement.elseBranch.location, start });
statement.tokens.else?.loc.start || statement.elseBranch.loc.start;
locations.push({ ...statement.elseBranch.loc, start });
branchHits.push(elseCoverage.hits);
}
}

coverageSummary.branchMap[key] = {
loc: statement.location,
loc: statement.loc,
type: "if",
locations,
line: statement.location.start.line,
line: statement.loc.start.line,
};
coverageSummary.b[key] = branchHits;
} else if (statement instanceof Stmt.Function) {
Expand All @@ -141,12 +140,12 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
if (functionCoverage) {
coverageSummary.fnMap[key] = {
name: statement.name.text,
loc: statement.location,
loc: statement.loc,
decl: {
...statement.func.keyword.location,
end: statement.name.location.end,
...statement.func.keyword.loc,
end: statement.name.loc.end,
},
line: statement.location.start.line,
line: statement.loc.start.line,
};
coverageSummary.f[key] = functionCoverage.hits;
}
Expand All @@ -156,9 +155,9 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
if (functionCoverage) {
coverageSummary.fnMap[key] = {
name: "[Function]",
loc: statement.location,
decl: statement.keyword.location,
line: statement.location.start.line,
loc: statement.loc,
decl: statement.keyword.loc,
line: statement.loc.start.line,
};
coverageSummary.f[key] = functionCoverage.hits;
}
Expand All @@ -171,31 +170,31 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType

let leftCoverage = this.get(statement.left);
if (leftCoverage) {
locations.push(statement.left.location);
locations.push(statement.left.loc);
branchHits.push(leftCoverage.hits);
}
let rightCoverage = this.get(statement.right);
if (rightCoverage) {
locations.push(statement.right.location);
locations.push(statement.right.loc);
branchHits.push(rightCoverage.hits);
}

coverageSummary.branchMap[key] = {
loc: statement.location,
loc: statement.loc,
type: statement.token.kind,
locations,
line: statement.location.start.line,
line: statement.loc.start.line,
};
coverageSummary.b[key] = branchHits;

// this is a statement as well as a branch, so put it in the statement map
coverageSummary.statementMap[key] = statement.location;
coverageSummary.statementMap[key] = statement.loc;
coverageSummary.s[key] = hits;
} else if (
isStatement(statement) &&
!(statement instanceof Stmt.Block) // blocks are part of other statements, so don't include them
) {
coverageSummary.statementMap[key] = statement.location;
coverageSummary.statementMap[key] = statement.loc;
coverageSummary.s[key] = hits;
}
});
Expand All @@ -218,11 +217,11 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType
}

visitExitFor(statement: Stmt.ExitFor): never {
throw new Stmt.ExitForReason(statement.location);
throw new Stmt.ExitForReason(statement.loc);
}

visitExitWhile(statement: Stmt.ExitWhile): never {
throw new Stmt.ExitWhileReason(statement.location);
throw new Stmt.ExitWhileReason(statement.loc);
}

visitPrint(statement: Stmt.Print) {
Expand Down Expand Up @@ -287,11 +286,11 @@ export class FileCoverage implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType

visitReturn(statement: Stmt.Return): never {
if (!statement.value) {
throw new Stmt.ReturnValue(statement.tokens.return.location);
throw new Stmt.ReturnValue(statement.tokens.return.loc);
}

let toReturn = this.evaluate(statement.value);
throw new Stmt.ReturnValue(statement.tokens.return.location, toReturn);
throw new Stmt.ReturnValue(statement.tokens.return.loc, toReturn);
}

visitDottedSet(statement: Stmt.DottedSet) {
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Environment {

// the special "LINE_NUM" variable always resolves to the line number on which it appears
if (lowercaseName === "line_num") {
return new Int32(name.location.start.line);
return new Int32(name.loc.start.line);
}

// "m" always maps to the special `m` pointer
Expand Down
Loading