PHP codegen generates reliable filenames
This commit is contained in:
parent
8a3fd4b129
commit
696ddbd93b
1 changed files with 6 additions and 2 deletions
|
|
@ -2089,7 +2089,8 @@ proc getClassName(t: PType): Rope =
|
||||||
s = skipTypes(t, abstractPtrs).sym
|
s = skipTypes(t, abstractPtrs).sym
|
||||||
if s.isNil or sfAnon in s.flags:
|
if s.isNil or sfAnon in s.flags:
|
||||||
internalError("cannot retrieve class name")
|
internalError("cannot retrieve class name")
|
||||||
result = mangleName(s, targetPHP)
|
if s.loc.r != nil: result = s.loc.r
|
||||||
|
else: result = rope(s.name.s)
|
||||||
|
|
||||||
proc genClass(obj: PType; content: Rope; ext: string) =
|
proc genClass(obj: PType; content: Rope; ext: string) =
|
||||||
let cls = getClassName(obj)
|
let cls = getClassName(obj)
|
||||||
|
|
@ -2100,6 +2101,7 @@ proc genClass(obj: PType; content: Rope; ext: string) =
|
||||||
let result = ("<?php$n" &
|
let result = ("<?php$n" &
|
||||||
"/* Generated by the Nim Compiler v$# */$n" &
|
"/* Generated by the Nim Compiler v$# */$n" &
|
||||||
"/* (c) 2016 Andreas Rumpf */$n$n" &
|
"/* (c) 2016 Andreas Rumpf */$n$n" &
|
||||||
|
"require_once \"nimsystem.php\";$n" &
|
||||||
"class $#$# {$n$#$n}$n") %
|
"class $#$# {$n$#$n}$n") %
|
||||||
[rope(VersionAsString), cls, extends, content]
|
[rope(VersionAsString), cls, extends, content]
|
||||||
|
|
||||||
|
|
@ -2112,13 +2114,15 @@ proc myClose(b: PPassContext, n: PNode): PNode =
|
||||||
var m = BModule(b)
|
var m = BModule(b)
|
||||||
if sfMainModule in m.module.flags:
|
if sfMainModule in m.module.flags:
|
||||||
let ext = if m.target == targetJS: "js" else: "php"
|
let ext = if m.target == targetJS: "js" else: "php"
|
||||||
|
let f = if globals.classes.len == 0: m.module.filename
|
||||||
|
else: "nimsystem"
|
||||||
let code = wholeCode(m)
|
let code = wholeCode(m)
|
||||||
let outfile =
|
let outfile =
|
||||||
if options.outFile.len > 0:
|
if options.outFile.len > 0:
|
||||||
if options.outFile.isAbsolute: options.outFile
|
if options.outFile.isAbsolute: options.outFile
|
||||||
else: getCurrentDir() / options.outFile
|
else: getCurrentDir() / options.outFile
|
||||||
else:
|
else:
|
||||||
changeFileExt(completeCFilePath(m.module.filename), ext)
|
changeFileExt(completeCFilePath(f), ext)
|
||||||
discard writeRopeIfNotEqual(genHeader(m.target) & code, outfile)
|
discard writeRopeIfNotEqual(genHeader(m.target) & code, outfile)
|
||||||
for obj, content in items(globals.classes):
|
for obj, content in items(globals.classes):
|
||||||
genClass(obj, content, ext)
|
genClass(obj, content, ext)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue