Browse Source

* correctly handle directives for function references

Sven/Sarah Barth 3 years ago
parent
commit
e8b0fc88e3
2 changed files with 28 additions and 8 deletions
  1. 23 6
      compiler/pdecl.pas
  2. 5 2
      compiler/pdecvar.pas

+ 23 - 6
compiler/pdecl.pas

@@ -325,20 +325,23 @@ implementation
                    current_tokenpos:=storetokenpos;
                    current_tokenpos:=storetokenpos;
                    skip_initialiser:=false;
                    skip_initialiser:=false;
                    { Anonymous proctype definitions can have proc directives }
                    { Anonymous proctype definitions can have proc directives }
-                   if (hdef.typ=procvardef) and
-                      (hdef.typesym=nil) then
+                   if (
+                         (hdef.typ=procvardef) or
+                         is_funcref(hdef)
+                       ) and
+                       (hdef.typesym=nil) then
                     begin
                     begin
                       { Either "procedure; stdcall" or "procedure stdcall" }
                       { Either "procedure; stdcall" or "procedure stdcall" }
                       expect_directive:=try_to_consume(_SEMICOLON);
                       expect_directive:=try_to_consume(_SEMICOLON);
                       if check_proc_directive(true) then
                       if check_proc_directive(true) then
-                        parse_proctype_directives(tprocvardef(hdef))
+                        parse_proctype_directives(hdef)
                       else if expect_directive then
                       else if expect_directive then
                        begin
                        begin
                          Message(parser_e_proc_directive_expected);
                          Message(parser_e_proc_directive_expected);
                          skip_initialiser:=true;
                          skip_initialiser:=true;
                        end;
                        end;
                       { add default calling convention }
                       { add default calling convention }
-                      handle_calling_convention(tabstractprocdef(hdef),hcc_default_actions_intf);
+                      handle_calling_convention(hdef,hcc_default_actions_intf);
                     end;
                     end;
                    { Parse the initialiser }
                    { Parse the initialiser }
                    if not skip_initialiser then
                    if not skip_initialiser then
@@ -1087,8 +1090,22 @@ implementation
                   end;
                   end;
                 objectdef :
                 objectdef :
                   begin
                   begin
-                    try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
-                    consume(_SEMICOLON);
+                    if is_funcref(hdef) then
+                      begin
+                        if not check_proc_directive(true) then
+                          begin
+                            try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
+                            consume(_SEMICOLON);
+                          end;
+                        parse_proctype_directives(hdef);
+                        if try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg) then
+                          consume(_SEMICOLON);
+                      end
+                    else
+                      begin
+                        try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
+                        consume(_SEMICOLON);
+                      end;
 
 
                     { change a forward and external class declaration into
                     { change a forward and external class declaration into
                       formal external definition, so the compiler does not
                       formal external definition, so the compiler does not

+ 5 - 2
compiler/pdecvar.pas

@@ -889,11 +889,14 @@ implementation
        begin
        begin
          result:=false;
          result:=false;
          { Process procvar directives before = and ; }
          { Process procvar directives before = and ; }
-         if (def.typ=procvardef) and
+         if (
+              (def.typ=procvardef) or
+              is_funcref(def)
+            ) and
             (def.typesym=nil) and
             (def.typesym=nil) and
             check_proc_directive(true) then
             check_proc_directive(true) then
            begin
            begin
-              parse_proctype_directives(tprocvardef(def));
+              parse_proctype_directives(def);
               result:=true;
               result:=true;
            end;
            end;
        end;
        end;