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

Adds .kind prop to AstNode. #799

Merged
merged 6 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmarks/targets/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = async (suite, name, brighterscript, projectPath, options) => {
cwd: projectPath,
createPackage: false,
copyToStaging: false,
enableTypeValidation: false,
//disable diagnostic reporting (they still get collected)
diagnosticFilters: ['**/*'],
logLevel: 'error'
Expand Down
239 changes: 120 additions & 119 deletions src/astUtils/reflection.ts

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/astUtils/visitors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-bitwise */
import type { CancellationToken } from 'vscode-languageserver';
import type { Body, AssignmentStatement, Block, ExpressionStatement, CommentStatement, ExitForStatement, ExitWhileStatement, FunctionStatement, IfStatement, IncrementStatement, PrintStatement, GotoStatement, LabelStatement, ReturnStatement, EndStatement, StopStatement, ForStatement, ForEachStatement, WhileStatement, DottedSetStatement, IndexedSetStatement, LibraryStatement, NamespaceStatement, ImportStatement, ClassStatement, ClassMethodStatement, ClassFieldStatement, EnumStatement, EnumMemberStatement, DimStatement, TryCatchStatement, CatchStatement, ThrowStatement, InterfaceStatement, InterfaceFieldStatement, InterfaceMethodStatement, FieldStatement, MethodStatement, ConstStatement, ContinueStatement } from '../parser/Statement';
import type { AALiteralExpression, AAMemberExpression, AnnotationExpression, ArrayLiteralExpression, BinaryExpression, CallExpression, CallfuncExpression, DottedGetExpression, EscapedCharCodeLiteralExpression, FunctionExpression, FunctionParameterExpression, GroupingExpression, IndexedGetExpression, LiteralExpression, NewExpression, NullCoalescingExpression, RegexLiteralExpression, SourceLiteralExpression, TaggedTemplateStringExpression, TemplateStringExpression, TemplateStringQuasiExpression, TernaryExpression, UnaryExpression, VariableExpression, XmlAttributeGetExpression } from '../parser/Expression';
import type { AALiteralExpression, AAMemberExpression, AnnotationExpression, ArrayLiteralExpression, BinaryExpression, CallExpression, CallfuncExpression, DottedGetExpression, EscapedCharCodeLiteralExpression, FunctionExpression, FunctionParameterExpression, GroupingExpression, IndexedGetExpression, LiteralExpression, NewExpression, NullCoalescingExpression, RegexLiteralExpression, SourceLiteralExpression, TaggedTemplateStringExpression, TemplateStringExpression, TemplateStringQuasiExpression, TernaryExpression, TypeCastExpression, TypeExpression, UnaryExpression, VariableExpression, XmlAttributeGetExpression } from '../parser/Expression';
import { isExpression, isStatement } from './reflection';
import type { AstEditor } from './AstEditor';
import type { Statement, Expression, AstNode } from '../parser/AstNode';
Expand Down Expand Up @@ -169,6 +169,8 @@ export function createVisitor(
TernaryExpression?: (expression: TernaryExpression, parent?: AstNode, owner?: any, key?: any) => Expression | void;
NullCoalescingExpression?: (expression: NullCoalescingExpression, parent?: AstNode, owner?: any, key?: any) => Expression | void;
RegexLiteralExpression?: (expression: RegexLiteralExpression, parent?: AstNode, owner?: any, key?: any) => Expression | void;
TypeExpression?: (expression: TypeExpression, parent?: AstNode, owner?: any, key?: any) => Expression | void;
TypeCastExpression?: (expression: TypeCastExpression, parent?: AstNode, owner?: any, key?: any) => Expression | void;
}
) {
//remap some deprecated visitor names TODO remove this in v1
Expand Down
8 changes: 4 additions & 4 deletions src/bscPlugin/CallExpressionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Expression } from '../parser/AstNode';
import type { CallExpression, CallfuncExpression, NewExpression } from '../parser/Expression';
import type { CallExpression, CallfuncExpression, NewExpression, VariableExpression } from '../parser/Expression';
import type { ClassStatement, NamespaceStatement } from '../parser/Statement';
import { isCallExpression, isCallfuncExpression, isVariableExpression, isDottedGetExpression, isClassStatement, isNewExpression } from '../astUtils/reflection';
import type { BrsFile } from '../files/BrsFile';
Expand Down Expand Up @@ -66,11 +66,11 @@ export class CallExpressionInfo {
this.newExpression = callExpression.parent;
}
if (isCallfuncExpression(callExpression)) {
this.name = callExpression.methodName.text;
this.name = (callExpression as CallfuncExpression).methodName.text;
} else if (isVariableExpression(callExpression.callee)) {
this.name = callExpression.callee.name.text;
} else if (isVariableExpression(callExpression)) {
this.name = callExpression.name.text;
this.name = (callExpression as VariableExpression).name.text;
} else if (isDottedGetExpression(callExpression.callee)) {
this.name = callExpression.callee.name.text;
if (isDottedGetExpression(callExpression.callee) && isVariableExpression(callExpression.callee.obj)) {
Expand Down Expand Up @@ -116,7 +116,7 @@ export class CallExpressionInfo {
}
}

return callExpression;
return callExpression as CallExpression;
}

ascertainType(): CallExpressionType {
Expand Down
2 changes: 1 addition & 1 deletion src/bscPlugin/validation/BrsFileValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ContinueStatement, EnumMemberStatement, EnumStatement, ForEachStat
import { SymbolTypeFlags } from '../../SymbolTable';
import type { BscType } from '../../types/BscType';
import { DynamicType } from '../../types/DynamicType';
import { NamespaceType } from '../../types/NameSpaceType';
import { NamespaceType } from '../../types/NamespaceType';
import util from '../../util';
import type { Range } from 'vscode-languageserver';

Expand Down
2 changes: 1 addition & 1 deletion src/globalCallables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ This function creates an roBitmap out of the background image file and returns a
isOptional: false
}]
}
] as Callable[];
] as unknown[] as Callable[];

export let globalCallables = [...mathFunctions, ...runtimeFunctions, ...globalUtilityFunctions, ...globalStringFunctions, ...programStatementFunctions];
for (let callable of globalCallables) {
Expand Down
73 changes: 73 additions & 0 deletions src/parser/AstNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { BscType } from '../types/BscType';
* A BrightScript AST node
*/
export abstract class AstNode {
public abstract kind: AstNodeKind;
/**
* The starting and ending location of the node.
*/
Expand Down Expand Up @@ -146,3 +147,75 @@ export abstract class Expression extends AstNode {
*/
public visitMode = InternalWalkMode.visitExpressions;
}

export enum AstNodeKind {
Body = 'Body',
BinaryExpression = 'BinaryExpression',
CallExpression = 'CallExpression',
FunctionExpression = 'FunctionExpression',
FunctionParameterExpression = 'FunctionParameterExpression',
NamespacedVariableNameExpression = 'NamespacedVariableNameExpression',
DottedGetExpression = 'DottedGetExpression',
XmlAttributeGetExpression = 'XmlAttributeGetExpression',
IndexedGetExpression = 'IndexedGetExpression',
GroupingExpression = 'GroupingExpression',
LiteralExpression = 'LiteralExpression',
EscapedCharCodeLiteralExpression = 'EscapedCharCodeLiteralExpression',
ArrayLiteralExpression = 'ArrayLiteralExpression',
AAMemberExpression = 'AAMemberExpression',
AALiteralExpression = 'AALiteralExpression',
UnaryExpression = 'UnaryExpression',
VariableExpression = 'VariableExpression',
SourceLiteralExpression = 'SourceLiteralExpression',
NewExpression = 'NewExpression',
CallfuncExpression = 'CallfuncExpression',
TemplateStringQuasiExpression = 'TemplateStringQuasiExpression',
TemplateStringExpression = 'TemplateStringExpression',
TaggedTemplateStringExpression = 'TaggedTemplateStringExpression',
AnnotationExpression = 'AnnotationExpression',
TernaryExpression = 'TernaryExpression',
NullCoalescingExpression = 'NullCoalescingExpression',
RegexLiteralExpression = 'RegexLiteralExpression',
EmptyStatement = 'EmptyStatement',
AssignmentStatement = 'AssignmentStatement',
ExpressionStatement = 'ExpressionStatement',
CommentStatement = 'CommentStatement',
ExitForStatement = 'ExitForStatement',
ExitWhileStatement = 'ExitWhileStatement',
FunctionStatement = 'FunctionStatement',
IfStatement = 'IfStatement',
IncrementStatement = 'IncrementStatement',
PrintStatement = 'PrintStatement',
DimStatement = 'DimStatement',
GotoStatement = 'GotoStatement',
LabelStatement = 'LabelStatement',
ReturnStatement = 'ReturnStatement',
EndStatement = 'EndStatement',
StopStatement = 'StopStatement',
ForStatement = 'ForStatement',
ForEachStatement = 'ForEachStatement',
WhileStatement = 'WhileStatement',
DottedSetStatement = 'DottedSetStatement',
IndexedSetStatement = 'IndexedSetStatement',
LibraryStatement = 'LibraryStatement',
NamespaceStatement = 'NamespaceStatement',
ImportStatement = 'ImportStatement',
InterfaceStatement = 'InterfaceStatement',
InterfaceFieldStatement = 'InterfaceFieldStatement',
InterfaceMethodStatement = 'InterfaceMethodStatement',
ClassStatement = 'ClassStatement',
MethodStatement = 'MethodStatement',
ClassMethodStatement = 'ClassMethodStatement',
FieldStatement = 'FieldStatement',
ClassFieldStatement = 'ClassFieldStatement',
TryCatchStatement = 'TryCatchStatement',
CatchStatement = 'CatchStatement',
ThrowStatement = 'ThrowStatement',
EnumStatement = 'EnumStatement',
EnumMemberStatement = 'EnumMemberStatement',
ConstStatement = 'ConstStatement',
ContinueStatement = 'ContinueStatement',
Block = 'Block',
TypeExpression = 'TypeExpression',
TypeCastExpression = 'TypeCastExpression'
}