Merge remote-tracking branch 'cappuccino/master'

This commit is contained in:
daboe01
2016-06-18 19:18:41 +02:00
15 changed files with 2997 additions and 1331 deletions
+15 -6
View File
@@ -49,17 +49,26 @@ if (DOMBaseElementsCount > 0)
if (typeof OBJJ_COMPILER_FLAGS !== 'undefined')
{
var flags = 0;
var flags = {};
for (var i = 0; i < OBJJ_COMPILER_FLAGS.length; i++)
{
var flag = ObjJAcornCompiler.Flags[OBJJ_COMPILER_FLAGS[i]];
if (flag != null)
switch (OBJJ_COMPILER_FLAGS[i])
{
flags |= flag;
case "IncludeDebugSymbols":
flags.includeMethodFunctionNames = true;
break;
case "IncludeTypeSignatures":
flags.includeIvarTypeSignatures = true;
flags.includeMethodArgumentTypeSignatures = true;
break;
case "InlineMsgSend":
flags.inlineMsgSendFunctions = true;
break;
}
}
exports.setCurrentCompilerFlags(flags);
FileExecutable.setCurrentCompilerFlags(flags);
}
// Turn the main file into a URL.
+1 -1
View File
@@ -371,7 +371,7 @@ function FileRequest(/*CFURL*/ aURL, onsuccess, onfailure, onprogress)
{
var aFilePath = aURL.toString().substring(5),
OS = require("os"),
gccFlags = require("objective-j").currentGccCompilerFlags(),
gccFlags = require("objective-j").FileExecutable.currentGccCompilerFlags(),
chunk,
fileContents = "";
+17 -22
View File
@@ -1,6 +1,7 @@
var FILE = require("file");
var sprintf = require("printf").sprintf;
var OS = require("os");
var window = exports.window = require("browser/window");
@@ -80,6 +81,7 @@ exports.run = function(args)
// copy the args since we're going to modify them
var argv = args.slice(1);
var outputFormatInXML = false;
if (argv[0] === "--version" || argv[0] === "-v")
{
@@ -120,25 +122,33 @@ exports.run = function(args)
case "-x":
case "--xml":
argv.shift();
exports.outputFormatInXML = true;
exports.messageOutputFormatInXML = true;
outputFormatInXML = true;
break;
case "-g":
case "--include-debug-symbols":
argv.shift();
(OBJJ_COMPILER_FLAGS || (OBJJ_COMPILER_FLAGS = [])).push("IncludeDebugSymbols");
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
flags.includeMethodFunctionNames = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
break;
case "-T":
case "--dont-include-type-signatures":
argv.shift();
(OBJJ_COMPILER_FLAGS || (OBJJ_COMPILER_FLAGS = [])).push("IncludeTypeSignatures");
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
flags.includeIvarTypeSignatures = true;
flags.includeMethodArgumentTypeSignatures = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
break;
case "-O2":
case "--inline-msg-send":
argv.shift();
(OBJJ_COMPILER_FLAGS || (OBJJ_COMPILER_FLAGS = [])).push("InlineMsgSend");
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
flags.inlineMsgSendFunctions = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
break;
}
}
@@ -160,19 +170,7 @@ exports.run = function(args)
}
catch(e)
{
if (exports.outputFormatInXML)
{
var dict = new CFMutableDictionary();
dict.addValueForKey('line', e.line ? e.line : 0);
dict.addValueForKey('sourcePath', e.path ? e.path : mainFilePath);
dict.addValueForKey('message', e.message);
errors.push(dict);
}
else
{
errors.push("\n" + e);
}
errors.push(e);
}
if (typeof main === "function")
@@ -194,10 +192,8 @@ exports.run = function(args)
if (errors.length)
{
if (exports.outputFormatInXML)
throw CFPropertyListCreateXMLData(errors, kCFPropertyListXMLFormat_v1_0).rawString();
else
throw errors;
// Make sure we get exit will failiure
OS.exit(1);
}
}
else
@@ -271,7 +267,6 @@ function getPackage() {
exports.version = function() { return getPackage()["version"]; }
exports.revision = function() { return getPackage()["cappuccino-revision"]; }
exports.timestamp = function() { return new Date(getPackage()["cappuccino-timestamp"]); }
exports.outputFormatInXML = false;
exports.fullVersionString = function() {
return sprintf("objective-j %s (%04d-%02d-%02d %s)",
@@ -6,10 +6,6 @@ var FILE = require("file"),
require("objective-j/rhino/regexp-rhino-patch");
ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess = 1 << 10;
ObjectiveJ.ObjJAcornCompiler.Flags.Compress = 1 << 11;
ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax = 1 << 12;
var compressors = {
ss : { id : "minify/shrinksafe" }
//,yui : { id : "minify/yuicompressor" }
@@ -37,9 +33,8 @@ function compressor(code)
function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavascript)
{
var shouldObjjPreprocess = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess,
shouldCheckSyntax = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax,
shouldCompress = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.Compress,
var shouldObjjPreprocess = true,
shouldCompress = objjcFlags.compress,
fileContents = "",
executable,
code;
@@ -118,7 +113,7 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavasc
}
}
ObjectiveJ.setCurrentCompilerFlags(objjcFlags);
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(objjcFlags);
ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, {}, module, system, print);
executable = new ObjectiveJ.FileExecutable(FILE.basename(aFilePath));
@@ -153,7 +148,7 @@ function resolveFlags(args)
count = args.length,
gccFlags = [],
objjcFlags = ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess | ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax;
objjcFlags = {};
for (; index < count; ++index)
{
@@ -180,27 +175,23 @@ function resolveFlags(args)
}
}
else if (argument.indexOf("-E") === 0)
objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess;
else if (argument.indexOf("-S") === 0)
objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax;
else if (argument.indexOf("-T") === 0)
objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures;
{
objjcFlags.includeIvarTypeSignatures = false;
objjcFlags.includeMethodArgumentTypeSignatures = false;
}
else if (argument.indexOf("-g") === 0)
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols;
objjcFlags.includeMethodFunctionNames = true;
else if (argument.indexOf("-O") === 0) {
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.Compress;
objjcFlags.compress = true;
// FIXME: currently we are sending in '-O2' when we want InlineMsgSend. Here we only check if we it is '-O...'
if (argument.length > 2)
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.InlineMsgSend;
objjcFlags.inlineMsgSendFunctions = true;
}
else if (argument.indexOf("-G") === 0)
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.Generate;
objjcFlags.generate = true;
else
filePaths.push(argument);
@@ -223,7 +214,7 @@ exports.main = function(args)
{
var shouldPrintOutput = false,
asPlainJavascript = false,
objjcFlags = 0;
objjcFlags = {};
var argv = args.slice(1);
@@ -251,7 +242,8 @@ exports.main = function(args)
if (argv[0] === "-T" || argv[0] === "--includeTypeSignatures")
{
objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures;
objjcFlags.includeIvarTypeSignatures = true;
objjcFlags.includeMethodArgumentTypeSignatures = true;
argv.shift();
continue;
}
@@ -280,9 +272,19 @@ exports.main = function(args)
var resolved = resolveFlags(argv),
outputFilePaths = resolved.outputFilePaths,
gccFlags = resolved.gccFlags;
gccFlags = resolved.gccFlags,
resolvedObjjcFlags = resolved.objjcFlags;
// Merge resolved keys into objjcFlags
for (var key in resolvedObjjcFlags)
{
if (resolvedObjjcFlags.hasOwnProperty(key))
{
if (resolvedObjjcFlags[key])
objjcFlags[key] = resolvedObjjcFlags[key];
}
}
objjcFlags |= resolved.objjcFlags;
resolved.filePaths.forEach(function(filePath, index)
{
if (!shouldPrintOutput)
@@ -907,7 +907,7 @@ BundleTask.prototype.defineSourceTasks = function()
basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length);
// Here we set the current compiler flags so the load system will know what compiler flags to use
ObjectiveJ.setCurrentGccCompilerFlags(environmentCompilerFlags);
ObjectiveJ.FileExecutable.setCurrentGccCompilerFlags(environmentCompilerFlags);
// Here we tell the CFBundle to load frameworks for the current build enviroment and not the enviroment that is running
CFBundle.environments = function() {return [anEnvironment.name(), "ObjJ"]};
ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print);
+5 -1
View File
@@ -169,6 +169,10 @@ Executable.prototype.execute = function()
this._compiler.popImport();
this.setCode(this._compiler.compilePass2());
if (FileExecutable.printWarningsAndErrors(this._compiler, exports.messageOutputFormatInXML))
throw "Compilation error";
this._compiler = null;
}
@@ -499,7 +503,7 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL)
{
if (!aStaticResource)
{
var compilingFileUrl = ObjJAcornCompiler ? ObjJAcornCompiler.currentCompileFile : null;
var compilingFileUrl = exports.ObjJCompiler ? exports.ObjJCompiler.currentCompileFile : null;
throw new Error("Could not load file at " + aURL + (compilingFileUrl ? " when compiling " + compilingFileUrl : ""));
}
+121 -1
View File
@@ -22,6 +22,9 @@
var FileExecutablesForURLStrings = { };
var currentCompilerFlags = {};
var currentGccCompilerFlags = "";
function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslateDictionary)
{
aURL = makeAbsoluteURL(aURL);
@@ -41,7 +44,17 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslate
if (fileContents.match(/^@STATIC;/))
executable = decompile(fileContents, aURL);
else if ((extension === "j" || !extension) && !fileContents.match(/^{/))
executable = exports.ObjJAcornCompiler.compileFileDependencies(fileContents, aURL, exports.currentCompilerFlags());
{
var compiler = exports.ObjJCompiler.compileFileDependencies(fileContents, aURL, currentCompilerFlags || {});
if (FileExecutable.printWarningsAndErrors(compiler, exports.messageOutputFormatInXML))
throw "Compilation error";
var fileDependencies = compiler.dependencies.map(function (aFileDep) {
return new FileDependency(new CFURL(aFileDep.url), aFileDep.isLocal);
});
executable = new Executable(compiler.jsBuffer ? compiler.jsBuffer.toString() : null, fileDependencies, compiler.URL, null, compiler);
}
else
executable = new Executable(fileContents, [], aURL);
@@ -139,3 +152,110 @@ FileExecutable._lookupCachedFunction = function(/*CFURL|String*/ aURL)
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
return FunctionCache[aURL];
}
FileExecutable.setCurrentGccCompilerFlags = function(/*String*/ compilerFlags)
{
if (currentGccCompilerFlags === compilerFlags) return;
currentGccCompilerFlags = compilerFlags;
var args = compilerFlags.split(" "),
count = args.length,
objjcFlags = {};
for (var index = 0; index < count; ++index)
{
var argument = args[index];
if (argument.indexOf("-g") === 0)
objjcFlags.includeMethodFunctionNames = true;
else if (argument.indexOf("-O") === 0) {
objjcFlags.inlineMsgSendFunctions = true;
// FIXME: currently we are sending in '-O2' when we want InlineMsgSend. Here we only check if it is '-O...'.
// Maybe we should have some other option for this
if (argument.length > 2)
objjcFlags.inlineMsgSendFunctions = true;
}
//else if (argument.indexOf("-G") === 0)
//objjcFlags |= ObjJAcornCompiler.Flags.Generate;
else if (argument.indexOf("-T") === 0) {
objjcFlags.includeIvarTypeSignatures = false;
objjcFlags.includeMethodArgumentTypeSignatures = false;
}
}
FileExecutable.setCurrentCompilerFlags(objjcFlags);
}
FileExecutable.currentGccCompilerFlags = function(/*String*/ compilerFlags)
{
return currentGccCompilerFlags;
}
FileExecutable.setCurrentCompilerFlags = function(/*JSObject*/ compilerFlags)
{
currentCompilerFlags = compilerFlags;
// Here we set the default flags if they are not included. We do this as the default values
// in the compiler might not be what we want.
if (currentCompilerFlags.transformNamedFunctionDeclarationToAssignment == null)
currentCompilerFlags.transformNamedFunctionDeclarationToAssignment = true;
if (currentCompilerFlags.sourceMap == null)
currentCompilerFlags.sourceMap = false;
if (currentCompilerFlags.inlineMsgSendFunctions == null)
currentCompilerFlags.inlineMsgSendFunctions = false;
}
FileExecutable.currentCompilerFlags = function(/*JSObject*/ compilerFlags)
{
return currentCompilerFlags;
}
/*!
This funtion prints all errors and warnings for the provieded compiler. It returns true if there
are any errors in the list. it will print it in xml format if printXML is 'true'
*/
FileExecutable.printWarningsAndErrors = function(/*ObjJCompiler*/ compiler, /*BOOL*/ printXML)
{
var warnings = [],
anyErrors = false;
for (var i = 0; i < compiler.warningsAndErrors.length; i++)
{
var warning = compiler.warningsAndErrors[i],
message = compiler.prettifyMessage(warning);
// Set anyErrors to 'true' if there are any errors in the list
anyErrors = anyErrors || warning.messageType === "ERROR";
#ifdef BROWSER
console.log(message);
#else
if (printXML)
{
var dict = new CFMutableDictionary();
if (warning.messageOnLine != null) dict.addValueForKey('line', warning.messageOnLine)
if (warning.path != null) dict.addValueForKey('sourcePath', new CFURL(warning.path).path())
if (message != null) dict.addValueForKey('message', message)
warnings.push(dict);
}
else
{
print(message);
}
#endif
}
#ifndef BROWSER
if (warnings.length && printXML)
try {
print(CFPropertyListCreateXMLData(warnings, kCFPropertyListXMLFormat_v1_0).rawString());
} catch (e) {
print ("XML encode error: " + e);
}
#endif
return anyErrors;
}
// Set the compiler flags to empty dictionary so the default values are correct.
FileExecutable.setCurrentCompilerFlags({});
File diff suppressed because it is too large Load Diff
+1182 -526
View File
File diff suppressed because it is too large Load Diff
+5 -6
View File
@@ -101,8 +101,7 @@ if (!exports.acorn) {
};
exports.TryStatement = function(node, st, c) {
c(node.block, st, "Statement");
for (var i = 0; i < node.handlers.length; ++i)
c(node.handlers[i].body, st, "ScopeBody");
if (node.handler) c(node.handler.body, st, "ScopeBody");
if (node.finalizer) c(node.finalizer, st, "Statement");
};
exports.WhileStatement = function(node, st, c) {
@@ -267,10 +266,10 @@ if (!exports.acorn) {
},
TryStatement: function(node, scope, c) {
c(node.block, scope, "Statement");
for (var i = 0; i < node.handlers.length; ++i) {
var handler = node.handlers[i], inner = makeScope(scope);
inner.vars[handler.param.name] = {type: "catch clause", node: handler.param};
c(handler.body, inner, "ScopeBody");
if (node.handler) {
var inner = makeScope(scope);
inner.vars[node.handler.param.name] = {type: "catch clause", node: node.handler.param};
c(node.handler.body, inner, "ScopeBody");
}
if (node.finalizer) c(node.finalizer, scope, "Statement");
},
@@ -0,0 +1,7 @@
var the_class=objj_allocateClassPair(Nil,"TheSuperClass"),meta_class=the_class.isa;
objj_registerClassPair(the_class);
var the_class=objj_allocateClassPair(Nil,"TheClass"),meta_class=the_class.isa;
objj_registerClassPair(the_class);
class_addMethods(the_class,[new objj_method(sel_getUid("xxxx:"),function $TheClass__xxxx_(_1,_2,_3){
(objj_getClass("TheClass").super_class.method_dtable["xxxx:"]||_objj_forward)(_1,"xxxx:",_3);
},["void","id"])]);
@@ -0,0 +1,11 @@
@implementation TheSuperClass
@end
@implementation TheClass
- (void)xxxx:(id)argument
{
[super xxxx:argument];
}
@end
@@ -0,0 +1,7 @@
var the_class=objj_allocateClassPair(Nil,"TheSuperClass"),meta_class=the_class.isa;
objj_registerClassPair(the_class);
var the_class=objj_allocateClassPair(Nil,"TheClass"),meta_class=the_class.isa;
objj_registerClassPair(the_class);
class_addMethods(the_class,[new objj_method(sel_getUid("xxxx:"),function $TheClass__xxxx_(_1,_2,_3){
objj_msgSendSuper1({receiver:_1,super_class:objj_getClass("TheClass").super_class},"xxxx:",_3);
},["void","id"])]);
@@ -16,6 +16,7 @@ var FILENAMES = [
"Messages/colon-selector",
"Messages/self-as-receiver",
"Messages/complex-receiver",
"Messages/super-selector",
"Misc/parenthesis-return",
"Misc/preprocess-if-directives",
@@ -53,12 +54,12 @@ var FILENAMES = [
correctInlined = FILE.exists(p) ? FILE.read(p) : correct; // Get inlined version if it exists. Otherwise use the regular one.
[self assertNoThrow:function() {
preprocessed = ObjectiveJ.ObjJAcornCompiler.compileToExecutable(unpreprocessed, nil, ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols | ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures).code();
preprocessed = ObjectiveJ.ObjJCompiler.compileToExecutable(unpreprocessed, nil, {includeMethodFunctionNames: true, includeMethodArgumentTypeSignatures: true, includeIvarTypeSignatures: true, inlineMsgSendFunctions: false, transformNamedFunctionDeclarationToAssignment: true}).code();
preprocessed = compressor.compress(preprocessed, { charset : "UTF-8", useServer : true });
correct = compressor.compress(correct, { charset : "UTF-8", useServer : true });
// Get an Inlined version
preprocessedInlined = ObjectiveJ.ObjJAcornCompiler.compileToExecutable(unpreprocessed, nil, ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols | ObjectiveJ.ObjJAcornCompiler.Flags.InlineMsgSend | ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures).code();
preprocessedInlined = ObjectiveJ.ObjJCompiler.compileToExecutable(unpreprocessed, nil, {includeMethodFunctionNames: true, includeMethodArgumentTypeSignatures: true, includeIvarTypeSignatures: true, inlineMsgSendFunctions: true, transformNamedFunctionDeclarationToAssignment:true}).code();
preprocessedInlined = compressor.compress(preprocessedInlined, { charset : "UTF-8", useServer : true });
correctInlined = compressor.compress(correctInlined, { charset : "UTF-8", useServer : true });
}];
+3 -2
View File
@@ -58,10 +58,11 @@ function cleanup() {
\nERROR line 1 in file:" + rootDirectory + "/objjErrorTestFile.j: Can&apos;t find superclass CPObject</string></dict></array></plist>\n" equals:p.stdout.read() message:"objj failed"];
var p = OS.popen(["objj", "-x", "objjWarningTestFile.j"]);
var pp = p.stdout.read();
[self assert:0 equals:p.wait() message:"objj failed"];
[self assert:"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version = \"1.0\"><array><dict><key>line</key><integer>1</integer><key>sourcePath</key><string>" + rootDirectory + "/objjWarningTestFile.j</string><key>message</key><string>\n@import &lt;Foundation/Foundation.j&gt;@implementation AppController : CPObject{CPWindow theWindow;}@end\
\n ^\
\nWARNING line 1 in file:" + rootDirectory + "/objjWarningTestFile.j: Unknown type &apos;CPWindow&apos; for ivar &apos;theWindow&apos;</string></dict></array></plist>\n" equals:p.stdout.read() message:"objj failed"];
\n ^\
\nWARNING line 1 in file:" + rootDirectory + "/objjWarningTestFile.j: Unknown type &apos;CPWindow&apos; for ivar &apos;theWindow&apos;</string></dict></array></plist>\n" equals:pp message:"objj failed"];
status = OS.system(["objj", "-m", "ToolsTestApp/AppController.j", "ToolsTestApp/AppController.j"]);
[self assert:0 equals:status message:"objj failed with several files"];