mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 11:42:33 +00:00
PHP codegen generates reliable filenames
This commit is contained in:
@@ -2089,7 +2089,8 @@ proc getClassName(t: PType): Rope =
|
||||
s = skipTypes(t, abstractPtrs).sym
|
||||
if s.isNil or sfAnon in s.flags:
|
||||
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) =
|
||||
let cls = getClassName(obj)
|
||||
@@ -2100,6 +2101,7 @@ proc genClass(obj: PType; content: Rope; ext: string) =
|
||||
let result = ("<?php$n" &
|
||||
"/* Generated by the Nim Compiler v$# */$n" &
|
||||
"/* (c) 2016 Andreas Rumpf */$n$n" &
|
||||
"require_once \"nimsystem.php\";$n" &
|
||||
"class $#$# {$n$#$n}$n") %
|
||||
[rope(VersionAsString), cls, extends, content]
|
||||
|
||||
@@ -2112,13 +2114,15 @@ proc myClose(b: PPassContext, n: PNode): PNode =
|
||||
var m = BModule(b)
|
||||
if sfMainModule in m.module.flags:
|
||||
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 outfile =
|
||||
if options.outFile.len > 0:
|
||||
if options.outFile.isAbsolute: options.outFile
|
||||
else: getCurrentDir() / options.outFile
|
||||
else:
|
||||
changeFileExt(completeCFilePath(m.module.filename), ext)
|
||||
changeFileExt(completeCFilePath(f), ext)
|
||||
discard writeRopeIfNotEqual(genHeader(m.target) & code, outfile)
|
||||
for obj, content in items(globals.classes):
|
||||
genClass(obj, content, ext)
|
||||
|
||||
Reference in New Issue
Block a user