diff --git a/Foundation/CPKeyValueObserving.j b/Foundation/CPKeyValueObserving.j index b3f01f05a..95c00d36a 100644 --- a/Foundation/CPKeyValueObserving.j +++ b/Foundation/CPKeyValueObserving.j @@ -423,7 +423,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti setKey_method_imp(self, _cmd, anObject); [self didChangeValueForKey:aKey]; - }, ""); + }, setKey_method.method_types); } // FIXME: Deprecated. @@ -441,7 +441,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti _setKey_method_imp(self, _cmd, anObject); [self didChangeValueForKey:aKey]; - }, ""); + }, _setKey_method.method_types); } // Ordered To-Many Relationships @@ -478,7 +478,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChange:CPKeyValueChangeInsertion valuesAtIndexes:[CPIndexSet indexSetWithIndex:anIndex] forKey:aKey]; - }, ""); + }, insertObject_inKeyAtIndex_method.method_types); } if (insertKey_atIndexes_method) @@ -496,7 +496,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChange:CPKeyValueChangeInsertion valuesAtIndexes:[indexes copy] forKey:aKey]; - }, ""); + }, insertKey_atIndexes_method.method_types); } if (removeObjectFromKeyAtIndex_method) @@ -514,7 +514,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChange:CPKeyValueChangeRemoval valuesAtIndexes:[CPIndexSet indexSetWithIndex:anIndex] forKey:aKey]; - }, ""); + }, removeObjectFromKeyAtIndex_method.method_types); } if (removeKeyAtIndexes_method) @@ -532,7 +532,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChange:CPKeyValueChangeRemoval valuesAtIndexes:[indexes copy] forKey:aKey]; - }, ""); + }, removeKeyAtIndexes_method.method_types); } // These are optional. @@ -558,7 +558,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChange:CPKeyValueChangeReplacement valuesAtIndexes:[CPIndexSet indexSetWithIndex:anIndex] forKey:aKey]; - }, ""); + }, replaceObjectInKeyAtIndex_withObject_method.method_types); } var replaceKeyAtIndexes_withKey_selector = @@ -581,7 +581,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChange:CPKeyValueChangeReplacement valuesAtIndexes:[indexes copy] forKey:aKey]; - }, ""); + }, replaceKeyAtIndexes_withKey_method.method_types); } } @@ -615,7 +615,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChangeValueForKey:aKey withSetMutation:CPKeyValueUnionSetMutation usingObjects:[CPSet setWithObject:anObject]]; - }, ""); + }, addKeyObject_method.method_types); } if (addKey_method) @@ -633,7 +633,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChangeValueForKey:aKey withSetMutation:CPKeyValueUnionSetMutation usingObjects:[objects copy]]; - }, ""); + }, addKey_method.method_types); } if (removeKeyObject_method) @@ -651,7 +651,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChangeValueForKey:aKey withSetMutation:CPKeyValueMinusSetMutation usingObjects:[CPSet setWithObject:anObject]]; - }, ""); + }, removeKeyObject_method.method_types); } if (removeKey_method) @@ -669,7 +669,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChangeValueForKey:aKey withSetMutation:CPKeyValueMinusSetMutation usingObjects:[objects copy]]; - }, ""); + }, removeKey_method.method_types); } // intersect: is optional. @@ -691,7 +691,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti [self didChangeValueForKey:aKey withSetMutation:CPKeyValueIntersectSetMutation usingObjects:[aSet copy]]; - }, ""); + }, intersectKey_method.method_types); } } diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index f3e1db5c4..1d74d0f10 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -90,11 +90,14 @@ exports.run = function(args) if (argv[0] === "--help" || argv[0] === "-h") { print("Usage (objj): " + args[0] + " [options] [--] files..."); - print(" -v, --version print the current version of objj"); - print(" -I, --objj-include-paths include a specific framework paths") - print(" -h, --help print this help"); - print(" -m, --multifiles launch objj on several files") - print(" -x, --xml specify the output format in xml.") + print(" -v, --version print the current version of objj"); + print(" -I, --objj-include-paths include a specific framework paths") + print(" -h, --help print this help"); + print(" -m, --multifiles launch objj on several files") + print(" -x, --xml specify the output format in xml.") + print(" -g, --include-debug-symbols Include debug symbols when compiling.") + print(" -T, --dont-include-type-signatures Do not include type signatures when compiling.") + print(" -O2, --inline-msg-send Inline objj_msgSend function when compiling.") return; } @@ -119,6 +122,24 @@ exports.run = function(args) argv.shift(); exports.outputFormatInXML = true; break; + + case "-g": + case "--include-debug-symbols": + argv.shift(); + (OBJJ_COMPILER_FLAGS || (OBJJ_COMPILER_FLAGS = [])).push("IncludeDebugSymbols"); + break; + + case "-T": + case "--dont-include-type-signatures": + argv.shift(); + (OBJJ_COMPILER_FLAGS || (OBJJ_COMPILER_FLAGS = [])).push("IncludeTypeSignatures"); + break; + + case "-O2": + case "--inline-msg-send": + argv.shift(); + (OBJJ_COMPILER_FLAGS || (OBJJ_COMPILER_FLAGS = [])).push("InlineMsgSend"); + break; } } } diff --git a/Objective-J/CommonJS/lib/objective-j/compiler.js b/Objective-J/CommonJS/lib/objective-j/compiler.js index 6f7f91972..6f761e3a5 100644 --- a/Objective-J/CommonJS/lib/objective-j/compiler.js +++ b/Objective-J/CommonJS/lib/objective-j/compiler.js @@ -187,7 +187,7 @@ function resolveFlags(args) objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax; else if (argument.indexOf("-T") === 0) - objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures; + objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures; else if (argument.indexOf("-g") === 0) objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols; @@ -259,12 +259,16 @@ exports.main = function(args) if (argv[0] === "--help" || argv[0].substr(0, 1) == '-') { print("Usage (objjc 2.0): " + args[0] + " [options] [--] file..."); - print(" -p, --print print the output directly to stdout"); - print(" --unmarked don't tag the output with @STATIC header"); + print(" -p, --print print the output directly to stdout"); + print(" --unmarked don't tag the output with @STATIC header"); print(""); - print(" -T, --includeTypeSignatures include type signatures in the compiled output"); + print(" -T, --dont-include-type-signatures include type signatures in the compiled output"); + print(" -g, --include-debug-symbols include debug symbols in the compiled output"); + print(" -T, --include-type-signatures include type signatures in the compiled output"); + print(" -O, --compress compress the compiled output"); + print(" -O2, --inline-msg-send inline objj_msgSend function in the compiled output"); print(""); - print(" --help print this help"); + print(" --help print this help"); return; } diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 89d1d6d76..fb53b2481 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -365,9 +365,6 @@ var MethodDef = function(name, types) this.types = types; } -var currentCompilerFlags = 0; -var currentGccCompilerFlags = ""; - var reservedIdentifiers = exports.acorn.makePredicate("self _cmd undefined localStorage arguments"); var wordPrefixOperators = exports.acorn.makePredicate("delete in instanceof new typeof void"); @@ -425,6 +422,16 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* compile(this.tokens, new Scope(null ,{ compiler: this }), pass === 2 ? pass2 : pass1); } +ObjJAcornCompiler.Flags = { }; + +ObjJAcornCompiler.Flags.IncludeDebugSymbols = 1 << 0; +ObjJAcornCompiler.Flags.IncludeTypeSignatures = 1 << 1; +ObjJAcornCompiler.Flags.Generate = 1 << 2; +ObjJAcornCompiler.Flags.InlineMsgSend = 1 << 3; + +var currentCompilerFlags = ObjJAcornCompiler.Flags.IncludeTypeSignatures; +var currentGccCompilerFlags = ""; + exports.ObjJAcornCompiler = ObjJAcornCompiler; exports.ObjJAcornCompiler.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) @@ -494,25 +501,25 @@ exports.setCurrentGccCompilerFlags = function(/*String*/ compilerFlags) var args = compilerFlags.split(" "), count = args.length, - objjcFlags = 0; + objjcFlags = ObjJAcornCompiler.Flags.IncludeTypeSignatures; for (var index = 0; index < count; ++index) { var argument = args[index]; if (argument.indexOf("-g") === 0) - objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols; - + objjcFlags |= ObjJAcornCompiler.Flags.IncludeDebugSymbols; else if (argument.indexOf("-O") === 0) { - objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.Compress; - // FIXME: currently we are sending in '-O2' when we want InlineMsgSend. Here we only check if we it is '-O...'. + objjcFlags |= ObjJAcornCompiler.Flags.Compress; + // 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 |= ObjectiveJ.ObjJAcornCompiler.Flags.InlineMsgSend; + objjcFlags |= ObjJAcornCompiler.Flags.InlineMsgSend; } - else if (argument.indexOf("-G") === 0) - objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.Generate; + objjcFlags |= ObjJAcornCompiler.Flags.Generate; + else if (argument.indexOf("-T") === 0) + objjcFlags &= ~ObjJAcornCompiler.Flags.IncludeTypeSignatures; } currentCompilerFlags = objjcFlags; @@ -533,13 +540,6 @@ exports.currentCompilerFlags = function(/*String*/ compilerFlags) return currentCompilerFlags; } -ObjJAcornCompiler.Flags = { }; - -ObjJAcornCompiler.Flags.IncludeDebugSymbols = 1 << 0; -ObjJAcornCompiler.Flags.IncludeTypeSignatures = 1 << 1; -ObjJAcornCompiler.Flags.Generate = 1 << 2; -ObjJAcornCompiler.Flags.InlineMsgSend = 1 << 3; - ObjJAcornCompiler.prototype.addWarning = function(/* Warning */ aWarning) { this.warnings.push(aWarning); @@ -2325,7 +2325,7 @@ MethodDeclarationStatement: function(node, st, c) { compiler.jsBuffer.concat("Nil\n"); } - if (compiler.flags & ObjJAcornCompiler.Flags.IncludeDebugSymbols) + if (compiler.flags & ObjJAcornCompiler.Flags.IncludeTypeSignatures) compiler.jsBuffer.concat(","+JSON.stringify(types)); compiler.jsBuffer.concat(")"); diff --git a/Tests/Foundation/CPKeyValueObservingTest.j b/Tests/Foundation/CPKeyValueObservingTest.j index 9726a7f05..59b501b1c 100644 --- a/Tests/Foundation/CPKeyValueObservingTest.j +++ b/Tests/Foundation/CPKeyValueObservingTest.j @@ -28,7 +28,7 @@ var _getCheeseCounter; count = arguments.length; for (; index < count; ++index) - class_addMethod(theClass, arguments[index], function() { }); + class_addMethod(theClass, arguments[index], function() { }, ["void"]); return [theClass new]; } @@ -268,7 +268,8 @@ var _getCheeseCounter; - (void)testOnlyInsertObject_AtKeyIndex_Implemented { var insertSelector = @selector(insertObject:inObjectsAtIndex:), - object = [self objectWithMethods:insertSelector]; + object = [self objectWithMethods:insertSelector], + methodTypes = class_getInstanceMethod(object.isa, insertSelector).method_types; // Sanity check [self assert:class_getInstanceMethod(object.isa, insertSelector) @@ -417,6 +418,64 @@ var _getCheeseCounter; [self assert:test equals:_lastObject]; } +- (void)testMethodTypesOnKVOForSet_Key_Implemented +{ + var setSelector = @selector(setObjects:), + object = [self objectWithMethods:setSelector], + methodTypes = class_getInstanceMethod(object.isa, setSelector).method_types; + + // Sanity check + [self assert:class_getInstanceMethod(object.isa, setSelector) + same:class_getInstanceMethod([object class], setSelector)]; + + [object + addObserver:self + forKeyPath:@"objects" + options:CPKeyValueObservingOptionOld | CPKeyValueObservingOptionNew + context:NULL]; + + // Sanity check + [self assert:class_getInstanceMethod(object.isa, setSelector) + notSame:class_getInstanceMethod([object class], setSelector)]; + + // Check that the return and parameter types are the same on the new method as the old + [self assertTrue:methodTypes != nil message:@"methodTypes can not be nil or undefined"]; + [self assert:methodTypes equals:class_getInstanceMethod(object.isa, setSelector).method_types]; +} + +- (void)testMethodTypesOnKVOForInsertObject_AtKeyIndex_Implemented_and_removeFromKeyAtIndex +{ + var insertSelector = @selector(insertObject:inObjectsAtIndex:), + removeSelector = @selector(removeObjectFromObjectsAtIndex:), + object = [self objectWithMethods:insertSelector, removeSelector], + methodTypesInsert = class_getInstanceMethod(object.isa, insertSelector).method_types, + methodTypesRemove = class_getInstanceMethod(object.isa, removeSelector).method_types; + + // Sanity check + [self assert:class_getInstanceMethod(object.isa, insertSelector) + same:class_getInstanceMethod([object class], insertSelector)]; + [self assert:class_getInstanceMethod(object.isa, removeSelector) + same:class_getInstanceMethod([object class], removeSelector)]; + + [object + addObserver:self + forKeyPath:@"objects" + options:CPKeyValueObservingOptionOld | CPKeyValueObservingOptionNew + context:NULL]; + + // Sanity check + [self assert:class_getInstanceMethod(object.isa, insertSelector) + notSame:class_getInstanceMethod([object class], insertSelector)]; + [self assert:class_getInstanceMethod(object.isa, removeSelector) + notSame:class_getInstanceMethod([object class], removeSelector)]; + + // Check that the return and parameter types are the same on the new method as the old + [self assertTrue:methodTypesInsert != nil message:@"methodTypes can not be nil or undefined on insert selector"]; + [self assertTrue:methodTypesRemove != nil message:@"methodTypes can not be nil or undefined in remove selector"]; + [self assert:methodTypesInsert equals:class_getInstanceMethod(object.isa, insertSelector).method_types]; + [self assert:methodTypesRemove equals:class_getInstanceMethod(object.isa, removeSelector).method_types]; +} + @end @implementation ObservingTester : CPObject diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js b/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js index ae78cbb53..faa0a5474 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js +++ b/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js @@ -5,7 +5,7 @@ if(!the_class){ throw new SyntaxError("*** Could not find definition for class \"TestClass\""); } var meta_class=the_class.isa; -class_addIvars(the_class,[new objj_ivar("ivar")]); +class_addIvars(the_class,[new objj_ivar("ivar","Type")]); class_addMethods(the_class,[new objj_method(sel_getUid("ivar"),function $TestClass__ivar(_1,_2){ return _1.ivar; },["Type"]),new objj_method(sel_getUid("setIvar:"),function $TestClass__setIvar_(_3,_4,_5){ diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-multiple-ivars.js b/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-multiple-ivars.js index 8cf16dc3b..622661139 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-multiple-ivars.js +++ b/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-multiple-ivars.js @@ -1,6 +1,6 @@ var the_class = objj_allocateClassPair(Nil, "TestClass"), meta_class = the_class.isa; -class_addIvars(the_class,[new objj_ivar("ivar"), new objj_ivar("array"), new objj_ivar("string"), new objj_ivar("integer")]); +class_addIvars(the_class,[new objj_ivar("ivar","Type"), new objj_ivar("array","CPArray"), new objj_ivar("string","CPString"), new objj_ivar("integer","int")]); objj_registerClassPair(the_class); diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-one-ivar.js b/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-one-ivar.js index 165c23dc8..a0327a8c8 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-one-ivar.js +++ b/Tests/Objective-J/Preprocessor/OutputTests/Class/root-class-one-ivar.js @@ -2,6 +2,6 @@ var the_class = objj_allocateClassPair(Nil, "TestClass"), meta_class = the_class.isa; -class_addIvars(the_class,[new objj_ivar("ivar")]); +class_addIvars(the_class,[new objj_ivar("ivar","Type")]); objj_registerClassPair(the_class); diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Misc/ref-self.js b/Tests/Objective-J/Preprocessor/OutputTests/Misc/ref-self.js index 778d931d6..b73f3c35f 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/Misc/ref-self.js +++ b/Tests/Objective-J/Preprocessor/OutputTests/Misc/ref-self.js @@ -1,5 +1,5 @@ {var the_class = objj_allocateClassPair(Nil, "TC"), -meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_control")]);objj_registerClassPair(the_class); +meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_control","id")]);objj_registerClassPair(the_class); class_addMethods(the_class, [new objj_method(sel_getUid("a"), function $TC__a(self, _cmd) { function(__input) { if (arguments.length) return self._control = __input; return self._control; }; diff --git a/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j b/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j index 8b19d2062..34150d7f2 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j +++ b/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j @@ -53,12 +53,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.ObjJAcornCompiler.compileToExecutable(unpreprocessed, nil, ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols | ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures).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.ObjJAcornCompiler.compileToExecutable(unpreprocessed, nil, ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols | ObjectiveJ.ObjJAcornCompiler.Flags.InlineMsgSend | ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures).code(); preprocessedInlined = compressor.compress(preprocessedInlined, { charset : "UTF-8", useServer : true }); correctInlined = compressor.compress(correctInlined, { charset : "UTF-8", useServer : true }); }]; diff --git a/Tools/capp/Resources/Templates/Application/index-debug.html b/Tools/capp/Resources/Templates/Application/index-debug.html index 91f96346c..652466be6 100644 --- a/Tools/capp/Resources/Templates/Application/index-debug.html +++ b/Tools/capp/Resources/Templates/Application/index-debug.html @@ -33,8 +33,18 @@