Merge branch 'master' into capp_env

This commit is contained in:
Antoine Mercadal committed 2015-06-19 10:12:02 -07:00
commit da6698b216
4 files changed
+50 -45

No files matched your search

+29 -17
View File
@@ -125,30 +125,34 @@ exports.run = function(args)
if (argv && argv.length > 0)
{
var endCommand = false;
var endCommand = false,
errors = [];
while (argv.length > 0)
{
var arg0 = argv.shift();
var mainFilePath = FILE.canonical(arg0);
var arg0 = argv.shift(),
mainFilePath = FILE.canonical(arg0);
if (multipleFiles)
{
// This is needed to process every files passed in args
// Otherwise it would stop when an error is raised or we would like to objj the other given files
try
{
exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print);
}
catch(e)
{
print("\n" + e);
}
}
else
try
{
exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print);
}
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);
}
}
if (typeof main === "function")
{
@@ -166,6 +170,14 @@ exports.run = function(args)
ObjectiveJ.FileExecutable.resetFileExecutables();
objj_resetRegisterClasses();
}
if (errors.length)
{
if (exports.outputFormatInXML)
throw CFPropertyListCreateXMLData(errors, kCFPropertyListXMLFormat_v1_0).rawString();
else
throw errors;
}
}
else
{
+8 -17
View File
@@ -398,7 +398,7 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*
{
var dict = new CFMutableDictionary();
dict.addValueForKey('line', e.line);
dict.addValueForKey('path', this.URL.path());
dict.addValueForKey('sourcePath', this.URL.path());
dict.addValueForKey('message', message);
print(CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString());
@@ -468,7 +468,7 @@ ObjJAcornCompiler.prototype.compilePass2 = function()
{
var dict = new CFMutableDictionary();
dict.addValueForKey('line', warning.line)
dict.addValueForKey('path', this.URL.path())
dict.addValueForKey('sourcePath', this.URL.path())
dict.addValueForKey('message', message)
warnings.push(dict);
@@ -692,23 +692,14 @@ ObjJAcornCompiler.prototype.prettifyMessage = function(/* Message */ aMessage, /
ObjJAcornCompiler.prototype.error_message = function(errorMessage, node)
{
var pos = exports.acorn.getLineInfo(this.source, node.start);
var pos = exports.acorn.getLineInfo(this.source, node.start),
syntaxErrorData = {message: errorMessage, line: pos.line, column: pos.column, lineStart: pos.lineStart, lineEnd: pos.lineEnd},
syntaxError = new SyntaxError(this.prettifyMessage(syntaxErrorData, "ERROR"));
if (exports.outputFormatInXML)
{
var dict = new CFMutableDictionary();
dict.addValueForKey('line', pos.line);
dict.addValueForKey('path', this.URL.path());
dict.addValueForKey('message', errorMessage);
syntaxError.line = pos.line;
syntaxError.path = this.URL.path();
return CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString();
}
else
{
var syntaxError = {message: errorMessage, line: pos.line, column: pos.column, lineStart: pos.lineStart, lineEnd: pos.lineEnd};
return new SyntaxError(this.prettifyMessage(syntaxError, "ERROR"));
}
return syntaxError;
}
ObjJAcornCompiler.prototype.pushImport = function(url)
+5 -2
View File
@@ -52,11 +52,14 @@ function cleanup() {
var p = OS.popen(["objj", "--xml", "objjErrorTestFile.j"]);
[self assert:1 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>path</key><string>" + rootDirectory + "/objjErrorTestFile.j</string><key>message</key><string>Can&apos;t find superclass CPObject</string></dict></array></plist>\n" equals:p.stdout.read() 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 + "/objjErrorTestFile.j</string><key>message</key><string>\
\n@implementation AppController : CPObject{}@end\
\n ^\
\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"]);
[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>path</key><string>" + rootDirectory + "/objjWarningTestFile.j</string><key>message</key><string>\n@import &lt;Foundation/Foundation.j&gt;@implementation AppController : CPObject{CPWindow theWindow;}@end\
[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"];
+8 -9
View File
@@ -4,9 +4,7 @@
var FILE = require("file"),
OS = require("os"),
stream = require("narwhal/term").stream,
SLASH_REPLACEMENT = "∕"; // DIVISION SLASH, Unicode: U+2215
stream = require("narwhal/term").stream;
function main(args)
{
@@ -138,16 +136,17 @@ function removeLastSlashIfNecessary(path)
/*
$1 Full project source path
$2 Destination
$-n name of the cocoa files
*/
function parser(args)
{
try
{
var projectBasePath = removeLastSlashIfNecessary(args[1]),
sourcePath = args[0],
var sourcePath = args.shift(),
projectBasePath = removeLastSlashIfNecessary(args.shift()),
outputDirectory = projectBasePath,
baseFilename = [sourcePath lastPathComponent],
baseFilenameWithNoExtension = baseFilename.substring(0, baseFilename.length - 2),
baseFilenameWithNoExtension = args.shift() == "-n" ? args.shift() : baseFilename.substring(0, baseFilename.length - 2),
outputHeaderURL = new CFURL([outputDirectory stringByAppendingPathComponent:baseFilenameWithNoExtension + ".h"]),
outputImplementationURL = new CFURL([outputDirectory stringByAppendingPathComponent:baseFilenameWithNoExtension + ".m"]),
source = FILE.read(sourcePath, { charset: "UTF-8" }),
@@ -175,7 +174,7 @@ function parser(args)
if (aClass.superClass)
ObjectiveCHeader += [CPString stringWithFormat:@"\n@interface %@ : %@", aClass.name, NSCompatibleClassName(aClass.superClass)];
else
ObjectiveCHeader += [CPString stringWithFormat:@"\n@interface %@ (%@)", aClass.name, aClass.category];
ObjectiveCHeader += [CPString stringWithFormat:@"\n@interface %@ (%@)", NSCompatibleClassName(aClass.name, NO), aClass.category];
// add each outlet in header
if (aClass.outlets.length > 0)
@@ -201,7 +200,7 @@ function parser(args)
ObjectiveCHeader += "\n@end\n";
// fill up the implementation file
ObjectiveCSource += "\n@implementation " + aClass.name + "\n@end\n";
ObjectiveCSource += "\n@implementation " + NSCompatibleClassName(aClass.name, NO) + "\n@end\n";
});
if (ObjectiveCSource.length)
@@ -214,7 +213,7 @@ function parser(args)
{
[errors addObject:@{
@"message": e.message,
@"path": sourcePath,
@"sourcePath": sourcePath,
@"line": e.line
}];