Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Haxe-Cpp synchronized blocks & methods support + Thread improvements …
Browse files Browse the repository at this point in the history
…in all targets + Kotlin 1.1.4-2 (#264)

* Haxe-Cpp synchronized blocks support + Thread improvements in all targets + Kotlin 1.1.4-2

* Small fix

* Extract modifier convenience properties

* Add synchronized method test

* Remove old comments

* Use new modifier shortcuts + reformat

* Support synchronized methods in haxe

* Initial common synchronized method support

* Complete unification of synchronized method support for targets supporting finally

* Fixed C# target

* Initial C# Thread support

* Do not reference System.out or System.err if possible

* Revert "Do not reference System.out or System.err if possible"

This reverts commit f245c2f

* Test threads on D target
  • Loading branch information
soywiz authored Aug 26, 2017
1 parent 4670454 commit 3fa03ca
Show file tree
Hide file tree
Showing 33 changed files with 879 additions and 510 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jtranscVersion=0.6.7
kotlinVersion=1.1.4
kotlinVersion=1.1.4-2
file.encoding=UTF-8
kotlin.incremental=true
org.gradle.daemon=true
Expand Down
96 changes: 50 additions & 46 deletions jtransc-core/src/com/jtransc/ast/ast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ class AstClass(
val source: String,
program: AstProgram,
val name: FqName,
val modifiers: AstModifiers,
override val modifiers: AstModifiers,
val extending: FqName? = null,
val implementing: List<FqName> = listOf(),
annotations: List<AstAnnotation> = listOf(),
val classId: Int = program.lastClassId++
) : AstAnnotatedElement(program, name.ref, annotations), IUserData by UserData() {
) : AstAnnotatedElement(program, name.ref, annotations), IUserData by UserData(), WithAstModifiersClass {
val types get() = program.types

val implementingUnique by lazy { implementing.distinct() }
Expand Down Expand Up @@ -680,14 +680,14 @@ class AstField(
val id: Int = containingClass.program.lastFieldId++,
name: String,
type: AstType,
val modifiers: AstModifiers,
override val modifiers: AstModifiers,
val desc: String,
annotations: List<AstAnnotation>,
val genericSignature: String?,
val constantValue: Any? = null,
val types: AstTypes,
override val ref: AstFieldRef = AstFieldRef(containingClass.name, name, type)
) : AstMember(containingClass, name, type, if (genericSignature != null) types.demangle(genericSignature) else type, modifiers.isStatic, modifiers.visibility, ref, annotations), FieldRef {
) : AstMember(containingClass, name, type, if (genericSignature != null) types.demangle(genericSignature) else type, modifiers.isStatic, modifiers.visibility, ref, annotations), FieldRef, WithAstModifiersField {
val uniqueName = containingClass.uniqueNames.alloc(name)
val isFinal: Boolean = modifiers.isFinal
val refWithoutClass: AstFieldWithoutClassRef by lazy { AstFieldWithoutClassRef(this.name, this.type) }
Expand All @@ -711,7 +711,7 @@ class AstMethod constructor(
val signature: String,
val genericSignature: String?,
val defaultTag: Any?,
val modifiers: AstModifiers,
override val modifiers: AstModifiers,
var generateBody: () -> AstBody?,
val bodyRef: AstMethodRef? = null,
val parameterAnnotations: List<List<AstAnnotation>> = listOf(),
Expand All @@ -721,7 +721,7 @@ class AstMethod constructor(
containingClass, name, methodType,
if (genericSignature != null) containingClass.types.demangleMethod(genericSignature) else methodType,
modifiers.isStatic, modifiers.visibility, ref, annotations
), MethodRef {
), MethodRef, WithAstModifiersMethod {
val types: AstTypes get() = program.types

val parameterAnnotationsList: List<AstAnnotationList> = parameterAnnotations.map { AstAnnotationList(ref, it) }
Expand All @@ -736,8 +736,6 @@ class AstMethod constructor(
}
}

val isNative: Boolean = modifiers.isNative

private var generatedBody: Boolean = false
private var generatedBodyBody: AstBody? = null

Expand Down Expand Up @@ -845,8 +843,19 @@ val AstMethodRef.isInstanceInit: Boolean get() = name == "<init>"
val AstMethodRef.isClassInit: Boolean get() = name == "<clinit>"
val AstMethodRef.isClassOrInstanceInit: Boolean get() = isInstanceInit || isClassInit

interface WithAstModifiers {
val modifiers: AstModifiers
}

interface WithAstModifiersMember : WithAstModifiers
interface WithAstModifiersMethod : WithAstModifiersMember
interface WithAstModifiersField : WithAstModifiersMember
interface WithAstModifiersParameter : WithAstModifiers
interface WithAstModifiersClass : WithAstModifiers

@Suppress("unused")
data class AstModifiers(val acc: Int) {
data class AstModifiers(val acc: Int) : WithAstModifiersMethod, WithAstModifiersField, WithAstModifiersClass, WithAstModifiersParameter {
override val modifiers = this
companion object {
fun withFlags(vararg flags: Int): AstModifiers {
var out = 0
Expand Down Expand Up @@ -875,43 +884,6 @@ data class AstModifiers(val acc: Int) {
const val ACC_MANDATED = 0x8000 // parameter
}

val isPublic: Boolean get() = acc hasFlag ACC_PUBLIC
val isPrivate: Boolean get() = acc hasFlag ACC_PRIVATE
val isProtected: Boolean get() = acc hasFlag ACC_PROTECTED
val isStatic: Boolean get() = acc hasFlag ACC_STATIC
val isFinal: Boolean get() = acc hasFlag ACC_FINAL
val isSuper: Boolean get() = acc hasFlag ACC_SUPER
val isSynchronized: Boolean get() = acc hasFlag ACC_SYNCHRONIZED
val isVolatile: Boolean get() = acc hasFlag ACC_VOLATILE
val isBridge: Boolean get() = acc hasFlag ACC_BRIDGE
val isVarargs: Boolean get() = acc hasFlag ACC_VARARGS
val isTransient: Boolean get() = acc hasFlag ACC_TRANSIENT
val isNative: Boolean get() = acc hasFlag ACC_NATIVE
val isInterface: Boolean get() = acc hasFlag ACC_INTERFACE
val isAbstract: Boolean get() = acc hasFlag ACC_ABSTRACT
val isStrict: Boolean get() = acc hasFlag ACC_STRICT
val isSynthetic: Boolean get() = acc hasFlag ACC_SYNTHETIC
val isAnnotation: Boolean get() = acc hasFlag ACC_ANNOTATION
val isEnum: Boolean get() = acc hasFlag ACC_ENUM
val isMandated: Boolean get() = acc hasFlag ACC_MANDATED
val isConcrete: Boolean get() = !isNative && !isAbstract

val visibility: AstVisibility get() = if (isPublic) {
AstVisibility.PUBLIC
} else if (isProtected) {
AstVisibility.PROTECTED
} else {
AstVisibility.PRIVATE
}

val classType: AstClassType get() = if (isInterface) {
AstClassType.INTERFACE
} else if (isAbstract) {
AstClassType.ABSTRACT
} else {
AstClassType.CLASS
}

fun with(flags: Int) = AstModifiers(this.acc or flags)
fun without(flags: Int) = AstModifiers(this.acc and flags.inv())

Expand All @@ -927,6 +899,38 @@ data class AstModifiers(val acc: Int) {
override fun toString(): String = "$acc"
}

val WithAstModifiers.isPublic: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_PUBLIC
val WithAstModifiers.isPrivate: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_PRIVATE
val WithAstModifiers.isProtected: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_PROTECTED
val WithAstModifiersMember.isStatic: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_STATIC
val WithAstModifiers.isFinal: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_FINAL
val WithAstModifiersMethod.isSynchronized: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_SYNCHRONIZED
val WithAstModifiersField.isVolatile: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_VOLATILE
val WithAstModifiersMethod.isBridge: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_BRIDGE
val WithAstModifiersMethod.isVarargs: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_VARARGS
val WithAstModifiersField.isTransient: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_TRANSIENT
val WithAstModifiersMethod.isNative: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_NATIVE
val WithAstModifiersMethod.isAbstract: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ABSTRACT
val WithAstModifiersMethod.isStrict: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_STRICT
val WithAstModifiers.isSynthetic: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_SYNTHETIC
val WithAstModifiersParameter.isMandated: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_MANDATED
val WithAstModifiersMethod.isConcrete: Boolean get() = !isNative && !isAbstract
val WithAstModifiers.visibility: AstVisibility get() = when {
isPublic -> AstVisibility.PUBLIC
isProtected -> AstVisibility.PROTECTED
else -> AstVisibility.PRIVATE
}
val WithAstModifiersClass.isSuper: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_SUPER
val WithAstModifiersClass.isInterface: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_INTERFACE
val WithAstModifiersClass.isAbstract: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ABSTRACT
val WithAstModifiersClass.isAnnotation: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ANNOTATION
val WithAstModifiersClass.isEnum: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ENUM
val WithAstModifiersClass.classType: AstClassType get() = when {
isInterface -> AstClassType.INTERFACE
isAbstract -> AstClassType.ABSTRACT
else -> AstClassType.CLASS
}

fun ARRAY(type: AstClass) = AstType.ARRAY(type.astType)

fun getCommonTypePrim(a: AstType.Primitive, b: AstType.Primitive): AstType.Primitive {
Expand Down
2 changes: 1 addition & 1 deletion jtransc-core/src/com/jtransc/ast/ast_body.kt
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ object AstExprUtils {
val clazz = program.get3(e.method.classRef)
val refMethod = program.get(e.method) ?: invalidOp("Can't find method: ${e.method} while generating $context")
// https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokespecial
return if (refMethod.modifiers.isPrivate || refMethod.isInstanceInit) {
return if (refMethod.isPrivate || refMethod.isInstanceInit) {
// Call this!
AstExpr.CALL_INSTANCE(e.obj.value, e.method, e.args.map { it.value }, e.isSpecial)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object CommonTagHandler {
val desc2 = dataParts.joinToString(":")
val classFqname = resolveClassName(dataParts[0], params)
if (!program.contains(classFqname)) {
invalidOp("evalReference: Can't find class '$classFqname' (I)")
invalidOp("evalReference: Can't find class '$classFqname' (I) : parts : $dataParts")
}
val clazz = program[classFqname]
val types = program.types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fun GetClassTemplateReferences(program: AstProgram, templateStr: String, current
return _GetTemplateReferences(program, templateStr, currentClass, classes = true, config = config).map { (it as CommonTagHandler.CLASS_REF).clazz }
}


fun _GetTemplateReferences(program: AstProgram, templateStr: String, currentClass: FqName, classes: Boolean, config: TRefConfig): List<CommonTagHandler.Result> {
val refs = arrayListOf<CommonTagHandler.Result>()
val params: HashMap<String, Any?> = hashMapOf("CLASS" to currentClass.fqname)
Expand Down
Loading

0 comments on commit 3fa03ca

Please sign in to comment.