Browse Source

* better support for indexed properties

peter 24 years ago
parent
commit
075b5188ee
2 changed files with 48 additions and 25 deletions
  1. 30 11
      compiler/pdecobj.pas
  2. 18 14
      compiler/pexpr.pas

+ 30 - 11
compiler/pdecobj.pas

@@ -315,6 +315,11 @@ implementation
                      until not try_to_consume(_SEMICOLON);
                      until not try_to_consume(_SEMICOLON);
                      dec(testcurobject);
                      dec(testcurobject);
                      consume(_RECKKLAMMER);
                      consume(_RECKKLAMMER);
+
+                     { the parser need to know if a property has parameters, the
+                       index parameter doesn't count (PFV) }
+                     if not(propertyparas.empty) then
+                       include(p.propoptions,ppo_hasparameters);
                   end;
                   end;
                 { overriden property ?                                 }
                 { overriden property ?                                 }
                 { force property interface, if there is a property parameter }
                 { force property interface, if there is a property parameter }
@@ -344,9 +349,6 @@ implementation
                           propertyparas.insert(hp2);
                           propertyparas.insert(hp2);
                           pt.free;
                           pt.free;
                        end;
                        end;
-                     { the parser need to know if a property has parameters }
-                     if not(propertyparas.empty) then
-                       include(p.propoptions,ppo_hasparameters);
                   end
                   end
                 else
                 else
                   begin
                   begin
@@ -388,9 +390,16 @@ implementation
                           end;
                           end;
                         varsym :
                         varsym :
                           begin
                           begin
-                            if not(propertyparas.empty) or
-                               not(is_equal(p.readaccess.def,p.proptype.def)) then
-                              Message(parser_e_ill_property_access_sym);
+                            if CheckTypes(p.readaccess.def,p.proptype.def) then
+                             begin
+                               { property parameters are allowed if this is
+                                 an indexed property, because the index is then
+                                 the parameter.
+                                 Note: In the help of Kylix it is written
+                                 that it isn't allowed, but the compiler accepts it (PFV) }
+                               if (ppo_hasparameters in p.propoptions) then
+                                Message(parser_e_ill_property_access_sym);
+                             end;
                           end;
                           end;
                         else
                         else
                           Message(parser_e_ill_property_access_sym);
                           Message(parser_e_ill_property_access_sym);
@@ -417,9 +426,16 @@ implementation
                           end;
                           end;
                         varsym :
                         varsym :
                           begin
                           begin
-                            if not(propertyparas.empty) or
-                               not(is_equal(p.writeaccess.def,p.proptype.def)) then
-                              Message(parser_e_ill_property_access_sym);
+                            if CheckTypes(p.writeaccess.def,p.proptype.def) then
+                             begin
+                               { property parameters are allowed if this is
+                                 an indexed property, because the index is then
+                                 the parameter.
+                                 Note: In the help of Kylix it is written
+                                 that it isn't allowed, but the compiler accepts it (PFV) }
+                               if (ppo_hasparameters in p.propoptions) then
+                                Message(parser_e_ill_property_access_sym);
+                             end;
                           end;
                           end;
                         else
                         else
                           Message(parser_e_ill_property_access_sym);
                           Message(parser_e_ill_property_access_sym);
@@ -461,7 +477,7 @@ implementation
                                    end;
                                    end;
                                  varsym :
                                  varsym :
                                    begin
                                    begin
-                                     if not(propertyparas.empty) or
+                                     if (ppo_hasparameters in p.propoptions) or
                                         not(is_boolean(p.storedaccess.def)) then
                                         not(is_boolean(p.storedaccess.def)) then
                                       Message(parser_e_stored_property_must_be_boolean);
                                       Message(parser_e_stored_property_must_be_boolean);
                                    end;
                                    end;
@@ -1078,7 +1094,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.30  2001-10-21 12:33:06  peter
+  Revision 1.31  2001-10-21 13:10:50  peter
+    * better support for indexed properties
+
+  Revision 1.30  2001/10/21 12:33:06  peter
     * array access for properties added
     * array access for properties added
 
 
   Revision 1.29  2001/08/30 20:13:53  peter
   Revision 1.29  2001/08/30 20:13:53  peter

+ 18 - 14
compiler/pexpr.pas

@@ -721,7 +721,7 @@ implementation
          paras:=nil;
          paras:=nil;
          { property parameters? read them only if the property really }
          { property parameters? read them only if the property really }
          { has parameters                                             }
          { has parameters                                             }
-         if ppo_hasparameters in tpropertysym(sym).propoptions then
+         if (ppo_hasparameters in tpropertysym(sym).propoptions) then
            begin
            begin
               if token=_LECKKLAMMER then
               if token=_LECKKLAMMER then
                 begin
                 begin
@@ -729,12 +729,12 @@ implementation
                    paras:=parse_paras(false,true);
                    paras:=parse_paras(false,true);
                    consume(_RECKKLAMMER);
                    consume(_RECKKLAMMER);
                 end;
                 end;
-              { indexed property }
-              if (ppo_indexed in tpropertysym(sym).propoptions) then
-                begin
-                   p2:=cordconstnode.create(tpropertysym(sym).index,tpropertysym(sym).indextype);
-                   paras:=ccallparanode.create(p2,paras);
-                end;
+           end;
+         { indexed property }
+         if (ppo_indexed in tpropertysym(sym).propoptions) then
+           begin
+              p2:=cordconstnode.create(tpropertysym(sym).index,tpropertysym(sym).indextype);
+              paras:=ccallparanode.create(p2,paras);
            end;
            end;
          { we need only a write property if a := follows }
          { we need only a write property if a := follows }
          { if not(afterassignment) and not(in_args) then }
          { if not(afterassignment) and not(in_args) then }
@@ -749,6 +749,7 @@ implementation
                          { generate the method call }
                          { generate the method call }
                          p1:=ccallnode.create(paras,
                          p1:=ccallnode.create(paras,
                                               tprocsym(tpropertysym(sym).writeaccess.firstsym^.sym),st,p1);
                                               tprocsym(tpropertysym(sym).writeaccess.firstsym^.sym),st,p1);
+                         paras:=nil;
                          consume(_ASSIGNMENT);
                          consume(_ASSIGNMENT);
                          { read the expression }
                          { read the expression }
                          getprocvar:=(tpropertysym(sym).proptype.def.deftype=procvardef);
                          getprocvar:=(tpropertysym(sym).proptype.def.deftype=procvardef);
@@ -761,9 +762,7 @@ implementation
                        end;
                        end;
                      varsym :
                      varsym :
                        begin
                        begin
-                         if assigned(paras) then
-                           message(parser_e_no_paras_allowed);
-                         { subscribed access? }
+                         { generate access code }
                          symlist_to_node(p1,tpropertysym(sym).writeaccess);
                          symlist_to_node(p1,tpropertysym(sym).writeaccess);
                          consume(_ASSIGNMENT);
                          consume(_ASSIGNMENT);
                          { read the expression }
                          { read the expression }
@@ -791,15 +790,14 @@ implementation
                    case tpropertysym(sym).readaccess.firstsym^.sym.typ of
                    case tpropertysym(sym).readaccess.firstsym^.sym.typ of
                      varsym :
                      varsym :
                        begin
                        begin
-                          if assigned(paras) then
-                            message(parser_e_no_paras_allowed);
-                          { subscribed access? }
+                          { generate access code }
                           symlist_to_node(p1,tpropertysym(sym).readaccess);
                           symlist_to_node(p1,tpropertysym(sym).readaccess);
                        end;
                        end;
                      procsym :
                      procsym :
                        begin
                        begin
                           { generate the method call }
                           { generate the method call }
                           p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).readaccess.firstsym^.sym),st,p1);
                           p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).readaccess.firstsym^.sym),st,p1);
+                          paras:=nil;
                           include(p1.flags,nf_isproperty);
                           include(p1.flags,nf_isproperty);
                        end
                        end
                      else
                      else
@@ -816,6 +814,9 @@ implementation
                    Message(parser_e_no_procedure_to_access_property);
                    Message(parser_e_no_procedure_to_access_property);
                 end;
                 end;
            end;
            end;
+        { release paras if not used }
+        if assigned(paras) then
+         paras.free;
       end;
       end;
 
 
 
 
@@ -2332,7 +2333,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.45  2001-10-21 12:33:07  peter
+  Revision 1.46  2001-10-21 13:10:51  peter
+    * better support for indexed properties
+
+  Revision 1.45  2001/10/21 12:33:07  peter
     * array access for properties added
     * array access for properties added
 
 
   Revision 1.44  2001/10/20 19:28:39  peter
   Revision 1.44  2001/10/20 19:28:39  peter