Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"mocha": "^11.1.0",
"multer": "^1.4.5-lts.1",
"opener": "^1.5.2",
"prettier": "^3.5.2",
"rimraf": "^6.0.1",
"rollup": "^4.34.8",
"rollup-plugin-copy": "^3.5.0",
Expand Down
4 changes: 3 additions & 1 deletion scripts/setup-playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const fs = require('fs-extra');
import fs from 'fs-extra';
import url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const src = `${__dirname}/../playground-template`
const dest = `${__dirname}/../playground`
fs.copySync(src, dest, { overwrite: false });
2 changes: 1 addition & 1 deletion src.compiler/csharp/CSharpAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ export interface ParameterDeclaration extends NamedElement, Node, DocumentedElem
type?: TypeNode;
initializer?: Expression;
params: boolean;
isOptional: boolean;
}

// Type System

export interface TypeNode extends Node {
isNullable?: boolean;
isOptional?: boolean;
}

export interface UnresolvedTypeNode extends TypeNode {
Expand Down
6 changes: 3 additions & 3 deletions src.compiler/csharp/CSharpAstPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default class CSharpAstPrinter extends AstPrinterBase {
if (p.initializer) {
this.write(' = ');
this.writeExpression(p.initializer);
} else if (p.type && p.type.isOptional) {
} else if (p.type && p.isOptional) {
this.write(' = default');
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ export default class CSharpAstPrinter extends AstPrinterBase {
nodeType: cs.SyntaxKind.Identifier,
text: p.name,
tsNode: defaultConstructor.tsNode
} as cs.Identifier)
}) as cs.Identifier
);
this.writeMember(defaultConstructor);
}
Expand Down Expand Up @@ -660,7 +660,7 @@ export default class CSharpAstPrinter extends AstPrinterBase {
this.write('TODO: ' + cs.SyntaxKind[type.nodeType]);
break;
}
if (type.isNullable && !forNew && !forTypeConstraint) {
if ((type.isNullable) && !forNew && !forTypeConstraint) {
this.write('?');
}
}
Expand Down
17 changes: 8 additions & 9 deletions src.compiler/csharp/CSharpAstTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ export default class CSharpAstTransformer {

parent.members.push(csMethod);
this._context.registerSymbol(csMethod);

return csMethod;
}

protected visitTestMethod(parent: cs.ClassDeclaration, d: ts.CallExpression) {
Expand Down Expand Up @@ -1861,6 +1863,10 @@ export default class CSharpAstTransformer {
];
}

if (s.finallyBlock) {
tryStatement.finallyBlock = this.visitBlock(tryStatement, s.finallyBlock);
}

return tryStatement;
}

Expand Down Expand Up @@ -1967,23 +1973,16 @@ export default class CSharpAstTransformer {
parent: csMethod,
type: this.createUnresolvedTypeNode(null, p.type ?? p, type),
tsNode: p,
params: !!p.dotDotDotToken
params: !!p.dotDotDotToken,
isOptional: !!p.questionToken
};
csParameter.type!.parent = csParameter;

if (p.questionToken) {
csParameter.type!.isOptional = true;
}

if (p.initializer) {
csParameter.initializer = this.visitExpression(csParameter, p.initializer) ?? undefined;
if (csParameter.initializer && cs.isNullLiteral(csParameter.initializer)) {
csParameter.type!.isNullable = true;
}
} else if (csParameter.type!.isOptional) {
if (this._context.isDefaultValueNull(type)) {
csParameter.type!.isNullable = true;
}
}

if (p.name) {
Expand Down
28 changes: 8 additions & 20 deletions src.compiler/csharp/CSharpEmitterContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,13 @@ export default class CSharpEmitterContext {
}

if (resolved) {
const wasOptional = node.isOptional;
const wasNullable = node.isNullable;
for (const prop of Object.getOwnPropertyNames(node)) {
delete (node as any)[prop];
}
for (const prop of Object.getOwnPropertyNames(resolved)) {
(node as any)[prop] = (resolved as any)[prop];
}
if (wasOptional) {
node.isOptional = true;
}
if (wasNullable) {
node.isNullable = true;
}
Expand Down Expand Up @@ -618,26 +614,23 @@ export default class CSharpEmitterContext {
// external union type alias, refer by name
if (!tsType.symbol && tsType.aliasSymbol) {
let isNullable = false;
let isOptional = false;
for (let t of tsType.types) {
if ((t.flags & ts.TypeFlags.Null) !== 0) {
isNullable = true;
} else if ((t.flags & ts.TypeFlags.Undefined) !== 0) {
isOptional = true;
isNullable = true;
}
}

return {
nodeType: cs.SyntaxKind.TypeReference,
parent: parent,
reference: this.buildCoreNamespace(tsType.aliasSymbol) + tsType.aliasSymbol.name,
isNullable: isNullable,
isOptional: isOptional
isNullable: isNullable
} as cs.TypeReference;
}

let isNullable = false;
let isOptional = false;
let actualType: ts.Type | null = null;
let fallbackToObject = false;
for (let t of tsType.types) {
Expand All @@ -648,7 +641,7 @@ export default class CSharpEmitterContext {
if ((t.flags & ts.TypeFlags.Null) !== 0) {
isNullable = true;
} else if ((t.flags & ts.TypeFlags.Undefined) !== 0) {
isOptional = true;
isNullable = true;
} else if (actualType == null) {
actualType = t;
} else if (actualType != null && actualType.flags !== t.flags) {
Expand All @@ -671,8 +664,7 @@ export default class CSharpEmitterContext {
nodeType: cs.SyntaxKind.PrimitiveTypeNode,
parent: parent,
type: cs.PrimitiveType.Object,
isNullable: isNullable,
isOptional: isOptional
isNullable: isNullable
} as cs.PrimitiveTypeNode;
}

Expand All @@ -686,8 +678,7 @@ export default class CSharpEmitterContext {
nodeType: cs.SyntaxKind.TypeReference,
parent: parent,
reference: tsType.symbol.name,
isNullable: isNullable,
isOptional: isOptional
isNullable: isNullable
} as cs.TypeReference;
} else {
type = this.getTypeFromTsType(parent, actualType, undefined, typeArguments);
Expand All @@ -697,8 +688,7 @@ export default class CSharpEmitterContext {
nodeType: cs.SyntaxKind.TypeReference,
parent: parent,
reference: type,
isNullable: isNullable,
isOptional: isOptional
isNullable: isNullable
} as cs.TypeReference;
}

Expand All @@ -725,22 +715,20 @@ export default class CSharpEmitterContext {
private resolvePrimitiveType(parent: cs.Node, tsType: ts.Type): cs.TypeNode | null {
const handleNullablePrimitive = (type: cs.PrimitiveType) => {
let isNullable = false;
let isOptional = false;
if (tsType.isUnion()) {
for (const t of tsType.types) {
if ((t.flags & ts.TypeFlags.Null) !== 0) {
isNullable = true;
} else if ((t.flags & ts.TypeFlags.Undefined) !== 0) {
isOptional = true;
isNullable = true;
}
}
}

return {
nodeType: cs.SyntaxKind.PrimitiveTypeNode,
type: type,
isNullable: isNullable,
isOptional: isOptional
isNullable: isNullable
} as cs.PrimitiveTypeNode;
};

Expand Down
34 changes: 22 additions & 12 deletions src.compiler/kotlin/KotlinAstPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ export default class KotlinAstPrinter extends AstPrinterBase {
if (p.type) {
this.write(': ');
if (p.params) {
this.writeType((p.type as cs.ArrayTypeNode).elementType, false, false);
this.writeType((p.type as cs.ArrayTypeNode).elementType, false, false, false, true, false);
} else {
this.writeType(p.type, false);
this.writeType(p.type, false, false, false, true, false);
}
}
if (!this.isOverrideMethod(p.parent!)) {
if (p.initializer) {
this.write(' = ');
this.writeExpression(p.initializer);
} else if (p.type && p.type.isOptional) {
} else if (p.type && p.isOptional) {
let type: cs.TypeNode = p.type;
if (cs.isTypeReference(p.type)) {
type = p.type.reference as cs.TypeNode;
Expand Down Expand Up @@ -582,23 +582,32 @@ export default class KotlinAstPrinter extends AstPrinterBase {
this.write(': ');
this.writeType(d.type);

let initializerWritten = false;
if (d.initializer && !isLateInit) {
this.write(' = ');
this.writeExpression(d.initializer);
initializerWritten = true;
this.writeLine();
} else if (writeAsField) {
this.writeLine();
}

if (!writeAsField && !isAutoProperty) {
this.writeLine();

if (d.getAccessor) {
this.writePropertyAccessor(d.getAccessor);
if (!writeAsField) {
if(isAutoProperty && d.type.isNullable && !initializerWritten &&
d.parent!.nodeType !== cs.SyntaxKind.InterfaceDeclaration
) {
this.write(' = null');
}
this.writeLine();

if (d.setAccessor) {
this.writePropertyAccessor(d.setAccessor);
if(!isAutoProperty) {
if (d.getAccessor) {
this.writePropertyAccessor(d.getAccessor);
}

if (d.setAccessor) {
this.writePropertyAccessor(d.setAccessor);
}
}
}
}
Expand Down Expand Up @@ -662,7 +671,8 @@ export default class KotlinAstPrinter extends AstPrinterBase {
forNew: boolean = false,
asNativeArray: boolean = false,
forTypeConstraint: boolean = false,
allowPromise: boolean = true
allowPromise: boolean = true,
optionalAsNullable: boolean = true
) {
switch (type.nodeType) {
case cs.SyntaxKind.PrimitiveTypeNode:
Expand Down Expand Up @@ -828,7 +838,7 @@ export default class KotlinAstPrinter extends AstPrinterBase {
this.write('TODO: ' + cs.SyntaxKind[type.nodeType]);
break;
}
if ((type.isNullable || type.isOptional) && !forNew && !forTypeConstraint) {
if ((type.isNullable) && !forNew && !forTypeConstraint) {
this.write('?');
}
}
Expand Down
18 changes: 18 additions & 0 deletions src.compiler/kotlin/KotlinAstTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,24 @@ export default class KotlinAstTransformer extends CSharpAstTransformer {
return func;
}


protected override visitTestClassMethod(parent: cs.ClassDeclaration, d: ts.FunctionDeclaration) {
this._paramReferences.push(new Map<string, cs.Identifier[]>());
this._paramsWithAssignment.push(new Set<string>());

const method = super.visitTestClassMethod(parent, d);

if (method.body && cs.isBlock(method.body)) {
this.injectParametersAsLocal(method.body);
}

this._paramReferences.pop();
this._paramsWithAssignment.pop();

return method;
}


protected override visitMethodDeclaration(
parent: cs.ClassDeclaration | cs.InterfaceDeclaration,
classElement: ts.MethodDeclaration
Expand Down
11 changes: 4 additions & 7 deletions src.csharp/AlphaTab/Platform/CSharp/GdiCanvas.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AlphaTab.Model;
using AlphaTab.Rendering.Glyphs;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -473,8 +472,7 @@ public TextMetrics MeasureText(string text)
}

public void FillMusicFontSymbol(double x, double y, double scale, MusicFontSymbol symbol,
bool centerAtPosition =
false)
bool? centerAtPosition = false)
{
if (symbol == MusicFontSymbol.None)
{
Expand All @@ -489,13 +487,12 @@ public void FillMusicFontSymbol(double x, double y, double scale, MusicFontSymbo

_graphics.DrawString(String.FromCharCode((int)symbol), GetMusicFont(scale),
_brush, (float)x, (float)y,
centerAtPosition ? MusicFontFormatCenter : MusicFontFormat);
centerAtPosition.GetValueOrDefault() ? MusicFontFormatCenter : MusicFontFormat);
}

public void FillMusicFontSymbols(double x, double y, double scale,
IList<MusicFontSymbol> symbols,
bool centerAtPosition
= false)
bool? centerAtPosition = false)
{
var s = "";
foreach (var symbol in symbols)
Expand All @@ -513,7 +510,7 @@ bool centerAtPosition
x += scale;

_graphics.DrawString(s, GetMusicFont(scale), _brush, (float)x, (float)y,
centerAtPosition ? MusicFontFormatCenter : MusicFontFormat);
centerAtPosition.GetValueOrDefault() ? MusicFontFormatCenter : MusicFontFormat);
}

public void BeginRotate(double centerX, double centerY, double angle)
Expand Down
Loading