Skip to content

Commit

Permalink
Merge pull request #59 from sashi0034/feature/propery-mode
Browse files Browse the repository at this point in the history
Support 'property' modifier
  • Loading branch information
sashi0034 authored Jan 3, 2025
2 parents 8f20144 + eb9a1a9 commit 49c620b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
"default": false,
"description": "Hoist enums to their parents scope."
},
"angelScript.explicitPropertyAccessor": {
"scope": "window",
"type": "boolean",
"default": true,
"description": "Controls whether the 'property' keyword is required for virtual property accessors. When set to true, functions must explicitly use the 'property' keyword to be treated as property accessors. When false, compatibility mode for AngelScript prior to v2.33.1 is enabled, and functions with 'get_' or 'set_' prefixes are automatically treated as property accessors."
},
"angelScript.formatter.maxBlankLines": {
"scope": "window",
"type": "number",
Expand Down
2 changes: 2 additions & 0 deletions server/src/code/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export interface LanguageServerSettings {
implicitMutualInclusion: boolean;
hoistEnumParentScope: boolean;
explicitPropertyAccessor: boolean;
builtinStringTypes: string[];
builtinArrayType: string,
formatter: {
Expand All @@ -20,6 +21,7 @@ export interface LanguageServerSettings {
const defaultSettings: LanguageServerSettings = {
implicitMutualInclusion: false,
hoistEnumParentScope: false,
explicitPropertyAccessor: false,
builtinStringTypes: ["string", "String"],
builtinArrayType: "array",
formatter: {
Expand Down
25 changes: 24 additions & 1 deletion server/src/compile/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import {
import {Mutable} from "../utils/utilities";
import {getGlobalSettings} from "../code/settings";
import assert = require("node:assert");
import {createVirtualToken} from "./tokenUtils";

type HoistingQueue = (() => void)[];

Expand Down Expand Up @@ -324,11 +325,12 @@ function hoistFunc(
) {
if (nodeFunc.head === funcHeadDestructor) return;

const returnType = isFunctionHeadReturnValue(nodeFunc.head) ? analyzeType(parentScope, nodeFunc.head.returnType) : undefined;
const symbol: Mutable<SymbolFunction> = {
symbolKind: SymbolKind.Function,
declaredPlace: nodeFunc.identifier,
declaredScope: parentScope,
returnType: isFunctionHeadReturnValue(nodeFunc.head) ? analyzeType(parentScope, nodeFunc.head.returnType) : undefined,
returnType: returnType,
parameterTypes: [],
sourceNode: nodeFunc,
nextOverload: undefined,
Expand All @@ -337,6 +339,27 @@ function hoistFunc(
};
if (insertSymbolObject(parentScope.symbolMap, symbol) === false) return;

// Check if the function is a virtual property setter or getter
if (nodeFunc.identifier.text.startsWith('get_') || nodeFunc.identifier.text.startsWith('set_')) {
if (nodeFunc.funcAttr?.isProperty === true || getGlobalSettings().explicitPropertyAccessor === false) {
const identifier: Mutable<ParsedToken> = createVirtualToken(TokenKind.Identifier, nodeFunc.identifier.text.substring(4));
identifier.location = nodeFunc.identifier.location;

const symbol: SymbolVariable = {
symbolKind: SymbolKind.Variable,
declaredPlace: identifier, // FIXME?
declaredScope: parentScope,
type: returnType,
isInstanceMember: isInstanceMember,
accessRestriction: nodeFunc.accessor,
};
tryInsertSymbolObject(parentScope.symbolMap, symbol);
}
} else if (nodeFunc.funcAttr?.isProperty === true) {
diagnostic.addError(nodeFunc.identifier.location, 'Property accessor must start with "get_" or "set_"');
}

// Create a new scope for the function
const scope: SymbolScope = createSymbolScopeAndInsert(nodeFunc, parentScope, nodeFunc.identifier.text);

hoisting.push(() => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/compile/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export interface SymbolAndScope {
*/
export interface ResolvedType {
readonly symbolType: SymbolType | SymbolFunction;
readonly sourceScope: SymbolScope | undefined;
readonly sourceScope: SymbolScope | undefined; // FIXME: Obsolete? Use symbolType.declaredScope instead.
readonly isHandler?: boolean;
readonly templateTranslate?: TemplateTranslation;
}

0 comments on commit 49c620b

Please sign in to comment.