mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-14 22:51:28 +00:00
Fixed objjc to use new acorn based compiler
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
|
||||
var FILE = require("file"),
|
||||
OS = require("os"),
|
||||
ObjectiveJ = require("objective-j");
|
||||
ObjectiveJ = require("objective-j"),
|
||||
JAKE = require("jake");
|
||||
|
||||
require("objective-j/rhino/regexp-rhino-patch");
|
||||
|
||||
ObjectiveJ.Preprocessor.Flags.Preprocess = 1 << 10;
|
||||
ObjectiveJ.Preprocessor.Flags.Compress = 1 << 11;
|
||||
ObjectiveJ.Preprocessor.Flags.CheckSyntax = 1 << 12;
|
||||
ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess = 1 << 10;
|
||||
ObjectiveJ.ObjJAcornCompiler.Flags.Compress = 1 << 11;
|
||||
ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax = 1 << 12;
|
||||
|
||||
var compressors = {
|
||||
ss : { id : "minify/shrinksafe" }
|
||||
@@ -36,16 +37,15 @@ function compressor(code)
|
||||
|
||||
function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavascript)
|
||||
{
|
||||
var shouldObjjPreprocess = objjcFlags & ObjectiveJ.Preprocessor.Flags.Preprocess,
|
||||
shouldCheckSyntax = objjcFlags & ObjectiveJ.Preprocessor.Flags.CheckSyntax,
|
||||
shouldCompress = objjcFlags & ObjectiveJ.Preprocessor.Flags.Compress,
|
||||
var shouldObjjPreprocess = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess,
|
||||
shouldCheckSyntax = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax,
|
||||
shouldCompress = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.Compress,
|
||||
fileContents = "",
|
||||
executable,
|
||||
code;
|
||||
|
||||
if (OS.popen("which gcc").stdout.read().length === 0)
|
||||
if (!shouldObjjPreprocess && OS.popen("which gcc").stdout.read().length === 0)
|
||||
fileContents = FILE.read(aFilePath, { charset:"UTF-8" });
|
||||
|
||||
else
|
||||
{
|
||||
// GCC preprocess the file.
|
||||
@@ -54,30 +54,38 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavasc
|
||||
|
||||
while (chunk = gcc.stdout.read())
|
||||
fileContents += chunk;
|
||||
}
|
||||
|
||||
if (!shouldObjjPreprocess)
|
||||
return fileContents;
|
||||
}
|
||||
|
||||
// Preprocess contents into fragments.
|
||||
// FIXME: should calculate relative path, etc.
|
||||
try
|
||||
{
|
||||
executable = ObjectiveJ.preprocess(fileContents, FILE.basename(aFilePath), objjcFlags);
|
||||
var sources = new JAKE.FileList("**/*.j"),
|
||||
translateFilenameToPath = {},
|
||||
otherwayTranslateFilenameToPath = {};
|
||||
|
||||
// Create a filename to filename path dictionary. (For example: CPArray.j -> CPArray/CPArray.j)
|
||||
sources.forEach(function(/*String*/ aFilename)
|
||||
{
|
||||
translateFilenameToPath[FILE.basename(aFilename)] = aFilename;
|
||||
otherwayTranslateFilenameToPath[aFilename] = FILE.basename(aFilename);
|
||||
}, this);
|
||||
|
||||
var translatedFilename = translateFilenameToPath[aFilePath] ? translateFilenameToPath[aFilePath] : aFilePath,
|
||||
otherwayTranslatedFilename = otherwayTranslateFilenameToPath[aFilePath] ? otherwayTranslateFilenameToPath[aFilePath] : aFilePath,
|
||||
theTranslatedFilename = otherwayTranslatedFilename ? otherwayTranslatedFilename : translatedFilename,
|
||||
absolutePath = FILE.absolute(theTranslatedFilename),
|
||||
basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length);
|
||||
|
||||
ObjectiveJ.setCurrentCompilerFlags(objjcFlags);
|
||||
ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, {}, module, system, print);
|
||||
|
||||
executable = new ObjectiveJ.FileExecutable(FILE.basename(aFilePath));
|
||||
}
|
||||
catch (anException)
|
||||
{print(anException);
|
||||
var lines = fileContents.split("\n"),
|
||||
PAD = 3,
|
||||
lineNumber = anException.lineNumber || anException.line,
|
||||
errorInfo = "Syntax error in " + aFilePath +
|
||||
" on preprocessed line number " + lineNumber + "\n\n" +
|
||||
"\t" + lines.slice(Math.max(0, lineNumber - 1 - PAD), lineNumber + PAD).join("\n\t");
|
||||
|
||||
print(errorInfo);
|
||||
|
||||
throw errorInfo;
|
||||
}
|
||||
{}
|
||||
|
||||
if (shouldCompress)
|
||||
{
|
||||
@@ -100,7 +108,7 @@ function resolveFlags(args)
|
||||
count = args.length,
|
||||
|
||||
gccFlags = [],
|
||||
objjcFlags = ObjectiveJ.Preprocessor.Flags.Preprocess | ObjectiveJ.Preprocessor.Flags.CheckSyntax;
|
||||
objjcFlags = ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess | ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax;
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
@@ -128,19 +136,19 @@ function resolveFlags(args)
|
||||
}
|
||||
|
||||
else if (argument.indexOf("-E") === 0)
|
||||
objjcFlags &= ~ObjectiveJ.Preprocessor.Flags.Preprocess;
|
||||
objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess;
|
||||
|
||||
else if (argument.indexOf("-S") === 0)
|
||||
objjcFlags &= ~ObjectiveJ.Preprocessor.Flags.CheckSyntax;
|
||||
objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax;
|
||||
|
||||
else if (argument.indexOf("-T") === 0)
|
||||
objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeTypeSignatures;
|
||||
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures;
|
||||
|
||||
else if (argument.indexOf("-g") === 0)
|
||||
objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeDebugSymbols;
|
||||
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols;
|
||||
|
||||
else if (argument.indexOf("-O") === 0)
|
||||
objjcFlags |= ObjectiveJ.Preprocessor.Flags.Compress;
|
||||
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.Compress;
|
||||
|
||||
else
|
||||
filePaths.push(argument);
|
||||
@@ -191,7 +199,7 @@ exports.main = function(args)
|
||||
|
||||
if (argv[0] === "-T" || argv[0] === "--includeTypeSignatures")
|
||||
{
|
||||
objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeTypeSignatures;
|
||||
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures;
|
||||
argv.shift();
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user