From 0df04229dc323fe97a37817f16c74566c7c1b225 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Wed, 7 Jun 2023 16:01:35 -0400 Subject: [PATCH] Rename SymbolTypeFlags to SymbolTypeFlag (#819) --- src/Program.ts | 24 +++---- src/Scope.spec.ts | 54 ++++++++-------- src/SymbolTable.spec.ts | 62 +++++++++---------- src/SymbolTable.ts | 16 ++--- .../BrsFileSemanticTokensProcessor.ts | 4 +- src/bscPlugin/validation/BrsFileValidator.ts | 52 ++++++++-------- src/bscPlugin/validation/ScopeValidator.ts | 10 +-- src/files/BrsFile.ts | 14 ++--- src/globalCallables.ts | 4 +- src/interfaces.ts | 4 +- src/parser/Expression.ts | 14 ++--- src/parser/Parser.Class.spec.ts | 4 +- src/parser/Parser.spec.ts | 10 +-- src/parser/Statement.ts | 18 +++--- .../tests/expression/TypeExpression.spec.ts | 18 +++--- src/types/BscType.ts | 6 +- src/types/ClassType.spec.ts | 22 +++---- src/types/InheritableType.ts | 4 +- src/types/InterfaceType.spec.ts | 4 +- src/types/InterfaceType.ts | 4 +- src/types/ObjectType.ts | 4 +- src/types/ReferenceType.spec.ts | 40 ++++++------ src/types/ReferenceType.ts | 6 +- src/types/UnionType.spec.ts | 56 ++++++++--------- src/types/helper.spec.ts | 10 +-- src/util.spec.ts | 4 +- src/validators/ClassValidator.ts | 8 +-- 27 files changed, 238 insertions(+), 238 deletions(-) diff --git a/src/Program.ts b/src/Program.ts index f69f4bdb9..786bd6e4d 100644 --- a/src/Program.ts +++ b/src/Program.ts @@ -31,7 +31,7 @@ import { SignatureHelpUtil } from './bscPlugin/SignatureHelpUtil'; import { DiagnosticSeverityAdjuster } from './DiagnosticSeverityAdjuster'; import { IntegerType } from './types/IntegerType'; import { StringType } from './types/StringType'; -import { SymbolTable, SymbolTypeFlags } from './SymbolTable'; +import { SymbolTable, SymbolTypeFlag } from './SymbolTable'; import { BooleanType } from './types/BooleanType'; import { DoubleType } from './types/DoubleType'; import { DynamicType } from './types/DynamicType'; @@ -124,20 +124,20 @@ export class Program { //Setup primitive types in global symbolTable //TODO: Need to handle Array types - this.globalScope.symbolTable.addSymbol('boolean', undefined, BooleanType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('double', undefined, DoubleType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('dynamic', undefined, DynamicType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('float', undefined, FloatType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('function', undefined, new FunctionType(DynamicType.instance), SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('integer', undefined, IntegerType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('longinteger', undefined, LongIntegerType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('object', undefined, new ObjectType(), SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('string', undefined, StringType.instance, SymbolTypeFlags.typetime); - this.globalScope.symbolTable.addSymbol('void', undefined, VoidType.instance, SymbolTypeFlags.typetime); + this.globalScope.symbolTable.addSymbol('boolean', undefined, BooleanType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('double', undefined, DoubleType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('dynamic', undefined, DynamicType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('float', undefined, FloatType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('function', undefined, new FunctionType(DynamicType.instance), SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('integer', undefined, IntegerType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('longinteger', undefined, LongIntegerType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('object', undefined, new ObjectType(), SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('string', undefined, StringType.instance, SymbolTypeFlag.typetime); + this.globalScope.symbolTable.addSymbol('void', undefined, VoidType.instance, SymbolTypeFlag.typetime); for (let pair of globalCallableMap) { let [key, callable] = pair; - this.globalScope.symbolTable.addSymbol(key, undefined, callable.type, SymbolTypeFlags.runtime); + this.globalScope.symbolTable.addSymbol(key, undefined, callable.type, SymbolTypeFlag.runtime); } } diff --git a/src/Scope.spec.ts b/src/Scope.spec.ts index 696a05c00..7f554167d 100644 --- a/src/Scope.spec.ts +++ b/src/Scope.spec.ts @@ -11,7 +11,7 @@ import { Logger } from './Logger'; import type { BrsFile } from './files/BrsFile'; import type { FunctionStatement, NamespaceStatement } from './parser/Statement'; import type { OnScopeValidateEvent } from './interfaces'; -import { SymbolTypeFlags } from './SymbolTable'; +import { SymbolTypeFlag } from './SymbolTable'; import { EnumMemberType } from './types/EnumType'; import { ClassType } from './types/ClassType'; import { BooleanType } from './types/BooleanType'; @@ -82,15 +82,15 @@ describe('Scope', () => { //the symbol table should contain the relative names for all items in this namespace across the entire scope expect( // eslint-disable-next-line no-bitwise - symbolTable.hasSymbol('Beta', SymbolTypeFlags.runtime | SymbolTypeFlags.typetime) + symbolTable.hasSymbol('Beta', SymbolTypeFlag.runtime | SymbolTypeFlag.typetime) ).to.be.true; expect( // eslint-disable-next-line no-bitwise - symbolTable.hasSymbol('Charlie', SymbolTypeFlags.runtime | SymbolTypeFlags.typetime) + symbolTable.hasSymbol('Charlie', SymbolTypeFlag.runtime | SymbolTypeFlag.typetime) ).to.be.true; expect( // eslint-disable-next-line no-bitwise - symbolTable.hasSymbol('createBeta', SymbolTypeFlags.runtime) + symbolTable.hasSymbol('createBeta', SymbolTypeFlag.runtime) ).to.be.true; expectZeroDiagnostics(program); @@ -2186,9 +2186,9 @@ describe('Scope', () => { expect(mainFnScope).to.exist; sourceScope.linkSymbolTable(); const mainSymbolTable = mainFnScope.symbolTable; - expectTypeToBe(mainSymbolTable.getSymbol('fooInstance', SymbolTypeFlags.runtime)[0].type, ClassType); - expect(mainSymbolTable.getSymbol('fooInstance', SymbolTypeFlags.runtime)[0].type.toString()).to.eq('Foo'); - let myNumType = mainSymbolTable.getSymbolType('myNum', { flags: SymbolTypeFlags.runtime }); + expectTypeToBe(mainSymbolTable.getSymbol('fooInstance', SymbolTypeFlag.runtime)[0].type, ClassType); + expect(mainSymbolTable.getSymbol('fooInstance', SymbolTypeFlag.runtime)[0].type.toString()).to.eq('Foo'); + let myNumType = mainSymbolTable.getSymbolType('myNum', { flags: SymbolTypeFlag.runtime }); expectTypeToBe(myNumType, IntegerType); }); @@ -2211,7 +2211,7 @@ describe('Scope', () => { expect(sourceScope).to.exist; expect(mainFnScope).to.exist; sourceScope.linkSymbolTable(); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('paintColor', SymbolTypeFlags.runtime)[0].type, EnumMemberType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('paintColor', SymbolTypeFlag.runtime)[0].type, EnumMemberType); }); it('finds correct class field type with default value enums are used', () => { @@ -2239,7 +2239,7 @@ describe('Scope', () => { expect(mainFnScope).to.exist; //sourceScope.linkSymbolTable(); let mainScopeSymbolTable = mainFnScope.symbolTable; - let paintType = mainScopeSymbolTable.getSymbolType('paintColor', { flags: SymbolTypeFlags.runtime }); + let paintType = mainScopeSymbolTable.getSymbolType('paintColor', { flags: SymbolTypeFlag.runtime }); expectTypeToBe(paintType, EnumMemberType); }); @@ -2254,15 +2254,15 @@ describe('Scope', () => { expect(sourceScope).to.exist; sourceScope.linkSymbolTable(); expect(mainFnScope).to.exist; - expectTypeToBe(mainFnScope.symbolTable.getSymbol('skin', SymbolTypeFlags.runtime)[0].type, EnumMemberType); - - expectTypeToBe(mainFnScope.symbolTable.getSymbol('flyBoy', SymbolTypeFlags.runtime)[0].type, ClassType); - expect(mainFnScope.symbolTable.getSymbol('flyBoy', SymbolTypeFlags.runtime)[0].type.toString()).to.eq('Animals.Bird'); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('flyBoysWings', SymbolTypeFlags.runtime)[0].type, BooleanType); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('flyBoysSkin', SymbolTypeFlags.runtime)[0].type, EnumMemberType); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('fido', SymbolTypeFlags.runtime)[0].type, ClassType); - expect(mainFnScope.symbolTable.getSymbol('fido', SymbolTypeFlags.runtime)[0].type.toString()).to.eq('Animals.Dog'); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('fidoBark', SymbolTypeFlags.runtime)[0].type, StringType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('skin', SymbolTypeFlag.runtime)[0].type, EnumMemberType); + + expectTypeToBe(mainFnScope.symbolTable.getSymbol('flyBoy', SymbolTypeFlag.runtime)[0].type, ClassType); + expect(mainFnScope.symbolTable.getSymbol('flyBoy', SymbolTypeFlag.runtime)[0].type.toString()).to.eq('Animals.Bird'); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('flyBoysWings', SymbolTypeFlag.runtime)[0].type, BooleanType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('flyBoysSkin', SymbolTypeFlag.runtime)[0].type, EnumMemberType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('fido', SymbolTypeFlag.runtime)[0].type, ClassType); + expect(mainFnScope.symbolTable.getSymbol('fido', SymbolTypeFlag.runtime)[0].type.toString()).to.eq('Animals.Dog'); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('fidoBark', SymbolTypeFlag.runtime)[0].type, StringType); }); it('finds correct type for members of classes with super classes', () => { @@ -2275,12 +2275,12 @@ describe('Scope', () => { expect(sourceScope).to.exist; sourceScope.linkSymbolTable(); expect(mainFnScope).to.exist; - const chimpType = mainFnScope.symbolTable.getSymbol('chimp', SymbolTypeFlags.runtime)[0].type; + const chimpType = mainFnScope.symbolTable.getSymbol('chimp', SymbolTypeFlag.runtime)[0].type; expectTypeToBe(chimpType, ClassType); expectTypeToBe((chimpType as ClassType).superClass, ClassType); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('chimpHasLegs', SymbolTypeFlags.runtime)[0].type, BooleanType); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('chimpSpeed', SymbolTypeFlags.runtime)[0].type, IntegerType); - expectTypeToBe(mainFnScope.symbolTable.getSymbol('fidoSpeed', SymbolTypeFlags.runtime)[0].type, IntegerType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('chimpHasLegs', SymbolTypeFlag.runtime)[0].type, BooleanType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('chimpSpeed', SymbolTypeFlag.runtime)[0].type, IntegerType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('fidoSpeed', SymbolTypeFlag.runtime)[0].type, IntegerType); }); it('finds correct types for method calls', () => { @@ -2308,7 +2308,7 @@ describe('Scope', () => { expect(sourceScope).to.exist; sourceScope.linkSymbolTable(); expect(mainFnScope).to.exist; - expectTypeToBe(mainFnScope.symbolTable.getSymbol('myVal', SymbolTypeFlags.runtime)[0].type, IntegerType); + expectTypeToBe(mainFnScope.symbolTable.getSymbol('myVal', SymbolTypeFlag.runtime)[0].type, IntegerType); }); it('finds correct types for self-referencing variables', () => { @@ -2326,7 +2326,7 @@ describe('Scope', () => { expect(sourceScope).to.exist; sourceScope.linkSymbolTable(); expect(mainFnScope).to.exist; - const getTypeOptions = { flags: SymbolTypeFlags.runtime }; + const getTypeOptions = { flags: SymbolTypeFlag.runtime }; let dtType = mainFnScope.symbolTable.getSymbolType('dt', getTypeOptions); expectTypeToBe(dtType, ObjectType); let hoursType = mainFnScope.symbolTable.getSymbolType('hours', getTypeOptions); @@ -2360,7 +2360,7 @@ describe('Scope', () => { sourceScope.linkSymbolTable(); expect(mainFnScope).to.exist; const mainSymbolTable = mainFnScope.symbolTable; - expectTypeToBe(mainSymbolTable.getSymbolType('name', { flags: SymbolTypeFlags.runtime }), StringType); + expectTypeToBe(mainSymbolTable.getSymbolType('name', { flags: SymbolTypeFlag.runtime }), StringType); }); it('should have an error when a non union member is accessed', () => { @@ -2405,7 +2405,7 @@ describe('Scope', () => { const sourceScope = program.getScopeByName('source'); sourceScope.linkSymbolTable(); let mainSymbolTable = mainFnScope.symbolTable; - expectTypeToBe(mainSymbolTable.getSymbol('value', SymbolTypeFlags.runtime)[0].type, FloatType); + expectTypeToBe(mainSymbolTable.getSymbol('value', SymbolTypeFlag.runtime)[0].type, FloatType); }); @@ -2425,7 +2425,7 @@ describe('Scope', () => { const sourceScope = program.getScopeByName('source'); sourceScope.linkSymbolTable(); let mainSymbolTable = mainFnScope.symbolTable; - expectTypeToBe(mainSymbolTable.getSymbol('value', SymbolTypeFlags.runtime)[0].type, StringType); + expectTypeToBe(mainSymbolTable.getSymbol('value', SymbolTypeFlag.runtime)[0].type, StringType); }); }); }); diff --git a/src/SymbolTable.spec.ts b/src/SymbolTable.spec.ts index 52e3ba800..e4433bdcc 100644 --- a/src/SymbolTable.spec.ts +++ b/src/SymbolTable.spec.ts @@ -3,7 +3,7 @@ import { expect } from './chai-config.spec'; import { StringType } from './types/StringType'; import { IntegerType } from './types/IntegerType'; import { BooleanType } from './types/BooleanType'; -import { SymbolTypeFlags } from './SymbolTable'; +import { SymbolTypeFlag } from './SymbolTable'; describe('SymbolTable', () => { let parent: SymbolTable; @@ -14,76 +14,76 @@ describe('SymbolTable', () => { it('is case insensitive', () => { const st = new SymbolTable('Child'); - st.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); - expect(st.getSymbol('FOO', SymbolTypeFlags.runtime).length).eq(1); - expect(st.getSymbol('FOO', SymbolTypeFlags.runtime)[0].type.toString()).eq('string'); + st.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); + expect(st.getSymbol('FOO', SymbolTypeFlag.runtime).length).eq(1); + expect(st.getSymbol('FOO', SymbolTypeFlag.runtime)[0].type.toString()).eq('string'); }); it('stores all previous symbols', () => { const st = new SymbolTable('Child'); - st.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); - st.addSymbol('foo', null, new IntegerType(), SymbolTypeFlags.runtime); - expect(st.getSymbol('FOO', SymbolTypeFlags.runtime).length).eq(2); + st.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); + st.addSymbol('foo', null, new IntegerType(), SymbolTypeFlag.runtime); + expect(st.getSymbol('FOO', SymbolTypeFlag.runtime).length).eq(2); }); it('reads from parent symbol table if not found in current', () => { const st = new SymbolTable('Child', () => parent); - parent.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); - expect(st.getSymbol('foo', SymbolTypeFlags.runtime)[0].type.toString()).eq('string'); + parent.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); + expect(st.getSymbol('foo', SymbolTypeFlag.runtime)[0].type.toString()).eq('string'); }); it('reads from current table if it exists', () => { const st = new SymbolTable('Child', () => parent); - parent.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); - st.addSymbol('foo', null, new IntegerType(), SymbolTypeFlags.runtime); - expect(st.getSymbol('foo', SymbolTypeFlags.runtime)[0].type.toString()).eq('integer'); + parent.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); + st.addSymbol('foo', null, new IntegerType(), SymbolTypeFlag.runtime); + expect(st.getSymbol('foo', SymbolTypeFlag.runtime)[0].type.toString()).eq('integer'); }); it('correct checks if a symbol is in the table using hasSymbol', () => { const child = new SymbolTable('Child', () => parent); - parent.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); - child.addSymbol('bar', null, new IntegerType(), SymbolTypeFlags.runtime); - expect(parent.hasSymbol('foo', SymbolTypeFlags.runtime)).to.be.true; - expect(parent.hasSymbol('bar', SymbolTypeFlags.runtime)).to.be.false; - expect(child.hasSymbol('foo', SymbolTypeFlags.runtime)).to.be.true; - expect(child.hasSymbol('bar', SymbolTypeFlags.runtime)).to.be.true; - expect(child.hasSymbol('buz', SymbolTypeFlags.runtime)).to.be.false; + parent.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); + child.addSymbol('bar', null, new IntegerType(), SymbolTypeFlag.runtime); + expect(parent.hasSymbol('foo', SymbolTypeFlag.runtime)).to.be.true; + expect(parent.hasSymbol('bar', SymbolTypeFlag.runtime)).to.be.false; + expect(child.hasSymbol('foo', SymbolTypeFlag.runtime)).to.be.true; + expect(child.hasSymbol('bar', SymbolTypeFlag.runtime)).to.be.true; + expect(child.hasSymbol('buz', SymbolTypeFlag.runtime)).to.be.false; }); it('matches bitflags given', () => { const table = new SymbolTable('Child', () => parent); - table.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); - table.addSymbol('bar', null, new IntegerType(), SymbolTypeFlags.typetime); - expect(table.hasSymbol('foo', SymbolTypeFlags.runtime)).to.be.true; - expect(table.hasSymbol('bar', SymbolTypeFlags.runtime)).to.be.false; - expect(table.hasSymbol('foo', SymbolTypeFlags.typetime)).to.be.false; - expect(table.hasSymbol('bar', SymbolTypeFlags.typetime)).to.be.true; + table.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); + table.addSymbol('bar', null, new IntegerType(), SymbolTypeFlag.typetime); + expect(table.hasSymbol('foo', SymbolTypeFlag.runtime)).to.be.true; + expect(table.hasSymbol('bar', SymbolTypeFlag.runtime)).to.be.false; + expect(table.hasSymbol('foo', SymbolTypeFlag.typetime)).to.be.false; + expect(table.hasSymbol('bar', SymbolTypeFlag.typetime)).to.be.true; }); describe('mergeSymbolTable', () => { it('adds each symbol to the table', () => { const st = new SymbolTable('Child'); - st.addSymbol('foo', null, new StringType(), SymbolTypeFlags.runtime); + st.addSymbol('foo', null, new StringType(), SymbolTypeFlag.runtime); const otherTable = new SymbolTable('OtherTable'); - otherTable.addSymbol('bar', null, new IntegerType(), SymbolTypeFlags.runtime); - otherTable.addSymbol('foo', null, new IntegerType(), SymbolTypeFlags.runtime); + otherTable.addSymbol('bar', null, new IntegerType(), SymbolTypeFlag.runtime); + otherTable.addSymbol('foo', null, new IntegerType(), SymbolTypeFlag.runtime); st.mergeSymbolTable(otherTable); }); }); it('searches siblings before parents', () => { - parent.addSymbol('alpha', null, new StringType(), SymbolTypeFlags.runtime); + parent.addSymbol('alpha', null, new StringType(), SymbolTypeFlag.runtime); const child = new SymbolTable('Child', () => parent); const sibling = new SymbolTable('Sibling'); child.addSibling(sibling); - sibling.addSymbol('alpha', null, new BooleanType(), SymbolTypeFlags.runtime); + sibling.addSymbol('alpha', null, new BooleanType(), SymbolTypeFlag.runtime); expect( - child.getSymbol('alpha', SymbolTypeFlags.runtime).map(x => x.type.toTypeString()) + child.getSymbol('alpha', SymbolTypeFlag.runtime).map(x => x.type.toTypeString()) ).to.eql([ 'boolean' ]); diff --git a/src/SymbolTable.ts b/src/SymbolTable.ts index fdebb5ba1..7ef604f20 100644 --- a/src/SymbolTable.ts +++ b/src/SymbolTable.ts @@ -7,7 +7,7 @@ import type { UnionType } from './types/UnionType'; import { getUniqueType } from './types/helpers'; import { isReferenceType } from './astUtils/reflection'; -export enum SymbolTypeFlags { +export enum SymbolTypeFlag { runtime = 1, typetime = 2 } @@ -42,7 +42,7 @@ export class SymbolTable implements SymbolTypeGetter { static cacheVerifier: CacheVerifier; - static ReferenceTypeFactory: (memberKey: string, fullName, flags: SymbolTypeFlags, tableProvider: SymbolTypeGetterProvider) => ReferenceType; + static ReferenceTypeFactory: (memberKey: string, fullName, flags: SymbolTypeFlag, tableProvider: SymbolTypeGetterProvider) => ReferenceType; static UnionTypeFactory: (types: BscType[]) => UnionType; @@ -91,7 +91,7 @@ export class SymbolTable implements SymbolTypeGetter { * @param bitFlags flags to match (See SymbolTypeFlags) * @returns true if this symbol is in the symbol table */ - hasSymbol(name: string, bitFlags: SymbolTypeFlags): boolean { + hasSymbol(name: string, bitFlags: SymbolTypeFlag): boolean { let currentTable: SymbolTable = this; const key = name?.toLowerCase(); let result: BscSymbol[]; @@ -126,7 +126,7 @@ export class SymbolTable implements SymbolTypeGetter { * @param bitFlags flags to match * @returns An array of BscSymbols - one for each time this symbol had a type implicitly defined */ - getSymbol(name: string, bitFlags: SymbolTypeFlags): BscSymbol[] { + getSymbol(name: string, bitFlags: SymbolTypeFlag): BscSymbol[] { let currentTable: SymbolTable = this; const key = name?.toLowerCase(); let result: BscSymbol[]; @@ -156,7 +156,7 @@ export class SymbolTable implements SymbolTypeGetter { /** * Adds a new symbol to the table */ - addSymbol(name: string, range: Range, type: BscType, bitFlags: SymbolTypeFlags) { + addSymbol(name: string, range: Range, type: BscType, bitFlags: SymbolTypeFlag) { const key = name.toLowerCase(); if (!this.symbolMap.has(key)) { this.symbolMap.set(key, []); @@ -169,7 +169,7 @@ export class SymbolTable implements SymbolTypeGetter { }); } - getSymbolTypes(name: string, bitFlags: SymbolTypeFlags): BscType[] { + getSymbolTypes(name: string, bitFlags: SymbolTypeFlag): BscType[] { const symbolArray = this.getSymbol(name, bitFlags); if (!symbolArray) { return undefined; @@ -224,7 +224,7 @@ export class SymbolTable implements SymbolTypeGetter { /** * Get list of all symbols declared in this SymbolTable (includes parent SymbolTable). */ - public getAllSymbols(bitFlags: SymbolTypeFlags): BscSymbol[] { + public getAllSymbols(bitFlags: SymbolTypeFlag): BscSymbol[] { let symbols = this.getOwnSymbols(); //look through any sibling maps next for (let sibling of this.siblings) { @@ -305,7 +305,7 @@ export interface BscSymbol { name: string; range: Range; type: BscType; - flags: SymbolTypeFlags; + flags: SymbolTypeFlag; } export interface SymbolTypeGetter { diff --git a/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts b/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts index ffe9ca525..dadb0e570 100644 --- a/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts +++ b/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts @@ -8,7 +8,7 @@ import type { Locatable } from '../../lexer/Token'; import { ParseMode } from '../../parser/Parser'; import type { NamespaceStatement } from '../../parser/Statement'; import util from '../../util'; -import { SymbolTypeFlags } from '../../SymbolTable'; +import { SymbolTypeFlag } from '../../SymbolTable'; export class BrsFileSemanticTokensProcessor { public constructor( @@ -36,7 +36,7 @@ export class BrsFileSemanticTokensProcessor { //classes used in function param types for (const func of this.event.file.parser.references.functionExpressions) { for (const param of func.parameters) { - if (isClassType(param.getType({ flags: SymbolTypeFlags.typetime }))) { + if (isClassType(param.getType({ flags: SymbolTypeFlag.typetime }))) { const namespace = param.findAncestor(isNamespaceStatement); classes.push({ className: util.getAllDottedGetParts(param.typeExpression.expression).map(x => x.text).join('.'), diff --git a/src/bscPlugin/validation/BrsFileValidator.ts b/src/bscPlugin/validation/BrsFileValidator.ts index b0a1e4815..4b19ec10e 100644 --- a/src/bscPlugin/validation/BrsFileValidator.ts +++ b/src/bscPlugin/validation/BrsFileValidator.ts @@ -8,7 +8,7 @@ import type { AstNode, Expression, Statement } from '../../parser/AstNode'; import type { LiteralExpression } from '../../parser/Expression'; import { ParseMode } from '../../parser/Parser'; import type { ContinueStatement, EnumMemberStatement, EnumStatement, ForEachStatement, ForStatement, ImportStatement, LibraryStatement, WhileStatement } from '../../parser/Statement'; -import { SymbolTypeFlags } from '../../SymbolTable'; +import { SymbolTypeFlag } from '../../SymbolTable'; import type { BscType } from '../../types/BscType'; import { DynamicType } from '../../types/DynamicType'; import { NamespaceType } from '../../types/NamespaceType'; @@ -50,7 +50,7 @@ export class BrsFileValidator { MethodStatement: (node) => { //add the `super` symbol to class methods //Todo: get the actual type of the parent class - node.func.body.symbolTable.addSymbol('super', undefined, DynamicType.instance, SymbolTypeFlags.runtime); + node.func.body.symbolTable.addSymbol('super', undefined, DynamicType.instance, SymbolTypeFlag.runtime); }, CallfuncExpression: (node) => { if (node.args.length > 5) { @@ -66,22 +66,22 @@ export class BrsFileValidator { this.validateEnumDeclaration(node); //register this enum declaration - const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlags.typetime }); + const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlag.typetime }); // eslint-disable-next-line no-bitwise - node.parent.getSymbolTable()?.addSymbol(node.tokens.name.text, node.tokens.name.range, nodeType, SymbolTypeFlags.typetime | SymbolTypeFlags.runtime); + node.parent.getSymbolTable()?.addSymbol(node.tokens.name.text, node.tokens.name.range, nodeType, SymbolTypeFlag.typetime | SymbolTypeFlag.runtime); }, ClassStatement: (node) => { this.validateDeclarationLocations(node, 'class', () => util.createBoundingRange(node.classKeyword, node.name)); //register this class - const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlags.typetime }); + const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlag.typetime }); // eslint-disable-next-line no-bitwise - node.parent.getSymbolTable()?.addSymbol(node.name.text, node.name.range, nodeType, SymbolTypeFlags.typetime | SymbolTypeFlags.runtime); + node.parent.getSymbolTable()?.addSymbol(node.name.text, node.name.range, nodeType, SymbolTypeFlag.typetime | SymbolTypeFlag.runtime); }, AssignmentStatement: (node) => { //register this variable - const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlags.runtime }); - node.parent.getSymbolTable()?.addSymbol(node.name.text, node.name.range, nodeType, SymbolTypeFlags.runtime); + const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlag.runtime }); + node.parent.getSymbolTable()?.addSymbol(node.name.text, node.name.range, nodeType, SymbolTypeFlag.runtime); }, DottedSetStatement: (node) => { this.validateNoOptionalChainingInVarSet(node, [node.obj]); @@ -91,7 +91,7 @@ export class BrsFileValidator { }, ForEachStatement: (node) => { //register the for loop variable - node.parent.getSymbolTable()?.addSymbol(node.item.text, node.item.range, DynamicType.instance, SymbolTypeFlags.runtime); + node.parent.getSymbolTable()?.addSymbol(node.item.text, node.item.range, DynamicType.instance, SymbolTypeFlag.runtime); }, NamespaceStatement: (node) => { this.validateDeclarationLocations(node, 'namespace', () => util.createBoundingRange(node.keyword, node.nameExpression)); @@ -105,7 +105,7 @@ export class BrsFileValidator { } const parentSymbolTable = node.parent.getSymbolTable(); // eslint-disable-next-line no-bitwise - const namespaceTypeFlags = SymbolTypeFlags.runtime | SymbolTypeFlags.typetime; + const namespaceTypeFlags = SymbolTypeFlag.runtime | SymbolTypeFlag.typetime; //Build namespace types, part by part, if they don't exist //Last one can use the node's `getType()` method @@ -116,12 +116,12 @@ export class BrsFileValidator { const part = namespaceParts[i]; nameSoFar += (i > 0 ? '.' : '') + part; //TODO: is this correct? - nextNamespaceType = currentSymbolTable.getSymbol(part, SymbolTypeFlags.typetime)?.[0]?.type; + nextNamespaceType = currentSymbolTable.getSymbol(part, SymbolTypeFlag.typetime)?.[0]?.type; if (!isNamespaceType(nextNamespaceType)) { // if it is the last one, ie, the part that represents this node/namespace. // make sure the namespace's symboltable is a provider for the previous types' member table - nextNamespaceType = (i === namespaceParts.length - 1) ? node.getType({ flags: SymbolTypeFlags.typetime }) : new NamespaceType(nameSoFar); + nextNamespaceType = (i === namespaceParts.length - 1) ? node.getType({ flags: SymbolTypeFlag.typetime }) : new NamespaceType(nameSoFar); currentSymbolTable.addSymbol(part, node.nameExpression.range, nextNamespaceType, namespaceTypeFlags); } @@ -137,14 +137,14 @@ export class BrsFileValidator { }, FunctionStatement: (node) => { this.validateDeclarationLocations(node, 'function', () => util.createBoundingRange(node.func.functionType, node.name)); - const funcType = node.getType({ flags: SymbolTypeFlags.typetime }); + const funcType = node.getType({ flags: SymbolTypeFlag.typetime }); if (node.name?.text) { node.parent.getSymbolTable().addSymbol( node.name.text, node.name.range, funcType, - SymbolTypeFlags.runtime + SymbolTypeFlag.runtime ); } @@ -155,7 +155,7 @@ export class BrsFileValidator { node.name.text, node.name.range, funcType, - SymbolTypeFlags.runtime + SymbolTypeFlag.runtime ); //add the transpiled name for namespaced functions to the root symbol table const transpiledNamespaceFunctionName = node.getName(ParseMode.BrightScript); @@ -164,39 +164,39 @@ export class BrsFileValidator { transpiledNamespaceFunctionName, node.name.range, funcType, - SymbolTypeFlags.runtime + SymbolTypeFlag.runtime ); } }, FunctionExpression: (node) => { - if (!node.symbolTable.hasSymbol('m', SymbolTypeFlags.runtime)) { - node.symbolTable.addSymbol('m', undefined, DynamicType.instance, SymbolTypeFlags.runtime); + if (!node.symbolTable.hasSymbol('m', SymbolTypeFlag.runtime)) { + node.symbolTable.addSymbol('m', undefined, DynamicType.instance, SymbolTypeFlag.runtime); } }, FunctionParameterExpression: (node) => { const paramName = node.name?.text; const symbolTable = node.getSymbolTable(); - const nodeType = node.getType({ flags: SymbolTypeFlags.typetime }); - symbolTable?.addSymbol(paramName, node.name.range, nodeType, SymbolTypeFlags.runtime); + const nodeType = node.getType({ flags: SymbolTypeFlag.typetime }); + symbolTable?.addSymbol(paramName, node.name.range, nodeType, SymbolTypeFlag.runtime); }, InterfaceStatement: (node) => { this.validateDeclarationLocations(node, 'interface', () => util.createBoundingRange(node.tokens.interface, node.tokens.name)); - const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlags.typetime }); + const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlag.typetime }); // eslint-disable-next-line no-bitwise - node.parent.getSymbolTable().addSymbol(node.tokens.name.text, node.tokens.name.range, nodeType, SymbolTypeFlags.runtime | SymbolTypeFlags.typetime); + node.parent.getSymbolTable().addSymbol(node.tokens.name.text, node.tokens.name.range, nodeType, SymbolTypeFlag.runtime | SymbolTypeFlag.typetime); }, ConstStatement: (node) => { this.validateDeclarationLocations(node, 'const', () => util.createBoundingRange(node.tokens.const, node.tokens.name)); - const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlags.typetime }); - node.parent.getSymbolTable().addSymbol(node.tokens.name.text, node.tokens.name.range, nodeType, SymbolTypeFlags.runtime); + const nodeType = this.getTypeFromNode(node, { flags: SymbolTypeFlag.typetime }); + node.parent.getSymbolTable().addSymbol(node.tokens.name.text, node.tokens.name.range, nodeType, SymbolTypeFlag.runtime); }, CatchStatement: (node) => { - node.parent.getSymbolTable().addSymbol(node.exceptionVariable.text, node.exceptionVariable.range, DynamicType.instance, SymbolTypeFlags.runtime); + node.parent.getSymbolTable().addSymbol(node.exceptionVariable.text, node.exceptionVariable.range, DynamicType.instance, SymbolTypeFlag.runtime); }, DimStatement: (node) => { if (node.identifier) { - node.parent.getSymbolTable().addSymbol(node.identifier.text, node.identifier.range, DynamicType.instance, SymbolTypeFlags.runtime); + node.parent.getSymbolTable().addSymbol(node.identifier.text, node.identifier.range, DynamicType.instance, SymbolTypeFlag.runtime); } }, ContinueStatement: (node) => { diff --git a/src/bscPlugin/validation/ScopeValidator.ts b/src/bscPlugin/validation/ScopeValidator.ts index 2c2d15486..1bba0c9ac 100644 --- a/src/bscPlugin/validation/ScopeValidator.ts +++ b/src/bscPlugin/validation/ScopeValidator.ts @@ -4,7 +4,7 @@ import { Cache } from '../../Cache'; import { DiagnosticMessages } from '../../DiagnosticMessages'; import type { BrsFile } from '../../files/BrsFile'; import type { BscFile, BsDiagnostic, OnScopeValidateEvent } from '../../interfaces'; -import { SymbolTypeFlags } from '../../SymbolTable'; +import { SymbolTypeFlag } from '../../SymbolTable'; import type { EnumStatement, NamespaceStatement } from '../../parser/Statement'; import util from '../../util'; import { nodes, components } from '../../roku-types'; @@ -107,12 +107,12 @@ export class ScopeValidator { //get the namespace container (accounting for namespace-relative as well) const namespaceContainer = scope.getNamespace(firstNamespacePartLower, info.enclosingNamespaceNameLower); const isUsedAsType = this.checkIfUsedAsTypeExpression(info.expression); - let symbolType = SymbolTypeFlags.runtime; - let oppositeSymbolType = SymbolTypeFlags.typetime; + let symbolType = SymbolTypeFlag.runtime; + let oppositeSymbolType = SymbolTypeFlag.typetime; if (isUsedAsType) { // This is used in a TypeExpression - only look up types from SymbolTable - symbolType = SymbolTypeFlags.typetime; - oppositeSymbolType = SymbolTypeFlags.runtime; + symbolType = SymbolTypeFlag.typetime; + oppositeSymbolType = SymbolTypeFlag.runtime; } if (scope.program.options.enableTypeValidation) { diff --git a/src/files/BrsFile.ts b/src/files/BrsFile.ts index f7039c3aa..f5832880f 100644 --- a/src/files/BrsFile.ts +++ b/src/files/BrsFile.ts @@ -28,7 +28,7 @@ import type { DependencyGraph } from '../DependencyGraph'; import { CommentFlagProcessor } from '../CommentFlagProcessor'; import { URI } from 'vscode-uri'; import type { AstNode, Expression, Statement } from '../parser/AstNode'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import type { BscType } from '../types/BscType'; import { ClassType } from '../types/ClassType'; import { createIdentifier } from '../astUtils/creators'; @@ -469,7 +469,7 @@ export class BrsFile { name: param.name.text, getType: () => { if (this.program.options.enableTypeValidation) { - return param.getType({ flags: SymbolTypeFlags.typetime }); + return param.getType({ flags: SymbolTypeFlag.typetime }); } paramType = paramType ?? this.getBscTypeFromTypeExpression(param.typeExpression); return paramType; @@ -522,7 +522,7 @@ export class BrsFile { name: statement.name.text, getType: () => { if (this.program.options.enableTypeValidation) { - return statement.getType({ flags: SymbolTypeFlags.runtime }); + return statement.getType({ flags: SymbolTypeFlag.runtime }); } assignmentType = assignmentType ?? this.getBscTypeFromAssignment(statement, scope); return assignmentType; @@ -541,7 +541,7 @@ export class BrsFile { return util.tokenToBscType(createIdentifier(typeAsString, typeExpr.range)) ?? new ClassType(typeAsString); } if (isLiteralExpression(defaultValue)) { - return defaultValue.getType({ flags: SymbolTypeFlags.typetime }); + return defaultValue.getType({ flags: SymbolTypeFlag.typetime }); } return DynamicType.instance; } @@ -565,7 +565,7 @@ export class BrsFile { * Short circuit full `node.getType()` calls - used when enhancedTypeValidation is false */ private getBscTypeFromAssignment(assignment: AssignmentStatement, scope: FunctionScope): BscType { - const getTypeOptions = { flags: SymbolTypeFlags.runtime }; + const getTypeOptions = { flags: SymbolTypeFlag.runtime }; try { //function if (isFunctionExpression(assignment.value)) { @@ -613,7 +613,7 @@ export class BrsFile { let params = [] as CallableParam[]; for (let param of statement.func.parameters) { const paramType = this.program.options.enableTypeValidation - ? param.getType({ flags: SymbolTypeFlags.typetime }) + ? param.getType({ flags: SymbolTypeFlag.typetime }) : this.getBscTypeFromTypeExpression(param.typeExpression, param.defaultValue); let callableParam = { @@ -626,7 +626,7 @@ export class BrsFile { } const funcType = this.program.options.enableTypeValidation - ? statement.getType({ flags: SymbolTypeFlags.typetime }) + ? statement.getType({ flags: SymbolTypeFlag.typetime }) : this.getFunctionTypeFromFuncExpr(statement.func, statement.name.text); this.callables.push({ diff --git a/src/globalCallables.ts b/src/globalCallables.ts index 1523a1812..0876993e5 100644 --- a/src/globalCallables.ts +++ b/src/globalCallables.ts @@ -1,4 +1,4 @@ -import { SymbolTypeFlags } from './SymbolTable'; +import { SymbolTypeFlag } from './SymbolTable'; import { BrsFile } from './files/BrsFile'; import type { Callable } from './interfaces'; import { ArrayType } from './types/ArrayType'; @@ -1017,7 +1017,7 @@ for (let callable of globalCallables) { } globalFile.callables = globalCallables as Callable[]; for (const callable of globalCallables) { - globalFile.parser.symbolTable.addSymbol(callable.name, undefined, callable.type, SymbolTypeFlags.runtime); + globalFile.parser.symbolTable.addSymbol(callable.name, undefined, callable.type, SymbolTypeFlag.runtime); } /** diff --git a/src/interfaces.ts b/src/interfaces.ts index 7b60db8a2..a9b3d4e6f 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -14,7 +14,7 @@ import type { SourceMapGenerator, SourceNode } from 'source-map'; import type { BscType } from './types/BscType'; import type { AstEditor } from './astUtils/AstEditor'; import type { Token } from './lexer/Token'; -import type { SymbolTypeFlags } from './SymbolTable'; +import type { SymbolTypeFlag } from './SymbolTable'; export interface BsDiagnostic extends Diagnostic { file: BscFile; @@ -409,7 +409,7 @@ export interface FileLink { } export interface GetTypeOptions { - flags: SymbolTypeFlags; + flags: SymbolTypeFlag; typeChain?: TypeChainEntry[]; } diff --git a/src/parser/Expression.ts b/src/parser/Expression.ts index bb80b9f75..7704003ca 100644 --- a/src/parser/Expression.ts +++ b/src/parser/Expression.ts @@ -14,7 +14,7 @@ import { isAALiteralExpression, isArrayLiteralExpression, isCallExpression, isCa import type { GetTypeOptions, TranspileResult, TypedefProvider } from '../interfaces'; import { TypeChainEntry } from '../interfaces'; import type { BscType } from '../types/BscType'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { FunctionType } from '../types/FunctionType'; import { AstNodeKind, Expression } from './AstNode'; import { SymbolTable } from '../SymbolTable'; @@ -62,7 +62,7 @@ export class BinaryExpression extends Expression { public getType(options: GetTypeOptions): BscType { const operatorKind = this.operator.kind; - if (options.flags & SymbolTypeFlags.typetime) { + if (options.flags & SymbolTypeFlag.typetime) { // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check switch (operatorKind) { case TokenKind.Or: @@ -370,8 +370,8 @@ export class FunctionParameterExpression extends Expression { public readonly kind = AstNodeKind.FunctionParameterExpression; public getType(options: GetTypeOptions) { - return this.typeExpression?.getType({ ...options, flags: SymbolTypeFlags.typetime }) ?? - this.defaultValue?.getType({ ...options, flags: SymbolTypeFlags.runtime }) ?? + return this.typeExpression?.getType({ ...options, flags: SymbolTypeFlag.typetime }) ?? + this.defaultValue?.getType({ ...options, flags: SymbolTypeFlag.runtime }) ?? DynamicType.instance; } @@ -475,7 +475,7 @@ export class DottedGetExpression extends Expression { const objType = this.obj?.getType(options); const result = objType?.getMemberType(this.name?.text, options); options.typeChain?.push(new TypeChainEntry(this.name?.text, result, this.range)); - if (result || options.flags & SymbolTypeFlags.typetime) { + if (result || options.flags & SymbolTypeFlag.typetime) { // All types should be known at typetime return result; } @@ -1700,7 +1700,7 @@ export class TypeExpression extends Expression implements TypedefProvider { public range: Range; public transpile(state: BrsTranspileState): TranspileResult { - return [this.getType({ flags: SymbolTypeFlags.typetime }).toTypeString()]; + return [this.getType({ flags: SymbolTypeFlag.typetime }).toTypeString()]; } public walk(visitor: WalkVisitor, options: WalkOptions) { if (options.walkMode & InternalWalkMode.walkExpressions) { @@ -1709,7 +1709,7 @@ export class TypeExpression extends Expression implements TypedefProvider { } public getType(options: GetTypeOptions): BscType { - return this.expression.getType({ ...options, flags: SymbolTypeFlags.typetime }); + return this.expression.getType({ ...options, flags: SymbolTypeFlag.typetime }); } getTypedef(state: TranspileState): (string | SourceNode)[] { diff --git a/src/parser/Parser.Class.spec.ts b/src/parser/Parser.Class.spec.ts index a6ecbbe84..15aacf665 100644 --- a/src/parser/Parser.Class.spec.ts +++ b/src/parser/Parser.Class.spec.ts @@ -8,7 +8,7 @@ import { ClassStatement } from './Statement'; import { NewExpression } from './Expression'; import { StringType } from '../types/StringType'; import { expectDiagnosticsIncludes } from '../testHelpers.spec'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; describe('parser class', () => { it('throws exception when used in brightscript scope', () => { @@ -200,7 +200,7 @@ describe('parser class', () => { expect(field.accessModifier.kind).to.equal(TokenKind.Public); expect(field.name.text).to.equal('firstName'); expect(field.as.text).to.equal('as'); - expect(field.getType({ flags: SymbolTypeFlags.typetime })).to.be.instanceOf(StringType); + expect(field.getType({ flags: SymbolTypeFlag.typetime })).to.be.instanceOf(StringType); }); it('can be solely an identifier', () => { diff --git a/src/parser/Parser.spec.ts b/src/parser/Parser.spec.ts index b7418f754..65eab66da 100644 --- a/src/parser/Parser.spec.ts +++ b/src/parser/Parser.spec.ts @@ -16,7 +16,7 @@ import { BrsFile } from '../files/BrsFile'; import { Program } from '../Program'; import { createVisitor, WalkMode } from '../astUtils/visitors'; import type { Expression, Statement } from './AstNode'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { IntegerType } from '../types/IntegerType'; import { FloatType } from '../types/FloatType'; import { StringType } from '../types/StringType'; @@ -1328,7 +1328,7 @@ describe('parser', () => { expect(isAssignmentStatement(assignment)).to.be.true; expect(isTypeCastExpression(assignment.value)).to.be.true; expect(isCallExpression((assignment.value as TypeCastExpression).obj)).to.be.true; - expectTypeToBe(assignment.getType({ flags: SymbolTypeFlags.typetime }), IntegerType); + expectTypeToBe(assignment.getType({ flags: SymbolTypeFlag.typetime }), IntegerType); }); it('allows type casts in the middle of expressions', () => { @@ -1352,7 +1352,7 @@ describe('parser', () => { expect(isGroupingExpression(assignment.value.callee.obj)).to.be.true; expect(isTypeCastExpression(assignment.value.callee.obj.expression)).to.be.true; //grouping expression is an integer - expectTypeToBe(assignment.value.callee.obj.getType({ flags: SymbolTypeFlags.typetime }), IntegerType); + expectTypeToBe(assignment.value.callee.obj.getType({ flags: SymbolTypeFlag.typetime }), IntegerType); }); it('allows type casts in a function call', () => { @@ -1376,7 +1376,7 @@ describe('parser', () => { expect(isTypeCastExpression(fnCall.args[0])).to.be.true; let arg = fnCall.args[0] as TypeCastExpression; //argument type is float - expectTypeToBe(arg.getType({ flags: SymbolTypeFlags.typetime }), FloatType); + expectTypeToBe(arg.getType({ flags: SymbolTypeFlag.typetime }), FloatType); }); it('allows multiple type casts', () => { @@ -1393,7 +1393,7 @@ describe('parser', () => { expect(isPrintStatement(print)).to.be.true; expect(isTypeCastExpression(print.expressions[0])).to.be.true; //argument type is float - expectTypeToBe(print.expressions[0].getType({ flags: SymbolTypeFlags.typetime }), StringType); + expectTypeToBe(print.expressions[0].getType({ flags: SymbolTypeFlag.typetime }), StringType); }); it('flags invalid type cast syntax - multiple as', () => { diff --git a/src/parser/Statement.ts b/src/parser/Statement.ts index e5f1fbd26..adebcb8ba 100644 --- a/src/parser/Statement.ts +++ b/src/parser/Statement.ts @@ -11,7 +11,7 @@ import type { WalkVisitor, WalkOptions } from '../astUtils/visitors'; import { InternalWalkMode, walk, createVisitor, WalkMode, walkArray } from '../astUtils/visitors'; import { isCallExpression, isCommentStatement, isEnumMemberStatement, isExpression, isExpressionStatement, isFieldStatement, isFunctionExpression, isFunctionStatement, isIfStatement, isInterfaceFieldStatement, isInterfaceMethodStatement, isInvalidType, isLiteralExpression, isMethodStatement, isNamespaceStatement, isTypedefProvider, isUnaryExpression, isVoidType } from '../astUtils/reflection'; import type { GetTypeOptions, TranspileResult, TypedefProvider } from '../interfaces'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { createInvalidLiteral, createMethodStatement, createToken, interpolatedRange } from '../astUtils/creators'; import { DynamicType } from '../types/DynamicType'; import type { SourceNode } from 'source-map'; @@ -1515,10 +1515,10 @@ export class InterfaceStatement extends Statement implements TypedefProvider { const resultType = new InterfaceType(this.getName(ParseMode.BrighterScript), superIface); for (const statement of this.methods) { - resultType.addMember(statement?.tokens.name?.text, statement?.range, statement?.getType(options), SymbolTypeFlags.runtime); + resultType.addMember(statement?.tokens.name?.text, statement?.range, statement?.getType(options), SymbolTypeFlag.runtime); } for (const statement of this.fields) { - resultType.addMember(statement?.tokens.name?.text, statement?.range, statement.getType(options), SymbolTypeFlags.runtime); + resultType.addMember(statement?.tokens.name?.text, statement?.range, statement.getType(options), SymbolTypeFlag.runtime); } return resultType; } @@ -2097,10 +2097,10 @@ export class ClassStatement extends Statement implements TypedefProvider { for (const statement of this.methods) { const funcType = statement?.func.getType(options); - resultType.addMember(statement?.name?.text, statement?.range, funcType, SymbolTypeFlags.runtime); + resultType.addMember(statement?.name?.text, statement?.range, funcType, SymbolTypeFlag.runtime); } for (const statement of this.fields) { - resultType.addMember(statement?.name?.text, statement?.range, statement.getType(options), SymbolTypeFlags.runtime); + resultType.addMember(statement?.name?.text, statement?.range, statement.getType(options), SymbolTypeFlag.runtime); } return resultType; } @@ -2327,8 +2327,8 @@ export class FieldStatement extends Statement implements TypedefProvider { * Defaults to `DynamicType` */ getType(options: GetTypeOptions) { - return this.typeExpression?.getType({ ...options, flags: SymbolTypeFlags.typetime }) ?? - this.initialValue?.getType({ ...options, flags: SymbolTypeFlags.runtime }) ?? DynamicType.instance; + return this.typeExpression?.getType({ ...options, flags: SymbolTypeFlag.typetime }) ?? + this.initialValue?.getType({ ...options, flags: SymbolTypeFlag.runtime }) ?? DynamicType.instance; } public readonly range: Range; @@ -2348,7 +2348,7 @@ export class FieldStatement extends Statement implements TypedefProvider { ); } - let type = this.getType({ flags: SymbolTypeFlags.typetime }); + let type = this.getType({ flags: SymbolTypeFlag.typetime }); if (isInvalidType(type) || isVoidType(type)) { type = new DynamicType(); } @@ -2665,7 +2665,7 @@ export class EnumStatement extends Statement implements TypedefProvider { const resultType = new EnumType(this.fullName); resultType.pushMemberProvider(() => this.getSymbolTable()); for (const statement of this.getMembers()) { - resultType.addMember(statement?.tokens?.name?.text, statement?.range, statement.getType(), SymbolTypeFlags.runtime); + resultType.addMember(statement?.tokens?.name?.text, statement?.range, statement.getType(), SymbolTypeFlag.runtime); } return resultType; diff --git a/src/parser/tests/expression/TypeExpression.spec.ts b/src/parser/tests/expression/TypeExpression.spec.ts index b5a1974ed..37f1b3d25 100644 --- a/src/parser/tests/expression/TypeExpression.spec.ts +++ b/src/parser/tests/expression/TypeExpression.spec.ts @@ -3,7 +3,7 @@ import { ParseMode } from '../../Parser'; import { parse } from '../../Parser.spec'; import { expectTypeToBe, expectZeroDiagnostics } from '../../../testHelpers.spec'; import { isFunctionStatement, isReferenceType, isTypeExpression } from '../../../astUtils/reflection'; -import { SymbolTypeFlags } from '../../../SymbolTable'; +import { SymbolTypeFlag } from '../../../SymbolTable'; import { IntegerType } from '../../../types/IntegerType'; import { StringType } from '../../../types/StringType'; import { UnionType } from '../../../types/UnionType'; @@ -27,9 +27,9 @@ describe('TypeExpressions', () => { for (const param of funcStmt.func.parameters) { expect(isTypeExpression(param.typeExpression)).to.be.true; } - expectTypeToBe(funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlags.typetime }), IntegerType); - expectTypeToBe(funcStmt.func.parameters[1].getType({ flags: SymbolTypeFlags.typetime }), StringType); - expect(isReferenceType(funcStmt.func.parameters[2].getType({ flags: SymbolTypeFlags.typetime }))).to.be.true; + expectTypeToBe(funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlag.typetime }), IntegerType); + expectTypeToBe(funcStmt.func.parameters[1].getType({ flags: SymbolTypeFlag.typetime }), StringType); + expect(isReferenceType(funcStmt.func.parameters[2].getType({ flags: SymbolTypeFlag.typetime }))).to.be.true; } else { assert.fail(`expected ${funcStmt} to be FunctionStatement`); @@ -49,7 +49,7 @@ describe('TypeExpressions', () => { if (isFunctionStatement(funcStmt)) { expect(funcStmt.func.parameters.length).to.eq(1); expect(isTypeExpression(funcStmt.func.parameters[0].typeExpression)).to.be.true; - const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlags.typetime }); + const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlag.typetime }); expectTypeToBe(p1Type, UnionType); expect(p1Type.toString()).to.eq('integer or Namespaced.SomeType or string'); } else { @@ -70,7 +70,7 @@ describe('TypeExpressions', () => { if (isFunctionStatement(funcStmt)) { expect(funcStmt.func.parameters.length).to.eq(1); expect(isTypeExpression(funcStmt.func.parameters[0].typeExpression)).to.be.true; - const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlags.typetime }); + const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlag.typetime }); expectTypeToBe(p1Type, UnionType); expect(p1Type.toString()).to.eq('Alpha or Beta or Charlie or Delta'); } else { @@ -91,7 +91,7 @@ describe('TypeExpressions', () => { if (isFunctionStatement(funcStmt)) { expect(funcStmt.func.parameters.length).to.eq(1); expect(isTypeExpression(funcStmt.func.parameters[0].typeExpression)).to.be.true; - const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlags.typetime }); + const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlag.typetime }); expectTypeToBe(p1Type, UnionType); expect(p1Type.toString()).to.eq('NS1.Alpha or NS1.NS2.Beta or NS1.NS2.NS3.Charlie or Delta'); } else { @@ -113,8 +113,8 @@ describe('TypeExpressions', () => { expect(funcStmt.func.parameters.length).to.eq(2); expect(isTypeExpression(funcStmt.func.parameters[0].typeExpression)).to.be.true; expect(isTypeExpression(funcStmt.func.parameters[1].typeExpression)).to.be.true; - const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlags.typetime }); - const p2Type = funcStmt.func.parameters[1].getType({ flags: SymbolTypeFlags.typetime }); + const p1Type = funcStmt.func.parameters[0].getType({ flags: SymbolTypeFlag.typetime }); + const p2Type = funcStmt.func.parameters[1].getType({ flags: SymbolTypeFlag.typetime }); expectTypeToBe(p1Type, UnionType); expect(p1Type.toString()).to.eq('Alpha or Beta or Charlie'); expectTypeToBe(p2Type, UnionType); diff --git a/src/types/BscType.ts b/src/types/BscType.ts index e8373d599..9ddf5d35e 100644 --- a/src/types/BscType.ts +++ b/src/types/BscType.ts @@ -1,6 +1,6 @@ import type { GetSymbolTypeOptions, SymbolTableProvider } from '../SymbolTable'; import type { Range } from 'vscode-languageserver'; -import type { SymbolTypeFlags } from '../SymbolTable'; +import type { SymbolTypeFlag } from '../SymbolTable'; import { SymbolTable } from '../SymbolTable'; export abstract class BscType { @@ -21,7 +21,7 @@ export abstract class BscType { this.memberTable.popParentProvider(); } - addMember(name: string, range: Range, type: BscType, flags: SymbolTypeFlags) { + addMember(name: string, range: Range, type: BscType, flags: SymbolTypeFlag) { this.memberTable.addSymbol(name, range, type, flags); } @@ -61,7 +61,7 @@ export abstract class BscType { } - checkCompatibilityBasedOnMembers(targetType: BscType, flags: SymbolTypeFlags) { + checkCompatibilityBasedOnMembers(targetType: BscType, flags: SymbolTypeFlag) { let isSuperSet = true; const targetSymbols = targetType.memberTable?.getAllSymbols(flags); for (const targetSymbol of targetSymbols) { diff --git a/src/types/ClassType.spec.ts b/src/types/ClassType.spec.ts index 8fd2d3e14..a6556935b 100644 --- a/src/types/ClassType.spec.ts +++ b/src/types/ClassType.spec.ts @@ -6,7 +6,7 @@ import { expectTypeToBe } from '../testHelpers.spec'; import { ReferenceType } from './ReferenceType'; import { isReferenceType } from '../astUtils/reflection'; import { IntegerType } from './IntegerType'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; describe('ClassType', () => { @@ -40,33 +40,33 @@ describe('ClassType', () => { it('will look in super classes for members', () => { const superKlass = new ClassType('SuperKlass'); - superKlass.addMember('title', null, StringType.instance, SymbolTypeFlags.runtime); + superKlass.addMember('title', null, StringType.instance, SymbolTypeFlag.runtime); const subKlass = new ClassType('SubKlass', superKlass); - expectTypeToBe(subKlass.getMemberType('title', { flags: SymbolTypeFlags.runtime }), StringType); + expectTypeToBe(subKlass.getMemberType('title', { flags: SymbolTypeFlag.runtime }), StringType); }); it('allow ReferenceTypes as super classes', () => { const myTable = new SymbolTable('test'); - const futureSuperKlass = new ReferenceType('SuperKlass', 'SuperKlass', SymbolTypeFlags.typetime, () => myTable); + const futureSuperKlass = new ReferenceType('SuperKlass', 'SuperKlass', SymbolTypeFlag.typetime, () => myTable); const subKlass = new ClassType('SubKlass', futureSuperKlass); expect(subKlass.isResolvable()).to.be.false; const superKlass = new ClassType('SuperKlass'); - myTable.addSymbol('SuperKlass', null, superKlass, SymbolTypeFlags.typetime); + myTable.addSymbol('SuperKlass', null, superKlass, SymbolTypeFlag.typetime); expect(subKlass.isResolvable()).to.be.true; }); it('allows members of future super classes to be resolved', () => { const myTable = new SymbolTable('test'); - const futureSuperKlass = new ReferenceType('SuperKlass', 'SuperKlass', SymbolTypeFlags.typetime, () => myTable); + const futureSuperKlass = new ReferenceType('SuperKlass', 'SuperKlass', SymbolTypeFlag.typetime, () => myTable); const subKlass = new ClassType('SubKlass', futureSuperKlass); expect(subKlass.isResolvable()).to.be.false; - const futureTitleType = subKlass.getMemberType('title', { flags: SymbolTypeFlags.runtime }); + const futureTitleType = subKlass.getMemberType('title', { flags: SymbolTypeFlag.runtime }); expect(isReferenceType(futureTitleType)).to.be.true; expect(futureTitleType.isResolvable()).to.be.false; const superKlass = new ClassType('SuperKlass'); - superKlass.addMember('title', null, StringType.instance, SymbolTypeFlags.runtime); + superKlass.addMember('title', null, StringType.instance, SymbolTypeFlag.runtime); // eslint-disable-next-line no-bitwise - myTable.addSymbol('SuperKlass', null, superKlass, SymbolTypeFlags.typetime | SymbolTypeFlags.runtime); + myTable.addSymbol('SuperKlass', null, superKlass, SymbolTypeFlag.typetime | SymbolTypeFlag.runtime); expect(futureTitleType.isResolvable()).to.be.true; expectTypeToBe(futureTitleType, StringType); }); @@ -75,8 +75,8 @@ describe('ClassType', () => { it('includes superclass members', () => { const superKlass = new ClassType('SuperKlass'); const subKlass = new ClassType('SubKlass', superKlass); - superKlass.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); - superKlass.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); + superKlass.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); + superKlass.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); expect((subKlass as any).toJSString).to.exist; expect((subKlass as any).toJSString()).to.equal('{ age: integer; name: string; }'); diff --git a/src/types/InheritableType.ts b/src/types/InheritableType.ts index 59b6672f3..cf9b2c553 100644 --- a/src/types/InheritableType.ts +++ b/src/types/InheritableType.ts @@ -1,6 +1,6 @@ import type { GetTypeOptions } from '../interfaces'; import { isInheritableType } from '../astUtils/reflection'; -import type { SymbolTypeFlags } from '../SymbolTable'; +import type { SymbolTypeFlag } from '../SymbolTable'; import { BscType } from './BscType'; export abstract class InheritableType extends BscType { @@ -73,7 +73,7 @@ export abstract class InheritableType extends BscType { */ private toJSString() { // eslint-disable-next-line no-bitwise - const flags = 3 as SymbolTypeFlags; //SymbolTypeFlags.runtime | SymbolTypeFlags.typetime; + const flags = 3 as SymbolTypeFlag; //SymbolTypeFlags.runtime | SymbolTypeFlags.typetime; let result = '{'; const memberSymbols = (this.memberTable?.getAllSymbols(flags) || []).sort((a, b) => a.name.localeCompare(b.name)); for (const symbol of memberSymbols) { diff --git a/src/types/InterfaceType.spec.ts b/src/types/InterfaceType.spec.ts index ac7662e63..ed620cd01 100644 --- a/src/types/InterfaceType.spec.ts +++ b/src/types/InterfaceType.spec.ts @@ -7,7 +7,7 @@ import { InterfaceType } from './InterfaceType'; import { ObjectType } from './ObjectType'; import { StringType } from './StringType'; import type { ReferenceType } from './ReferenceType'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; describe('InterfaceType', () => { describe('toJSString', () => { @@ -200,7 +200,7 @@ function iface(members: Record, name?: string, parentType?: Int const ifaceType = new InterfaceType(name, parentType); for (const key in members) { - ifaceType.addMember(key, null, members[key], SymbolTypeFlags.runtime); + ifaceType.addMember(key, null, members[key], SymbolTypeFlag.runtime); } return ifaceType; } diff --git a/src/types/InterfaceType.ts b/src/types/InterfaceType.ts index f99cb570d..07d57ccc7 100644 --- a/src/types/InterfaceType.ts +++ b/src/types/InterfaceType.ts @@ -1,4 +1,4 @@ -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { isDynamicType, isInterfaceType, isUnionType, isInheritableType } from '../astUtils/reflection'; import type { BscType } from './BscType'; import { BscTypeKind } from './BscTypeKind'; @@ -27,7 +27,7 @@ export class InterfaceType extends InheritableType { return true; } if (isInheritableType(targetType) || isUnionType(targetType)) { - return this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlags.runtime); + return this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime); } return false; } diff --git a/src/types/ObjectType.ts b/src/types/ObjectType.ts index 06e75664b..989dc6e38 100644 --- a/src/types/ObjectType.ts +++ b/src/types/ObjectType.ts @@ -1,4 +1,4 @@ -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { isDynamicType, isInheritableType, isObjectType, isUnionType } from '../astUtils/reflection'; import type { GetTypeOptions } from '../interfaces'; import { BscType } from './BscType'; @@ -41,6 +41,6 @@ export class ObjectType extends BscType { } isEqual(otherType: BscType) { - return isObjectType(otherType) && this.checkCompatibilityBasedOnMembers(otherType, SymbolTypeFlags.runtime); + return isObjectType(otherType) && this.checkCompatibilityBasedOnMembers(otherType, SymbolTypeFlag.runtime); } } diff --git a/src/types/ReferenceType.spec.ts b/src/types/ReferenceType.spec.ts index 0df3d4244..dd1ff6ba9 100644 --- a/src/types/ReferenceType.spec.ts +++ b/src/types/ReferenceType.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { SymbolTable } from '../SymbolTable'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { expectTypeToBe } from '../testHelpers.spec'; import { DynamicType } from './DynamicType'; import { IntegerType } from './IntegerType'; @@ -12,7 +12,7 @@ import { isTypePropertyReferenceType, isReferenceType } from '../astUtils/reflec import { FunctionType } from './FunctionType'; import { NamespaceType } from './NamespaceType'; -const runtimeFlag = SymbolTypeFlags.runtime; +const runtimeFlag = SymbolTypeFlag.runtime; describe('ReferenceType', () => { it('can be checked with reflection', () => { @@ -26,28 +26,28 @@ describe('ReferenceType', () => { expectTypeToBe(new ReferenceType('test', 'test', runtimeFlag, () => undefined), DynamicType); const table = new SymbolTable('testTable'); expectTypeToBe(new ReferenceType('test', 'test', runtimeFlag, () => table), DynamicType); - table.addSymbol('someVar', null, StringType.instance, SymbolTypeFlags.runtime); + table.addSymbol('someVar', null, StringType.instance, SymbolTypeFlag.runtime); expectTypeToBe(new ReferenceType('test', 'test', runtimeFlag, () => table), DynamicType); }); it('can resolve based on a symbol table', () => { const table = new SymbolTable('test'); const ref = new ReferenceType('someVar', 'someVar', runtimeFlag, () => table); - table.addSymbol('someVar', null, StringType.instance, SymbolTypeFlags.runtime); + table.addSymbol('someVar', null, StringType.instance, SymbolTypeFlag.runtime); expectTypeToBe(ref, StringType); }); it('resolves before checking assigning and convertible', () => { const table = new SymbolTable('test'); const ref = new ReferenceType('someVar', 'someVar', runtimeFlag, () => table); - table.addSymbol('someVar', null, IntegerType.instance, SymbolTypeFlags.runtime); + table.addSymbol('someVar', null, IntegerType.instance, SymbolTypeFlag.runtime); expect(ref.isTypeCompatible(FloatType.instance)).to.be.true; }); it('resolves before stringifying', () => { const table = new SymbolTable('test'); const ref = new ReferenceType('someKlass', 'someKlass', runtimeFlag, () => table); - table.addSymbol('someKlass', null, new ClassType('SomeKlass'), SymbolTypeFlags.runtime); + table.addSymbol('someKlass', null, new ClassType('SomeKlass'), SymbolTypeFlag.runtime); expect(ref.toString()).to.eq('SomeKlass'); }); @@ -55,7 +55,7 @@ describe('ReferenceType', () => { it('catches circular references', () => { const table = new SymbolTable('test'); const ref = new ReferenceType('someVar', 'someVar', runtimeFlag, () => table); - table.addSymbol('someVar', null, ref, SymbolTypeFlags.runtime); + table.addSymbol('someVar', null, ref, SymbolTypeFlag.runtime); expectTypeToBe(ref, DynamicType); }); @@ -65,11 +65,11 @@ describe('ReferenceType', () => { const ref1 = new ReferenceType('someVar1', 'someVar1', runtimeFlag, () => table); const ref2 = new ReferenceType('someVar2', 'someVar2', runtimeFlag, () => table); const ref3 = new ReferenceType('someVar3', 'someVar3', runtimeFlag, () => table); - table.addSymbol('someVar0', null, ref1, SymbolTypeFlags.runtime); - table.addSymbol('someVar1', null, ref2, SymbolTypeFlags.runtime); - table.addSymbol('someVar2', null, ref3, SymbolTypeFlags.runtime); - table.addSymbol('someVar3', null, ref1, SymbolTypeFlags.runtime); - expectTypeToBe(table.getSymbol('someVar0', SymbolTypeFlags.runtime)[0].type, DynamicType); + table.addSymbol('someVar0', null, ref1, SymbolTypeFlag.runtime); + table.addSymbol('someVar1', null, ref2, SymbolTypeFlag.runtime); + table.addSymbol('someVar2', null, ref3, SymbolTypeFlag.runtime); + table.addSymbol('someVar3', null, ref1, SymbolTypeFlag.runtime); + expectTypeToBe(table.getSymbol('someVar0', SymbolTypeFlag.runtime)[0].type, DynamicType); }); }); @@ -97,7 +97,7 @@ describe('PropertyReferenceType', () => { // `ref` will resolve to DynamicType, and its returnType is DynamicType.Instance expectTypeToBe(propRef, DynamicType); // Set ref to resolve to a function - table.addSymbol('someFunc', null, new FunctionType(IntegerType.instance), SymbolTypeFlags.runtime); + table.addSymbol('someFunc', null, new FunctionType(IntegerType.instance), SymbolTypeFlag.runtime); expectTypeToBe(propRef, IntegerType); }); @@ -105,14 +105,14 @@ describe('PropertyReferenceType', () => { const table = new SymbolTable('test'); const fnRef = new ReferenceType('someFunc', 'someFunc', runtimeFlag, () => table); const returnRef = new TypePropertyReferenceType(fnRef, 'returnType'); - const returnPropRef = returnRef.getMemberType('myNum', { flags: SymbolTypeFlags.runtime }); + const returnPropRef = returnRef.getMemberType('myNum', { flags: SymbolTypeFlag.runtime }); // `ref` will resolve to DynamicType, and its returnType is DynamicType.Instance expectTypeToBe(returnPropRef, DynamicType); // Set fnRef to resolve to a function that returns a complex type const klassType = new ClassType('Klass'); - klassType.addMember('myNum', null, IntegerType.instance, SymbolTypeFlags.runtime); - table.addSymbol('someFunc', null, new FunctionType(klassType), SymbolTypeFlags.runtime); + klassType.addMember('myNum', null, IntegerType.instance, SymbolTypeFlag.runtime); + table.addSymbol('someFunc', null, new FunctionType(klassType), SymbolTypeFlag.runtime); // returnPropRef = someFunc().myNum expectTypeToBe(fnRef, FunctionType); @@ -127,15 +127,15 @@ describe('PropertyReferenceType', () => { let nsA = new NamespaceType('Alpha'); let nsAB = new NamespaceType('Alpha.Beta'); let nsABC = new NamespaceType('Alpha.Beta.Charlie'); - nsA.addMember('Beta', null, nsAB, SymbolTypeFlags.typetime); - nsAB.addMember('Charlie', null, nsABC, SymbolTypeFlags.typetime); + nsA.addMember('Beta', null, nsAB, SymbolTypeFlag.typetime); + nsAB.addMember('Charlie', null, nsABC, SymbolTypeFlag.typetime); - let myRef = new ReferenceType('MyKlass', 'Alpha.Beta.Charlie.MyKlass', SymbolTypeFlags.typetime, () => nsABC.memberTable); + let myRef = new ReferenceType('MyKlass', 'Alpha.Beta.Charlie.MyKlass', SymbolTypeFlag.typetime, () => nsABC.memberTable); expect(myRef.isResolvable()).to.be.false; expect(myRef.toString()).to.eq('Alpha.Beta.Charlie.MyKlass'); let myKlass = new ClassType('Alpha.Beta.Charlie.MyKlass'); - nsABC.addMember('MyKlass', null, myKlass, SymbolTypeFlags.typetime); + nsABC.addMember('MyKlass', null, myKlass, SymbolTypeFlag.typetime); expect(myRef.isResolvable()).to.be.true; expect(myRef.toString()).to.eq('Alpha.Beta.Charlie.MyKlass'); }); diff --git a/src/types/ReferenceType.ts b/src/types/ReferenceType.ts index 758de42af..3527c99b1 100644 --- a/src/types/ReferenceType.ts +++ b/src/types/ReferenceType.ts @@ -1,13 +1,13 @@ import type { GetTypeOptions } from '../interfaces'; import type { CacheVerifierProvider } from '../CacheVerifier'; import type { GetSymbolTypeOptions, SymbolTypeGetterProvider } from '../SymbolTable'; -import type { SymbolTypeFlags } from '../SymbolTable'; +import type { SymbolTypeFlag } from '../SymbolTable'; import { isDynamicType, isReferenceType } from '../astUtils/reflection'; import { BscType } from './BscType'; import { DynamicType } from './DynamicType'; import { BscTypeKind } from './BscTypeKind'; -export function referenceTypeFactory(memberKey: string, fullName, flags: SymbolTypeFlags, tableProvider: SymbolTypeGetterProvider) { +export function referenceTypeFactory(memberKey: string, fullName, flags: SymbolTypeFlag, tableProvider: SymbolTypeGetterProvider) { return new ReferenceType(memberKey, fullName, flags, tableProvider); } @@ -20,7 +20,7 @@ export class ReferenceType extends BscType { * @param flags is this type available at typetime, runtime, etc. * @param tableProvider function that returns a SymbolTable that we use for the lookup. */ - constructor(public memberKey: string, public fullName, public flags: SymbolTypeFlags, private tableProvider: SymbolTypeGetterProvider, private cacheVerifierProvider?: CacheVerifierProvider) { + constructor(public memberKey: string, public fullName, public flags: SymbolTypeFlag, private tableProvider: SymbolTypeGetterProvider, private cacheVerifierProvider?: CacheVerifierProvider) { super(memberKey); // eslint-disable-next-line no-constructor-return return new Proxy(this, { diff --git a/src/types/UnionType.spec.ts b/src/types/UnionType.spec.ts index 021c6c57f..e895972bc 100644 --- a/src/types/UnionType.spec.ts +++ b/src/types/UnionType.spec.ts @@ -4,7 +4,7 @@ import { IntegerType } from './IntegerType'; import { UnionType } from './UnionType'; import { FloatType } from './FloatType'; import { InterfaceType } from './InterfaceType'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { BooleanType } from './BooleanType'; import { expectTypeToBe } from '../testHelpers.spec'; import { isReferenceType } from '../astUtils/reflection'; @@ -13,14 +13,14 @@ import { isReferenceType } from '../astUtils/reflection'; describe('UnionType', () => { it('can be assigned to by anything that can be assigned to an included type', () => { const parentIFace = new InterfaceType('IfaceParent'); - parentIFace.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); + parentIFace.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); const iFace = new InterfaceType('IfaceChild', parentIFace); - iFace.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); + iFace.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); const otheriFaceWithSameMembers = new InterfaceType('OtherIface'); - otheriFaceWithSameMembers.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); - otheriFaceWithSameMembers.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); - otheriFaceWithSameMembers.addMember('height', null, FloatType.instance, SymbolTypeFlags.runtime); + otheriFaceWithSameMembers.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); + otheriFaceWithSameMembers.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); + otheriFaceWithSameMembers.addMember('height', null, FloatType.instance, SymbolTypeFlag.runtime); const myUnion = new UnionType([FloatType.instance, iFace, StringType.instance]); @@ -40,15 +40,15 @@ describe('UnionType', () => { it('can assign to a more general Union with interfaces', () => { const parentIFace = new InterfaceType('IfaceParent'); - parentIFace.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); + parentIFace.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); const iFace = new InterfaceType('IfaceChild', parentIFace); - iFace.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); - iFace.addMember('height', null, FloatType.instance, SymbolTypeFlags.runtime); + iFace.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); + iFace.addMember('height', null, FloatType.instance, SymbolTypeFlag.runtime); const myUnion = new UnionType([FloatType.instance, iFace, StringType.instance, BooleanType.instance]); const otheriFaceWithSameMembers = new InterfaceType('OtherIface'); - otheriFaceWithSameMembers.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); - otheriFaceWithSameMembers.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); + otheriFaceWithSameMembers.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); + otheriFaceWithSameMembers.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); const otherUnion = new UnionType([FloatType.instance, otheriFaceWithSameMembers, StringType.instance]); @@ -58,9 +58,9 @@ describe('UnionType', () => { it('will get a string representation in order given', () => { const iFace1 = new InterfaceType('SomeIface'); - iFace1.addMember('age', null, IntegerType.instance, SymbolTypeFlags.typetime); - iFace1.addMember('name', null, StringType.instance, SymbolTypeFlags.typetime); - iFace1.addMember('height', null, FloatType.instance, SymbolTypeFlags.typetime); + iFace1.addMember('age', null, IntegerType.instance, SymbolTypeFlag.typetime); + iFace1.addMember('name', null, StringType.instance, SymbolTypeFlag.typetime); + iFace1.addMember('height', null, FloatType.instance, SymbolTypeFlag.typetime); const myUnion = new UnionType([FloatType.instance, StringType.instance, BooleanType.instance, iFace1]); expect(myUnion.toString()).to.eq('float or string or boolean or SomeIface'); @@ -69,18 +69,18 @@ describe('UnionType', () => { describe('getMemberType', () => { it('will find the union of inner types', () => { const iFace1 = new InterfaceType('iFace1'); - iFace1.addMember('age', null, IntegerType.instance, SymbolTypeFlags.typetime); - iFace1.addMember('name', null, StringType.instance, SymbolTypeFlags.typetime); - iFace1.addMember('height', null, FloatType.instance, SymbolTypeFlags.typetime); + iFace1.addMember('age', null, IntegerType.instance, SymbolTypeFlag.typetime); + iFace1.addMember('name', null, StringType.instance, SymbolTypeFlag.typetime); + iFace1.addMember('height', null, FloatType.instance, SymbolTypeFlag.typetime); const iFace2 = new InterfaceType('iFace2'); - iFace2.addMember('age', null, IntegerType.instance, SymbolTypeFlags.typetime); - iFace2.addMember('name', null, StringType.instance, SymbolTypeFlags.typetime); - iFace2.addMember('height', null, StringType.instance, SymbolTypeFlags.typetime); + iFace2.addMember('age', null, IntegerType.instance, SymbolTypeFlag.typetime); + iFace2.addMember('name', null, StringType.instance, SymbolTypeFlag.typetime); + iFace2.addMember('height', null, StringType.instance, SymbolTypeFlag.typetime); const myUnion = new UnionType([iFace1, iFace2]); - const options = { flags: SymbolTypeFlags.typetime }; + const options = { flags: SymbolTypeFlag.typetime }; const ageType = myUnion.getMemberType('age', options); expectTypeToBe(ageType, IntegerType); const nameType = myUnion.getMemberType('name', options); @@ -95,16 +95,16 @@ describe('UnionType', () => { it('will return reference types if any inner type does not include the member', () => { const iFace1 = new InterfaceType('iFace1'); - iFace1.addMember('age', null, IntegerType.instance, SymbolTypeFlags.typetime); - iFace1.addMember('name', null, StringType.instance, SymbolTypeFlags.typetime); - iFace1.addMember('height', null, FloatType.instance, SymbolTypeFlags.typetime); + iFace1.addMember('age', null, IntegerType.instance, SymbolTypeFlag.typetime); + iFace1.addMember('name', null, StringType.instance, SymbolTypeFlag.typetime); + iFace1.addMember('height', null, FloatType.instance, SymbolTypeFlag.typetime); const iFace2 = new InterfaceType('iFace2'); - iFace2.addMember('age', null, IntegerType.instance, SymbolTypeFlags.typetime); - iFace2.addMember('name', null, StringType.instance, SymbolTypeFlags.typetime); + iFace2.addMember('age', null, IntegerType.instance, SymbolTypeFlag.typetime); + iFace2.addMember('name', null, StringType.instance, SymbolTypeFlag.typetime); const myUnion = new UnionType([iFace1, iFace2]); - const options = { flags: SymbolTypeFlags.typetime }; + const options = { flags: SymbolTypeFlag.typetime }; const heightType1 = myUnion.getMemberType('height', options); expectTypeToBe(heightType1, UnionType); const heightTypes1 = (heightType1 as UnionType).types; @@ -114,7 +114,7 @@ describe('UnionType', () => { expect(isReferenceType(heightTypes1[1])).to.be.true; expect(heightTypes1[1].isResolvable()).to.be.false; - iFace2.addMember('height', null, FloatType.instance, SymbolTypeFlags.typetime); + iFace2.addMember('height', null, FloatType.instance, SymbolTypeFlag.typetime); const heightType2 = myUnion.getMemberType('height', options); expectTypeToBe(heightType2, FloatType); }); diff --git a/src/types/helper.spec.ts b/src/types/helper.spec.ts index 9b5f26d51..eada92802 100644 --- a/src/types/helper.spec.ts +++ b/src/types/helper.spec.ts @@ -9,7 +9,7 @@ import { StringType } from './StringType'; import { UnionType, unionTypeFactory } from './UnionType'; import { findTypeIntersection, findTypeUnion, getUniqueType, getUniqueTypesFromArray } from './helpers'; import { InterfaceType } from './InterfaceType'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; import { DoubleType } from './DoubleType'; import { BooleanType } from './BooleanType'; @@ -128,12 +128,12 @@ describe('getUniqueType', () => { it('should return a a union type of two compatible interfaces', () => { const iface1 = new InterfaceType('iface1'); - iface1.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); - iface1.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); + iface1.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); + iface1.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); const iface2 = new InterfaceType('iface2'); - iface2.addMember('name', null, StringType.instance, SymbolTypeFlags.runtime); - iface2.addMember('age', null, IntegerType.instance, SymbolTypeFlags.runtime); + iface2.addMember('name', null, StringType.instance, SymbolTypeFlag.runtime); + iface2.addMember('age', null, IntegerType.instance, SymbolTypeFlag.runtime); expect(iface1.isTypeCompatible(iface2)).to.be.true; expect(iface2.isTypeCompatible(iface1)).to.be.true; diff --git a/src/util.spec.ts b/src/util.spec.ts index 96acf2924..cef085b78 100644 --- a/src/util.spec.ts +++ b/src/util.spec.ts @@ -11,7 +11,7 @@ import { TypeChainEntry } from './interfaces'; import { ClassType } from './types/ClassType'; import { NamespaceType } from './types/NamespaceType'; import { ReferenceType } from './types/ReferenceType'; -import { SymbolTypeFlags } from './SymbolTable'; +import { SymbolTypeFlag } from './SymbolTable'; const sinon = createSandbox(); @@ -815,7 +815,7 @@ describe('util', () => { const chain = [ new TypeChainEntry('AlphaNamespace', new NamespaceType('Alpha'), util.createRange(1, 1, 2, 2)), new TypeChainEntry('BetaProp', new ClassType('Beta'), util.createRange(2, 2, 3, 3)), - new TypeChainEntry('CharlieProp', new ReferenceType('Charlie', 'Alpha.Beta.CharlieProp', SymbolTypeFlags.runtime, () => null), util.createRange(3, 3, 4, 4)) + new TypeChainEntry('CharlieProp', new ReferenceType('Charlie', 'Alpha.Beta.CharlieProp', SymbolTypeFlag.runtime, () => null), util.createRange(3, 3, 4, 4)) ]; const result = util.processTypeChain(chain); diff --git a/src/validators/ClassValidator.ts b/src/validators/ClassValidator.ts index fe4d03436..3b3e14e2e 100644 --- a/src/validators/ClassValidator.ts +++ b/src/validators/ClassValidator.ts @@ -13,7 +13,7 @@ import type { BrsFile } from '../files/BrsFile'; import { TokenKind } from '../lexer/TokenKind'; import { DynamicType } from '../types/DynamicType'; import type { BscType } from '../types/BscType'; -import { SymbolTypeFlags } from '../SymbolTable'; +import { SymbolTypeFlag } from '../SymbolTable'; export class BsClassValidator { private scope: Scope; @@ -222,11 +222,11 @@ export class BsClassValidator { if (isFieldStatement(member)) { let ancestorMemberType: BscType = new DynamicType(); if (isFieldStatement(ancestorAndMember.member)) { - ancestorMemberType = ancestorAndMember.member.getType({ flags: SymbolTypeFlags.typetime }); + ancestorMemberType = ancestorAndMember.member.getType({ flags: SymbolTypeFlag.typetime }); } else if (isMethodStatement(ancestorAndMember.member)) { - ancestorMemberType = ancestorAndMember.member.func.getType({ flags: SymbolTypeFlags.typetime }); + ancestorMemberType = ancestorAndMember.member.func.getType({ flags: SymbolTypeFlag.typetime }); } - const childFieldType = member.getType({ flags: SymbolTypeFlags.typetime }); + const childFieldType = member.getType({ flags: SymbolTypeFlag.typetime }); if (!ancestorMemberType.isTypeCompatible(childFieldType)) { //flag incompatible child field type to ancestor field type this.diagnostics.push({