瀏覽代碼

compiler: modernize exception class parse:
- use specially implemented type search routine in case of declaration with colon (on E: Exception do)
- parse nested types in case of declaration without colon (on Exception do)
+ test

fixes issue #0022225

git-svn-id: trunk@25412 -

paul 12 年之前
父節點
當前提交
115ddf4364
共有 4 個文件被更改,包括 43 次插入27 次删除
  1. 1 0
      .gitattributes
  2. 22 27
      compiler/pstatmnt.pas
  3. 3 0
      compiler/ptype.pas
  4. 17 0
      tests/webtbs/tw22225.pp

+ 1 - 0
.gitattributes

@@ -13399,6 +13399,7 @@ tests/webtbs/tw22155.pp svneol=native#text/plain
 tests/webtbs/tw22160a1.pp svneol=native#text/pascal
 tests/webtbs/tw22160b1.pp svneol=native#text/pascal
 tests/webtbs/tw2220.pp svneol=native#text/plain
+tests/webtbs/tw22225.pp svneol=native#text/pascal
 tests/webtbs/tw2226.pp svneol=native#text/plain
 tests/webtbs/tw2229.pp svneol=native#text/plain
 tests/webtbs/tw22290.pp svneol=native#text/plain

+ 22 - 27
compiler/pstatmnt.pas

@@ -53,7 +53,7 @@ implementation
        nutils,ngenutil,nbas,nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,
        { parser }
        scanner,
-       pbase,pexpr,
+       pbase,ptype,pexpr,
        { codegen }
        procinfo,cgbase,
        { assembler reader }
@@ -900,22 +900,13 @@ implementation
                           { is a explicit name for the exception given ? }
                           if try_to_consume(_COLON) then
                             begin
-                               consume_sym(srsym,srsymtable);
-                               if (srsym.typ=typesym) and
-                                  (is_class(ttypesym(srsym).typedef) or
-                                   is_javaclass(ttypesym(srsym).typedef)) then
-                                 begin
-                                    ot:=ttypesym(srsym).typedef;
-                                    sym:=tlocalvarsym.create(objrealname,vs_value,ot,[]);
-                                 end
-                               else
-                                 begin
-                                    sym:=tlocalvarsym.create(objrealname,vs_value,generrordef,[]);
-                                    if (srsym.typ=typesym) then
-                                      Message1(type_e_class_type_expected,ttypesym(srsym).typedef.typename)
-                                    else
-                                      Message1(type_e_class_type_expected,ot.typename);
-                                 end;
+                              single_type(ot,[]);
+                              if not (is_class(ot) or is_javaclass(ot)) then
+                                begin
+                                  Message1(type_e_class_type_expected,ot.typename);
+                                  ot:=generrordef;
+                                end;
+                              sym:=tlocalvarsym.create(objrealname,vs_value,ot,[]);
                             end
                           else
                             begin
@@ -933,19 +924,23 @@ implementation
                                  consume(t);
                                { check if type is valid, must be done here because
                                  with "e: Exception" the e is not necessary }
-                               if (srsym.typ=typesym) and
-                                  (is_class(ttypesym(srsym).typedef) or
-                                   is_javaclass(ttypesym(srsym).typedef)) then
-                                 ot:=ttypesym(srsym).typedef
+                               if (srsym.typ=typesym) then
+                                 begin
+                                   ot:=ttypesym(srsym).typedef;
+                                   parse_nested_types(ot,false,nil);
+                                   if not (is_class(ot) or is_javaclass(ot)) then
+                                     begin
+                                       Message1(type_e_class_type_expected,ot.typename);
+                                       ot:=generrordef;
+                                     end;
+                                 end
                                else
                                  begin
-                                    ot:=generrordef;
-                                    if (srsym.typ=typesym) then
-                                      Message1(type_e_class_type_expected,ttypesym(srsym).typedef.typename)
-                                    else
-                                      Message1(type_e_class_type_expected,ot.typename);
+                                   Message(type_e_type_id_expected);
+                                   ot:=generrordef;
                                  end;
-                               { create dummy symbol so we don't need a special
+
+                                 { create dummy symbol so we don't need a special
                                  case in ncgflw, and so that we always know the
                                  type }
                                sym:=tlocalvarsym.create('$exceptsym',vs_value,ot,[]);

+ 3 - 0
compiler/ptype.pas

@@ -49,6 +49,9 @@ interface
     { reads any type declaration }
     procedure read_anon_type(var def : tdef;parseprocvardir:boolean);
 
+    { parse nested type declaration of the def (typedef) }
+    procedure parse_nested_types(var def: tdef; isforwarddef: boolean; currentstructstack: tfpobjectlist);
+
 
     { add a definition for a method to a record/objectdef that will contain
       all code for initialising typed constants (only for targets in

+ 17 - 0
tests/webtbs/tw22225.pp

@@ -0,0 +1,17 @@
+{ %NORUN }
+
+program tw22225;
+
+{$mode objfpc}
+type
+  TT = class
+  public 
+    type 
+      TErr = class 
+      end;
+  end;
+begin
+  try
+  except on TT.TErr do;
+  end;
+end.