Browse Source

+ support for single character message names (patch by Dmitry Boyarintsev,
mantis #14680)

git-svn-id: branches/objc@13769 -

Jonas Maebe 16 years ago
parent
commit
50f37ad445
3 changed files with 21 additions and 7 deletions
  1. 12 5
      compiler/pdecsub.pas
  2. 7 0
      tests/test/talign.pp
  3. 2 2
      tests/test/tobjc22.pp

+ 12 - 5
compiler/pdecsub.pas

@@ -1385,16 +1385,18 @@ begin
         Message(parser_e_ill_msg_param);
         Message(parser_e_ill_msg_param);
     end;
     end;
   pt:=comp_expr(true);
   pt:=comp_expr(true);
-  if pt.nodetype=stringconstn then
+  { message is 1-character long }
+  if is_constcharnode(pt) then 
+    begin
+      include(pd.procoptions,po_msgstr);
+      tprocdef(pd).messageinf.str:=stringdup(chr(byte(tordconstnode(pt).value.uvalue and $FF)));
+    end
+  else if pt.nodetype=stringconstn then
     begin
     begin
       include(pd.procoptions,po_msgstr);
       include(pd.procoptions,po_msgstr);
       if (tstringconstnode(pt).len>255) then
       if (tstringconstnode(pt).len>255) then
         Message(parser_e_message_string_too_long);
         Message(parser_e_message_string_too_long);
       tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
       tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
-      { check whether the selector name is valid in case of Objective-C }
-      if is_objc_class_or_protocol(tprocdef(pd)._class) and
-         not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
-        Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
     end
     end
   else
   else
    if is_constintnode(pt) and
    if is_constintnode(pt) and
@@ -1409,6 +1411,11 @@ begin
     end
     end
   else
   else
     Message(parser_e_ill_msg_expr);
     Message(parser_e_ill_msg_expr);
+  { check whether the selector name is valid in case of Objective-C }
+  if (po_msgstr in pd.procoptions) and
+     is_objc_class_or_protocol(tprocdef(pd)._class) and
+     not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
+    Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
   pt.free;
   pt.free;
 end;
 end;
 
 

+ 7 - 0
tests/test/talign.pp

@@ -1,3 +1,5 @@
+{ %norun }
+
 { This is just a small file used to verify the alignment of different
 { This is just a small file used to verify the alignment of different
   structures. Only the assembler output should be checked.
   structures. Only the assembler output should be checked.
 }
 }
@@ -13,6 +15,7 @@ type
   tmyotherclass = class(tmyclass)
   tmyotherclass = class(tmyclass)
   public
   public
     procedure tito(var Msg); message 'hello';
     procedure tito(var Msg); message 'hello';
+    procedure tita(var Msg); message 'h';
     procedure titi(var Msg); message 12;
     procedure titi(var Msg); message 12;
   published
   published
     procedure published_method;
     procedure published_method;
@@ -22,6 +25,10 @@ type
    begin
    begin
    end;
    end;
 
 
+  procedure tmyotherclass.tita(var Msg);
+   begin
+   end;
+
   procedure tmyotherclass.titi(var Msg);
   procedure tmyotherclass.titi(var Msg);
    begin
    begin
    end;
    end;

+ 2 - 2
tests/test/tobjc22.pp

@@ -8,7 +8,7 @@ program protocoltest;
 
 
 type
 type
   MyProtocolA = objcprotocol
   MyProtocolA = objcprotocol
-    function newMethod: longint; message 'newMethod';
+    function newMethod: longint; message 'n';
   end;
   end;
 
 
   MyProtocolB = objcprotocol(MyProtocolA)
   MyProtocolB = objcprotocol(MyProtocolA)
@@ -24,7 +24,7 @@ type
   end;
   end;
 
 
   TMyObjectB = objcclass(NSObject,MyProtocolA)
   TMyObjectB = objcclass(NSObject,MyProtocolA)
-    function newMethod: longint; message 'newMethod';
+    function newMethod: longint; message 'n';
     class function newClassMethod: longint; message 'newClassMethod';
     class function newClassMethod: longint; message 'newClassMethod';
   end;
   end;