From 8e81477fcf72671a24369fcfd4b7ceac927a2d89 Mon Sep 17 00:00:00 2001 From: Jonas Maebe <jonas@freepascal.org> Date: Sat, 12 Sep 2009 14:04:44 +0000 Subject: [PATCH] * make hidden '_cmd' (selector) parameter available in Objective-C methods * don't give a hint if this hidden _cmd parameter is unused git-svn-id: branches/objc@13700 - --- .gitattributes | 1 + compiler/pdecsub.pas | 9 +++++++++ compiler/symtable.pas | 5 ++++- tests/test/tobjc21.pp | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/test/tobjc21.pp diff --git a/.gitattributes b/.gitattributes index 109e0212ff..9115cf1e34 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8597,6 +8597,7 @@ tests/test/tobjc18.pp svneol=native#text/plain tests/test/tobjc19.pp svneol=native#text/plain tests/test/tobjc2.pp svneol=native#text/plain tests/test/tobjc20.pp svneol=native#text/plain +tests/test/tobjc21.pp svneol=native#text/plain tests/test/tobjc3.pp svneol=native#text/plain tests/test/tobjc4.pp svneol=native#text/plain tests/test/tobjc4a.pp svneol=native#text/plain diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index 9d863cd919..36ddcf5ce5 100644 --- a/compiler/pdecsub.pas +++ b/compiler/pdecsub.pas @@ -162,6 +162,8 @@ implementation vs : tparavarsym; hdef : tdef; vsp : tvarspez; + aliasvs : tabsolutevarsym; + sl : tpropaccesslist; begin if (pd.typ=procdef) and is_objc_class_or_protocol(tprocdef(pd)._class) then @@ -169,6 +171,13 @@ implementation { insert Objective-C self and selector parameters } vs:=tparavarsym.create('$_cmd',paranr_objc_cmd,vs_value,objc_seltype,[vo_is_msgsel,vo_is_hidden_para]); pd.parast.insert(vs); + { make accessible to code } + sl:=tpropaccesslist.create; + sl.addsym(sl_load,vs); + aliasvs:=tabsolutevarsym.create_ref('_CMD',objc_seltype,sl); + include(aliasvs.varoptions,vo_is_msgsel); + tlocalsymtable(tprocdef(pd).localst).insert(aliasvs); + vs:=tparavarsym.create('$self',paranr_objc_self,vs_value,objc_idtype,[vo_is_self,vo_is_hidden_para]); pd.parast.insert(vs); end diff --git a/compiler/symtable.pas b/compiler/symtable.pas index 35fbbcab0c..03eedc8b74 100644 --- a/compiler/symtable.pas +++ b/compiler/symtable.pas @@ -630,7 +630,10 @@ implementation (tsym(sym).typ<>procsym) or ((tsym(sym).owner.symtabletype=staticsymtable) and not current_module.is_unit) - ) then + ) and + { don't complain about alias for hidden _cmd parameter to + obj-c methods } + not (vo_is_msgsel in tabstractvarsym(sym).varoptions) then MessagePos2(tsym(sym).fileinfo,sym_h_local_symbol_not_used,SymTypeName[tsym(sym).typ],tsym(sym).prettyname); end; end; diff --git a/tests/test/tobjc21.pp b/tests/test/tobjc21.pp new file mode 100644 index 0000000000..6c46bc61b4 --- /dev/null +++ b/tests/test/tobjc21.pp @@ -0,0 +1,37 @@ +{ %target=darwin } +{ %cpu=powerpc,i386 } + +program project1; + +{$mode objfpc}{$H+} +{$modeswitch objectivec1} +type + + MyObject = objcclass(NSObject) + + function getsspara(l1,l2: longint): shortstring ; message 'getss:l1:'; + + end; + +var + m: MyObject; + b: boolean; + +function MyObject.getsspara(l1,l2: longint): shortstring; +begin + if (self<>m) then + halt(1); + if _cmd<>objcselector('getss:l1:') then + halt(2); + result:=''; +end; + + +begin + m := MyObject.alloc; + m:=m.init; + + m.getsspara(1,2); + + m.release; +end.