Skip to content

Commit

Permalink
Merge pull request #62 from sashi0034/feature/minor-fixes-25-01-04
Browse files Browse the repository at this point in the history
Feature/minor fixes 25 01 04
  • Loading branch information
sashi0034 authored Jan 4, 2025
2 parents 49c620b + 4dcb064 commit 38dcf9b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
41 changes: 32 additions & 9 deletions server/src/compile/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
ResolvedType,
SymbolFunction,
SymbolKind,
SymbolObject,
SymbolScope,
SymbolType,
SymbolVariable
Expand Down Expand Up @@ -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)[];

Expand Down Expand Up @@ -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<SymbolFunction> = {...superConstructor};

const declaredPlace: Mutable<ParsedToken> = createVirtualToken(TokenKind.Identifier, 'super');
declaredPlace.location = {...superSymbol.declaredPlace.location};

superSymbol.declaredPlace = declaredPlace;
insertSymbolObject(scope.symbolMap, superSymbol);
}
});
});

pushHintOfCompletionScopeToParent(parentScope, scope, nodeClass.nodeRange);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/src/compile/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/test/compile/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38dcf9b

Please sign in to comment.