Skip to content

Commit

Permalink
code cleanup, deprecate getRange() to reduce the polymorphism complex…
Browse files Browse the repository at this point in the history
…ity among other less significant methods.
  • Loading branch information
EliotVU committed May 21, 2024
1 parent d3d523f commit 3436a03
Show file tree
Hide file tree
Showing 42 changed files with 454 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"!${workspaceRoot}/out/vendor.js"
],
"sourceMaps": true,
"smartStep": false,
"smartStep": true,
"restart": true,
"request": "attach",
"type": "node",
Expand Down
43 changes: 0 additions & 43 deletions grammars/test/Grammar.uc

This file was deleted.

4 changes: 2 additions & 2 deletions server/src/UC/Parser/Parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function parseExec(parser: UCParser): { errors: string[] } {

describe('Grammar', () => {
it('should have no syntax errors', () => {
const tests = ['Grammar.uc', 'parser.constDecl.uc', 'parser.defaultPropertiesBlock.uc'];
const tests = ['parser.constDecl.uc', 'parser.defaultPropertiesBlock.uc'];
for (const testFileName of tests) {
const text = getText(resolveExampleFileName(testFileName));
const p = parseText(text);
Expand All @@ -61,4 +61,4 @@ describe('Grammar', () => {
expect(state.errors.length === 0, testFileName).to.be.true;
}
});
});
});
2 changes: 1 addition & 1 deletion server/src/UC/Symbols/ArrayOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './';

/** (defaultproperties) Acts as a template for array operations such as MyArray.Replace(item1, item2) etc. */
export const DefaultArray = new UCStructSymbol({ name: NAME_ARRAY, range: DEFAULT_RANGE });
export const DefaultArray = new UCStructSymbol({ name: NAME_ARRAY, range: DEFAULT_RANGE }, DEFAULT_RANGE);
DefaultArray.modifiers |= ModifierFlags.Intrinsic | ModifierFlags.Keyword;

const EmptyOperation = new UCMethodLikeSymbol(toName('Empty'));
Expand Down
11 changes: 0 additions & 11 deletions server/src/UC/Symbols/ClassSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,6 @@ export class UCClassSymbol extends UCStructSymbol {
return text;
}

override getSymbolAtPos(position: Position): ISymbol | undefined {
if (intersectsWith(this.getRange(), position)) {
if (intersectsWithRange(position, this.id.range)) {
return this;
}
return this.getContainedSymbolAtPos(position);
}
// HACK: due the fact that a class doesn't enclose its symbols we'll have to check for child symbols regardless if the given position is within the declaration span.
return this.getChildSymbolAtPos(position);
}

override getContainedSymbolAtPos(position: Position) {
let symbol: ISymbol | undefined = undefined;
if (this.extendsType && (symbol = this.extendsType.getSymbolAtPos(position))) {
Expand Down
33 changes: 9 additions & 24 deletions server/src/UC/Symbols/DefaultPropertiesBlock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@


import { UCDocument } from '../document';
import { Name } from '../name';
import { SymbolWalker } from '../symbolWalker';
import {
isArchetypeSymbol, ModifierFlags, UCFieldSymbol, UCObjectSymbol, UCStructSymbol, UCSymbolKind
isArchetypeSymbol, ModifierFlags, UCFieldSymbol, UCStructSymbol, UCSymbolKind
} from './';

export class UCDefaultPropertiesBlock extends UCStructSymbol {
Expand All @@ -15,30 +11,19 @@ export class UCDefaultPropertiesBlock extends UCStructSymbol {
// Set to either the document's class or a generated Default_ClassName archetype.
public default: UCStructSymbol;

override getTooltip(): string {
return `(${this.id.name.text.toLowerCase()}) ${this.default.getTooltip()}`;
}
override getTooltip(): string {
return `(${this.id.name.text.toLowerCase()}) ${this.default.getTooltip()}`;
}

override addSymbol(symbol: UCFieldSymbol): number | undefined {
override addSymbol(symbol: UCFieldSymbol): number | undefined {
const r = super.addSymbol(symbol);
if (isArchetypeSymbol(symbol)) {
symbol.outer = this.default;
}
return r;
}

override findSuperSymbol<T extends UCFieldSymbol>(id: Name, kind?: UCSymbolKind) {
// We assume that @default is set to either a class or an archetype (UE3)
// If the default is an archetype then the archetype will look for its symbols in its own @super
const symbol = this.default.findSuperSymbol<T>(id, kind);
return symbol;
}

override acceptCompletion(_document: UCDocument, _context: UCObjectSymbol): boolean {
return false;
}
}

override accept<Result>(visitor: SymbolWalker<Result>): Result | void {
return visitor.visitDefaultPropertiesBlock(this);
}
override accept<Result>(visitor: SymbolWalker<Result>): Result | void {
return visitor.visitDefaultPropertiesBlock(this);
}
}
28 changes: 2 additions & 26 deletions server/src/UC/Symbols/FieldSymbol.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Position, Range } from 'vscode-languageserver-types';
import { Position } from 'vscode-languageserver-types';

import { UCDocument } from '../document';
import { intersectsWith, intersectsWithRange } from '../helpers';
import { indexDeclarationReference } from '../indexer';
import { Identifier, isParamSymbol, ISymbol, ITypeSymbol, UCObjectSymbol, UCStructSymbol } from './';
import { isParamSymbol, ISymbol, ITypeSymbol, UCObjectSymbol, UCStructSymbol } from './';

export enum ModifierFlags {
None = 0x0000,
Expand Down Expand Up @@ -52,14 +51,6 @@ export abstract class UCFieldSymbol extends UCObjectSymbol {
public modifiers: ModifierFlags = ModifierFlags.None;
public next?: UCFieldSymbol = undefined;

constructor(id: Identifier, private readonly range: Range = id.range) {
super(id);
}

override getRange(): Range {
return this.range;
}

getType(): ITypeSymbol | undefined {
return undefined;
}
Expand All @@ -82,17 +73,6 @@ export abstract class UCFieldSymbol extends UCObjectSymbol {
return this.getPath();
}

override getSymbolAtPos(position: Position) {
if (!intersectsWith(this.getRange(), position)) {
return undefined;
}

if (intersectsWithRange(position, this.id.range)) {
return this;
}
return this.getContainedSymbolAtPos(position);
}

getCompletionContext(_position: Position): ISymbol | undefined {
return undefined;
}
Expand All @@ -109,10 +89,6 @@ export abstract class UCFieldSymbol extends UCObjectSymbol {
return (this.modifiers & ModifierFlags.WithDimension) === ModifierFlags.WithDimension;
}

override acceptCompletion(_document: UCDocument, _context: ISymbol): boolean {
return true;
}

override index(document: UCDocument, _context: UCStructSymbol) {
if ((this.modifiers & ModifierFlags.NoDeclaration) == 0) indexDeclarationReference(this, document);
}
Expand Down
23 changes: 13 additions & 10 deletions server/src/UC/Symbols/ISymbol.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { Location, Position, Range } from 'vscode-languageserver-types';

import { UCDocument } from '../document';
import { Name } from '../name';
import { SymbolWalker } from '../symbolWalker';
import { ITypeSymbol, UCNodeKind, UCStructSymbol, UCSymbolKind, UCTypeKind, typeKindToDisplayString } from './';
import { ITypeSymbol, UCNodeKind, UCSymbolKind, UCTypeKind, typeKindToDisplayString } from './';

export type Identifier = Readonly<{
readonly name: Name;
readonly range: Range;
}>;

export interface INode {
export interface IRange {
/**
* Encompassing range of the node in a document.
*
* TODO: Flatten and simplify boundaries.
**/
readonly range: Range;
}

export interface INode extends IRange {
readonly kind: UCNodeKind;
}

export interface ISymbol {
export interface ISymbol extends IRange {
readonly kind: UCSymbolKind;
readonly id: Identifier;

Expand All @@ -31,7 +39,6 @@ export interface ISymbol {
getName(): Name;
getHash(): number;

getRange(): Range;
/**
* Returns a path presented in a qualified identifier format.
* e.g. "Core.Object.Outer".
Expand Down Expand Up @@ -83,10 +90,6 @@ export interface IWithInnerSymbols {
getSymbolAtPos(position: Position): ISymbol | undefined;
}

export interface IWithIndex {
index(document: UCDocument, context: UCStructSymbol, info?: ContextInfo): void;
}

/**
* Returns the outer of a symbol that matches the kind.
*
Expand Down Expand Up @@ -144,7 +147,7 @@ export function getSymbolDebugInfo(symbol?: ISymbol): string {
return 'null';
}

const range = symbol.getRange();
const range = symbol.range;
const path = symbol.getName().text;
return `(${range.start.line + 1}:${range.start.character} - ${range.end.line + 1}:${range.end.character}) [${path}]: ${typeKindToDisplayString(symbol.getTypeKind())}`;
}
22 changes: 11 additions & 11 deletions server/src/UC/Symbols/IntrinsicSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import {
export * from './CoreSymbols';
export * from './EngineSymbols';

// HACK: Not truly an uc object, but since NativeArray has pseudo properties, it's a convenience to re-use the struct's features.
export const IntrinsicArray = new UCStructSymbol({ name: NAME_ARRAY, range: DEFAULT_RANGE });
// HACK: Not truly an uc object, but since NativeArray has pseudo properties, it's convenient to re-use the struct symbol features.
export const IntrinsicArray = new UCStructSymbol({ name: NAME_ARRAY, range: DEFAULT_RANGE }, DEFAULT_RANGE);
IntrinsicArray.modifiers |= ModifierFlags.Intrinsic;

export const Array_LengthProperty = new UCPropertySymbol({ name: toName('Length'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
Array_LengthProperty.modifiers |= ModifierFlags.Intrinsic;
IntrinsicArray.addSymbol(Array_LengthProperty);

const Array_InsertFunction = new UCMethodSymbol({ name: toName('Insert'), range: DEFAULT_RANGE });
const Array_InsertFunction = new UCMethodSymbol({ name: toName('Insert'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_InsertFunction.modifiers |= ModifierFlags.Intrinsic;
const IndexParam = new UCParamSymbol({ name: toName('Index'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
const CountParam = new UCParamSymbol({ name: toName('Count'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
Expand All @@ -38,7 +38,7 @@ Array_InsertFunction.addSymbol(CountParam);
Array_InsertFunction.params = [IndexParam, CountParam];
IntrinsicArray.addSymbol(Array_InsertFunction);

const Array_RemoveFunction = new UCMethodSymbol({ name: toName('Remove'), range: DEFAULT_RANGE });
const Array_RemoveFunction = new UCMethodSymbol({ name: toName('Remove'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_RemoveFunction.modifiers |= ModifierFlags.Intrinsic;
const IndexParam2 = new UCParamSymbol({ name: toName('Index'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
const CountParam2 = new UCParamSymbol({ name: toName('Count'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
Expand All @@ -47,21 +47,21 @@ Array_RemoveFunction.addSymbol(CountParam2);
Array_RemoveFunction.params = [IndexParam2, CountParam2];
IntrinsicArray.addSymbol(Array_RemoveFunction);

const Array_AddFunction = new UCMethodSymbol({ name: toName('Add'), range: DEFAULT_RANGE });
const Array_AddFunction = new UCMethodSymbol({ name: toName('Add'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_AddFunction.modifiers |= ModifierFlags.Intrinsic;
const CountParam3 = new UCParamSymbol({ name: toName('Count'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
Array_AddFunction.addSymbol(CountParam3);
Array_AddFunction.params = [CountParam3];
IntrinsicArray.addSymbol(Array_AddFunction);

const Array_AddItemFunction = new UCMethodSymbol({ name: toName('AddItem'), range: DEFAULT_RANGE });
const Array_AddItemFunction = new UCMethodSymbol({ name: toName('AddItem'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_AddItemFunction.modifiers |= ModifierFlags.Intrinsic;
const ItemParam = new UCParamSymbol({ name: toName('Item'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticMetaType);
Array_AddItemFunction.addSymbol(ItemParam);
Array_AddItemFunction.params = [ItemParam];
IntrinsicArray.addSymbol(Array_AddItemFunction);

const Array_InsertItemFunction = new UCMethodSymbol({ name: toName('InsertItem'), range: DEFAULT_RANGE });
const Array_InsertItemFunction = new UCMethodSymbol({ name: toName('InsertItem'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_InsertItemFunction.modifiers |= ModifierFlags.Intrinsic;
const IndexParam3 = new UCParamSymbol({ name: toName('Index'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticIntType);
const ItemParam2 = new UCParamSymbol({ name: toName('Item'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticMetaType);
Expand All @@ -70,21 +70,21 @@ Array_InsertItemFunction.addSymbol(ItemParam2);
Array_InsertItemFunction.params = [IndexParam3, ItemParam2];
IntrinsicArray.addSymbol(Array_InsertItemFunction);

const Array_RemoveItemFunction = new UCMethodSymbol({ name: toName('RemoveItem'), range: DEFAULT_RANGE });
const Array_RemoveItemFunction = new UCMethodSymbol({ name: toName('RemoveItem'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_RemoveItemFunction.modifiers |= ModifierFlags.Intrinsic;
const ItemParam3 = new UCParamSymbol({ name: toName('Item'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticMetaType);
Array_RemoveItemFunction.addSymbol(ItemParam3);
Array_RemoveItemFunction.params = [ItemParam3];
IntrinsicArray.addSymbol(Array_RemoveItemFunction);

const Array_FindFunction = new UCMethodSymbol({ name: toName('Find'), range: DEFAULT_RANGE });
const Array_FindFunction = new UCMethodSymbol({ name: toName('Find'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_FindFunction.modifiers |= ModifierFlags.Intrinsic | ModifierFlags.ReadOnly;
const ItemParam4 = new UCParamSymbol({ name: toName('Value'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticMetaType);
Array_FindFunction.addSymbol(ItemParam4);
Array_FindFunction.params = [ItemParam4];
IntrinsicArray.addSymbol(Array_FindFunction);

const Array_FindMemberFunction = new UCMethodSymbol({ name: toName('Find'), range: DEFAULT_RANGE });
const Array_FindMemberFunction = new UCMethodSymbol({ name: toName('Find'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_FindMemberFunction.modifiers |= ModifierFlags.Intrinsic | ModifierFlags.ReadOnly;
const ItemParam6 = new UCParamSymbol({ name: toName('PropertyName'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticNameType);
Array_FindMemberFunction.addSymbol(ItemParam6);
Expand All @@ -93,7 +93,7 @@ Array_FindMemberFunction.addSymbol(ItemParam7);
Array_FindMemberFunction.params = [ItemParam6, ItemParam7];
IntrinsicArray.addSymbol(Array_FindMemberFunction);

const Array_SortFunction = new UCMethodSymbol({ name: toName('Sort'), range: DEFAULT_RANGE });
const Array_SortFunction = new UCMethodSymbol({ name: toName('Sort'), range: DEFAULT_RANGE }, DEFAULT_RANGE);
Array_SortFunction.modifiers |= ModifierFlags.Intrinsic;
const PredicateParam = new UCParamSymbol({ name: toName('Predicate'), range: DEFAULT_RANGE }, DEFAULT_RANGE, StaticDelegateType);
Array_SortFunction.addSymbol(PredicateParam);
Expand Down
9 changes: 2 additions & 7 deletions server/src/UC/Symbols/MethodSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export enum MethodFlags {
OperatorKind = Operator | PreOperator | PostOperator,
HasKind = Function | OperatorKind | Event | Delegate,

NonOverridable = Final || PreOperator,
NonOverridable = Final | PreOperator,
}

export class UCMethodSymbol extends UCStructSymbol {
Expand Down Expand Up @@ -253,7 +253,7 @@ export class UCMethodLikeSymbol extends UCMethodSymbol {
override specifiers = MethodFlags.Static | MethodFlags.Final;

constructor(name: Name) {
super({ name, range: DEFAULT_RANGE });
super({ name, range: DEFAULT_RANGE }, DEFAULT_RANGE);
}

override getTypeKind() {
Expand Down Expand Up @@ -284,11 +284,6 @@ export class UCDelegateSymbol extends UCMethodSymbol {

export abstract class UCBaseOperatorSymbol extends UCMethodSymbol {
override kind = UCSymbolKind.Operator;

override acceptCompletion(_document: UCDocument, _context: ISymbol): boolean {
// TODO: Perhaps only list operators with a custom Identifier? i.e. "Dot" and "Cross".
return false;
}
}

export class UCBinaryOperatorSymbol extends UCBaseOperatorSymbol {
Expand Down
4 changes: 2 additions & 2 deletions server/src/UC/Symbols/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class UCPackage extends UCObjectSymbol {
override kind = UCSymbolKind.Package;

constructor(name: Name) {
super({ name, range: DEFAULT_RANGE });
super({ name, range: DEFAULT_RANGE }, DEFAULT_RANGE);
}

override getTypeKind() {
Expand Down Expand Up @@ -245,4 +245,4 @@ export function* enumerateObjects(): Generator<UCObjectSymbol, UCObjectSymbol[]>
}

return [];
}
}
Loading

0 comments on commit 3436a03

Please sign in to comment.