Skip to content

Commit

Permalink
Merge pull request #211 from rayshader/feat/207-dump-const-flag
Browse files Browse the repository at this point in the history
Dump and show const flag in function's argument
  • Loading branch information
poirierlouis authored Nov 18, 2024
2 parents f57485e + 7cdea20 commit 2bb8bbb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
@if (node) {
@switch (syntax) {
@case (cpp) {
<!--
@if (node.isConst) {
<span class="stx-lang">const&nbsp;</span>
}
-->
@if (node.isOptional) {
<span class="stx-lang">Optional</span>
<span class="stx-type"><</span>
Expand All @@ -21,11 +19,9 @@
<span class="stx-arg">&nbsp;{{node.name}}</span>
}
@default {
<!--
@if (node.isConst) {
<span class="stx-lang">const&nbsp;</span>
}
-->
@if (node.isOut) {
<span class="stx-lang">out&nbsp;</span>
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/reddump/classes.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/assets/reddump/globals.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/shared/formatters/redscript.formatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('RedscriptFormatter', () => {
false,
RedVisibilityDef.public,
[
AstHelper.buildArg('a', AstHelper.Float),
AstHelper.buildArg('a', AstHelper.Float, false, false, true),
AstHelper.buildArg('b', AstHelper.buildStruct('Vector4'), false, true),
AstHelper.buildArg('c', AstHelper.buildRef('WeaponObject'), true),
]
Expand All @@ -220,7 +220,7 @@ describe('RedscriptFormatter', () => {
const code: string = fmt.formatPrototype(func);

// THEN
expect(code).toBe('Fake(a: Float, out b: Vector4, opt c: ref<WeaponObject>) -> array<wref<GameObject>>');
expect(code).toBe('Fake(const a: Float, out b: Vector4, opt c: ref<WeaponObject>) -> array<wref<GameObject>>');
});
});

Expand Down
10 changes: 6 additions & 4 deletions src/shared/red-ast/red-argument.ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {RedTypeAst} from "./red-type.ast";
import {CodeSyntax} from "../services/settings.service";

export interface RedArgumentAst {
//readonly isConst: boolean;
readonly isConst: boolean;
readonly isOut: boolean;
readonly isOptional: boolean;
readonly name: string;
Expand All @@ -14,7 +14,9 @@ export class RedArgumentAst {
static toString(argument: RedArgumentAst, syntax?: CodeSyntax): string {
let flag: string = '';

if (argument.isOut) {
if (argument.isConst) {
flag = 'const ';
} else if (argument.isOut) {
flag = 'out ';
} else if (argument.isOptional) {
flag = 'opt ';
Expand All @@ -23,10 +25,10 @@ export class RedArgumentAst {
}

static fromJson(json: RedPropertyJson): RedArgumentAst {
const flags: number = json.c;
const flags: number = json.c === undefined ? 0 : json.c;

return {
//isConst: ((flags >> RedArgumentFlags.isConst) & 1) !== 0,
isConst: ((flags >> RedArgumentFlags.isConst) & 1) !== 0,
isOut: ((flags >> RedArgumentFlags.isOut) & 1) !== 0,
isOptional: ((flags >> RedArgumentFlags.isOptional) & 1) !== 0,
name: json.b ?? '',
Expand Down
4 changes: 2 additions & 2 deletions src/shared/red-ast/red-property.ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {cyrb53} from "../string";
export interface RedPropertyJson {
readonly a: RedTypeJson; // type
readonly b?: string; // name
readonly c: number; // flags
readonly c?: number; // flags
readonly d?: number; // offset
}

Expand Down Expand Up @@ -58,7 +58,7 @@ export class RedPropertyAst {
}

static fromJson(json: RedPropertyJson): RedPropertyAst {
const flags: number = json.c;
const flags: number = json.c === undefined ? 0 : json.c;
const name: string = json.b ?? '';

return {
Expand Down
4 changes: 3 additions & 1 deletion tests/ast.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export class AstHelper {
static buildArg(name: string,
type: RedTypeAst | string,
isOptional: boolean = false,
isOut: boolean = false): RedArgumentAst {
isOut: boolean = false,
isConst: boolean = false): RedArgumentAst {
let argType: RedTypeAst | undefined;

if (typeof type === 'string') {
Expand All @@ -119,6 +120,7 @@ export class AstHelper {
return {
name: name,
type: argType,
isConst: isConst,
isOptional: isOptional,
isOut: isOut
};
Expand Down

0 comments on commit 2bb8bbb

Please sign in to comment.