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

#line in C# + avoid mono bug with goto on unix #226

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Add C# #line
  • Loading branch information
soywiz committed Aug 5, 2017
commit 14a3f90028c43fa92a9e35bf5414bb0bcf12af17
2 changes: 1 addition & 1 deletion jtransc-core/src/com/jtransc/gen/common/CommonGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ abstract class CommonGenerator(val injector: Injector) : IProgramTemplate {
fun genExprLocal(e: AstExpr.LOCAL) = if (localVarPrefix.isEmpty()) e.local.targetName else localVarPrefix + e.local.targetName
fun genExprTypedLocal(e: AstExpr.TYPED_LOCAL) = genExprCast(genExprLocal(e.local), e.local.type, e.type)

fun genStmLine(stm: AstStm.LINE) = indent {
open fun genStmLine(stm: AstStm.LINE) = indent {
mark(stm)
if (GENERATE_LINE_NUMBERS) line("// ${stm.line}")
}
Expand Down
10 changes: 10 additions & 0 deletions jtransc-gen-cs/src/com/jtransc/gen/cs/CSharpTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.jtransc.injector.Injector
import com.jtransc.injector.Singleton
import com.jtransc.io.ProcessResult2
import com.jtransc.text.Indenter
import com.jtransc.text.quote
import com.jtransc.vfs.*
import java.io.File

Expand Down Expand Up @@ -67,6 +68,8 @@ class CSharpGenerator(injector: Injector) : CommonGenerator(injector) {
override val interfacesSupportStaticMembers: Boolean = false
override val floatHasFSuffix = true

override val GENERATE_LINE_NUMBERS = true

override val keywords = setOf(
"abstract", "alias", "align", "asm", "assert", "auto",
"body", "bool", "break", "byte",
Expand Down Expand Up @@ -105,6 +108,11 @@ class CSharpGenerator(injector: Injector) : CommonGenerator(injector) {
return csharpCompiler.genCommand(programFile, debug, libs, extraParams)
}

override fun genStmLine(stm: AstStm.LINE) = indent {
mark(stm)
if (GENERATE_LINE_NUMBERS) line("#line ${stm.line} ${stm.file.quote()}")
}

override fun run(redirect: Boolean): ProcessResult2 {
val names = if (JTranscSystem.isWindows()) {
listOf("program.exe", "a.exe")
Expand Down Expand Up @@ -138,6 +146,8 @@ class CSharpGenerator(injector: Injector) : CommonGenerator(injector) {

override fun quoteString(str: String) = str.dquote()



override fun genSingleFileClasses(output: SyncVfsFile): Indenter = Indenter {
val StringFqName = buildTemplateClass("java.lang.String".fqname)
val classesStr = super.genSingleFileClasses(output)
Expand Down