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

Remove FunctionScope and improve type tracking #258

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a24b93f
Add `for each` variable to completions
TwitchBronBron Dec 18, 2020
e4d01fa
ForEachStatement's `item` is now VaribleExpression
TwitchBronBron Dec 18, 2020
fc2100f
Fix ts build issue.
TwitchBronBron Dec 18, 2020
04d7b72
fix broken tests
TwitchBronBron Dec 18, 2020
91a7d21
Merge branch 'master' into for-each-var-completions
TwitchBronBron Dec 19, 2020
0e4589e
fix broken test.
TwitchBronBron Dec 19, 2020
948400c
Collection function variables in _references
TwitchBronBron Dec 19, 2020
4aa2f0d
Removed FunctionScope in favor of func expressions
TwitchBronBron Dec 21, 2020
2ab29ef
Merge branch 'master' into for-each-var-completions
TwitchBronBron Jan 13, 2021
62a6103
Merge branch 'master' of https://github.com/rokucommunity/brighterscr…
TwitchBronBron Jan 13, 2021
ea4f72e
lint and interface fixes
TwitchBronBron Jan 13, 2021
5613304
Repopulate `references.localVars` during `findReferences`
TwitchBronBron Jan 13, 2021
b1a93ce
Merge branch 'master' into for-each-var-completions
TwitchBronBron Jan 15, 2021
f916694
Handle sub with explicit return type
TwitchBronBron Jan 15, 2021
73c432c
Fix `findReferences` for local vars
TwitchBronBron Jan 15, 2021
03c99a8
Merge branch 'master' into for-each-var-completions
TwitchBronBron Jan 30, 2021
f2dc8f0
Merge branch 'master' into for-each-var-completions
TwitchBronBron Jan 30, 2021
b47b3a5
Normalize line endings for Scope.ts
TwitchBronBron Jan 30, 2021
eb6dad6
Merge branch 'master' into for-each-var-completions
TwitchBronBron Mar 16, 2021
c2a825b
Merge branch 'master' of https://github.com/rokucommunity/brighterscr…
TwitchBronBron Mar 16, 2021
54c356f
Merge branch 'master' into for-each-var-completions
TwitchBronBron Mar 16, 2021
60284a4
Merge branch 'master' of https://github.com/rokucommunity/brighterscr…
TwitchBronBron Mar 30, 2021
8fe2bf7
Feature/symbol table (#380)
markwpearce Apr 1, 2021
65c0d92
Feature/scope tracked symbol tables (#395)
markwpearce Apr 23, 2021
db329b0
Merge branch 'master' of https://github.com/rokucommunity/brighterscr…
TwitchBronBron Apr 23, 2021
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
28 changes: 28 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,34 @@ describe('Program', () => {
});

describe('getCompletions', () => {
it('includes `for each` variable', async () => {
await program.addOrReplaceFile('source/main.brs', `
sub main()
items = [1, 2, 3]
for each thing in items
t =
end for
end for
end sub
`);
await program.validate();
let completions = (await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(4, 28))).map(x => x.label);
expect(completions).to.include('thing');
});

it('includes `for` variable', async () => {
await program.addOrReplaceFile('source/main.brs', `
sub main()
for i = 0 to 10
t =
end for
end sub
`);
await program.validate();
let completions = (await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(3, 28))).map(x => x.label);
expect(completions).to.include('i');
});

it('should include first-level namespace names for brighterscript files', async () => {
await program.addOrReplaceFile('source/main.bs', `
namespace NameA.NameB.NameC
Expand Down
14 changes: 14 additions & 0 deletions src/files/BrsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,20 @@ export class BrsFile {
});
}

//add every loop-defined variable
func.body.walk(createVisitor({
TwitchBronBron marked this conversation as resolved.
Show resolved Hide resolved
ForEachStatement: (stmt) => {
scope.variableDeclarations.push({
nameRange: stmt.item.range,
lineIndex: stmt.item.range.start.line,
name: stmt.item.name.text,
type: new DynamicType()
});
}
}), {
walkMode: WalkMode.visitStatements
});

this.scopesByFunc.set(func, scope);

//find every statement in the scope
Expand Down
2 changes: 1 addition & 1 deletion src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ export class Parser {
in: maybeIn,
endFor: endFor
},
name,
new VariableExpression(name as Identifier, this.currentNamespaceName),
target,
body
);
Expand Down
5 changes: 3 additions & 2 deletions src/parser/Statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ export class ForEachStatement extends Statement {
in: Token;
endFor: Token;
},
readonly item: Token,
readonly item: VariableExpression,
readonly target: Expression,
readonly body: Block
) {
Expand All @@ -825,7 +825,7 @@ export class ForEachStatement extends Statement {
);
//item
result.push(
new SourceNode(this.tokens.forEach.range.start.line + 1, this.tokens.forEach.range.start.character, state.pathAbsolute, this.item.text),
...this.item.transpile(state),
' '
);
//in
Expand All @@ -852,6 +852,7 @@ export class ForEachStatement extends Statement {

walk(visitor: WalkVisitor, options: WalkOptions) {
if (options.walkMode & InternalWalkMode.walkExpressions) {
walk(this, 'item', visitor, options);
TwitchBronBron marked this conversation as resolved.
Show resolved Hide resolved
walk(this, 'target', visitor, options);
}
if (options.walkMode & InternalWalkMode.walkStatements) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/tests/controlFlow/ForEach.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('parser foreach loops', () => {
let forEach = statements[0] as any;
expect(forEach).to.be.instanceof(ForEachStatement);

expect(forEach.item).to.deep.include(identifier('word'));
expect(forEach.item.name.text).to.eql('word');
expect(forEach.target).to.be.instanceof(VariableExpression);
expect(forEach.target.name).to.deep.include(identifier('lipsum'));
});
Expand Down