From 2535c63bd7fb24fe662e5827e4bd54fe39157627 Mon Sep 17 00:00:00 2001 From: sashi Date: Sat, 4 Jan 2025 09:41:03 +0900 Subject: [PATCH 1/2] Fixed a bug in tokenizing floating point --- server/src/compile/tokenizer.ts | 2 +- server/test/compile/parser.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/compile/tokenizer.ts b/server/src/compile/tokenizer.ts index 47054f0..49ee807 100644 --- a/server/src/compile/tokenizer.ts +++ b/server/src/compile/tokenizer.ts @@ -151,7 +151,7 @@ function consumeNumber(tokenizer: TokenizerState) { numeric = NumberLiterals.Double; } - if (f > 1) { + if (f >= 1) { tokenizer.stepFor(f); // Check half precision floating point diff --git a/server/test/compile/parser.spec.ts b/server/test/compile/parser.spec.ts index 1517920..c48c656 100644 --- a/server/test/compile/parser.spec.ts +++ b/server/test/compile/parser.spec.ts @@ -25,7 +25,7 @@ function itParses(content: string) { describe("Parser", () => { itParses("void foo() {}"); - itParses("int MyValue = 0;"); + itParses("int MyValue = 0; float MyFloat = 15.f;"); itParses("const uint Flag1 = 0x01;"); itParses(` class Foo From 4dcb06468fba7597402c597c13ee5eb549abab17 Mon Sep 17 00:00:00 2001 From: sashi Date: Sat, 4 Jan 2025 10:58:22 +0900 Subject: [PATCH 2/2] Support for 'super' --- server/src/compile/analyzer.ts | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/server/src/compile/analyzer.ts b/server/src/compile/analyzer.ts index e3ca084..1fb0fcc 100644 --- a/server/src/compile/analyzer.ts +++ b/server/src/compile/analyzer.ts @@ -59,6 +59,7 @@ import { ResolvedType, SymbolFunction, SymbolKind, + SymbolObject, SymbolScope, SymbolType, SymbolVariable @@ -106,8 +107,8 @@ import { } from "./symbolUtils"; import {Mutable} from "../utils/utilities"; import {getGlobalSettings} from "../code/settings"; -import assert = require("node:assert"); import {createVirtualToken} from "./tokenUtils"; +import assert = require("node:assert"); type HoistingQueue = (() => void)[]; @@ -218,12 +219,30 @@ function hoistClass(parentScope: SymbolScope, nodeClass: NodeClass, analyzing: A const templateTypes = hoistClassTemplateTypes(scope, nodeClass.typeTemplates); if (templateTypes.length > 0) symbol.templateTypes = templateTypes; - const baseList = hoistBaseList(scope, nodeClass); - if (baseList !== undefined) symbol.baseList = baseList; + symbol.baseList = hoistBaseList(scope, nodeClass); hoisting.push(() => { hoistClassMembers(scope, nodeClass, analyzing, hoisting); - if (baseList !== undefined) copyBaseMembers(scope, baseList); + + hoisting.push(() => { + if (symbol.baseList === undefined) return; + + // Copy the members of the base class + copyBaseMembers(scope, symbol.baseList); + + // Check to insert the super constructor + const primeBase = symbol.baseList.length >= 1 ? symbol.baseList[0] : undefined; + const superConstructor = findConstructorForResolvedType(primeBase); + if (superConstructor?.symbolKind === SymbolKind.Function) { + const superSymbol: Mutable = {...superConstructor}; + + const declaredPlace: Mutable = createVirtualToken(TokenKind.Identifier, 'super'); + declaredPlace.location = {...superSymbol.declaredPlace.location}; + + superSymbol.declaredPlace = declaredPlace; + insertSymbolObject(scope.symbolMap, superSymbol); + } + }); }); pushHintOfCompletionScopeToParent(parentScope, scope, nodeClass.nodeRange); @@ -1095,11 +1114,7 @@ function analyzeConstructorCaller( callerArgList: NodeArgList, constructorType: ResolvedType ): ResolvedType | undefined { - const constructorIdentifier = constructorType.symbolType.declaredPlace.text; - if (constructorType.sourceScope === undefined) return undefined; - - const classScope = findScopeShallowly(constructorType.sourceScope, constructorIdentifier); - const constructor = classScope !== undefined ? findSymbolShallowly(classScope, constructorIdentifier) : undefined; + const constructor = findConstructorForResolvedType(constructorType); if (constructor === undefined || constructor.symbolKind !== SymbolKind.Function) { return analyzeBuiltinConstructorCaller(scope, callerIdentifier, callerArgList, constructorType); } @@ -1108,6 +1123,14 @@ function analyzeConstructorCaller( return constructorType; } +function findConstructorForResolvedType(resolvedType: ResolvedType | undefined): SymbolObject | undefined { + if (resolvedType?.sourceScope === undefined) return undefined; + + const constructorIdentifier = resolvedType.symbolType.declaredPlace.text; + const classScope = findScopeShallowly(resolvedType.sourceScope, constructorIdentifier); + return classScope !== undefined ? findSymbolShallowly(classScope, constructorIdentifier) : undefined; +} + function analyzeBuiltinConstructorCaller( scope: SymbolScope, callerIdentifier: ParsedToken,