浏览代码

+ accept system.string, resolves #10489

git-svn-id: trunk@9727 -
florian 17 年之前
父节点
当前提交
2d91fef4f1
共有 5 个文件被更改,包括 56 次插入12 次删除
  1. 1 0
      .gitattributes
  2. 29 8
      compiler/pbase.pas
  3. 3 2
      compiler/pexpr.pas
  4. 3 2
      compiler/ptype.pas
  5. 20 0
      tests/webtbs/tw10489.pp

+ 1 - 0
.gitattributes

@@ -7966,6 +7966,7 @@ tests/webtbs/tw10425.pp svneol=native#text/plain
 tests/webtbs/tw1044.pp svneol=native#text/plain
 tests/webtbs/tw1044.pp svneol=native#text/plain
 tests/webtbs/tw10454.pp svneol=native#text/plain
 tests/webtbs/tw10454.pp svneol=native#text/plain
 tests/webtbs/tw1046.pp svneol=native#text/plain
 tests/webtbs/tw1046.pp svneol=native#text/plain
+tests/webtbs/tw10489.pp svneol=native#text/plain
 tests/webtbs/tw1050.pp svneol=native#text/plain
 tests/webtbs/tw1050.pp svneol=native#text/plain
 tests/webtbs/tw10540.pp svneol=native#text/plain
 tests/webtbs/tw10540.pp svneol=native#text/plain
 tests/webtbs/tw1061.pp svneol=native#text/plain
 tests/webtbs/tw1061.pp svneol=native#text/plain

+ 29 - 8
compiler/pbase.pas

@@ -88,7 +88,7 @@ interface
     function consume_sym(var srsym:tsym;var srsymtable:TSymtable):boolean;
     function consume_sym(var srsym:tsym;var srsymtable:TSymtable):boolean;
     function consume_sym_orgid(var srsym:tsym;var srsymtable:TSymtable;var s : string):boolean;
     function consume_sym_orgid(var srsym:tsym;var srsymtable:TSymtable;var s : string):boolean;
 
 
-    function try_consume_unitsym(var srsym:tsym;var srsymtable:TSymtable):boolean;
+    function try_consume_unitsym(var srsym:tsym;var srsymtable:TSymtable;var tokentoconsume : ttoken):boolean;
 
 
     function try_consume_hintdirective(var symopt:tsymoptions):boolean;
     function try_consume_hintdirective(var symopt:tsymoptions):boolean;
 
 
@@ -100,7 +100,7 @@ interface
 implementation
 implementation
 
 
     uses
     uses
-       globals,htypechk,scanner,systems,verbose;
+       globals,htypechk,scanner,systems,verbose,fmodule;
 
 
 {****************************************************************************
 {****************************************************************************
                                Token Parsing
                                Token Parsing
@@ -177,6 +177,8 @@ implementation
       must be changed as well (FK)
       must be changed as well (FK)
     }
     }
     function consume_sym(var srsym:tsym;var srsymtable:TSymtable):boolean;
     function consume_sym(var srsym:tsym;var srsymtable:TSymtable):boolean;
+      var
+        t : ttoken;
       begin
       begin
         { first check for identifier }
         { first check for identifier }
         if token<>_ID then
         if token<>_ID then
@@ -189,7 +191,7 @@ implementation
           end;
           end;
         searchsym(pattern,srsym,srsymtable);
         searchsym(pattern,srsym,srsymtable);
         { handle unit specification like System.Writeln }
         { handle unit specification like System.Writeln }
-        try_consume_unitsym(srsym,srsymtable);
+        try_consume_unitsym(srsym,srsymtable,t);
         { if nothing found give error and return errorsym }
         { if nothing found give error and return errorsym }
         if assigned(srsym) then
         if assigned(srsym) then
           check_hints(srsym,srsym.symoptions)
           check_hints(srsym,srsym.symoptions)
@@ -199,7 +201,7 @@ implementation
             srsym:=generrorsym;
             srsym:=generrorsym;
             srsymtable:=nil;
             srsymtable:=nil;
           end;
           end;
-        consume(_ID);
+        consume(t);
         result:=assigned(srsym);
         result:=assigned(srsym);
       end;
       end;
 
 
@@ -208,6 +210,8 @@ implementation
       if required and returns the id with it's original casing
       if required and returns the id with it's original casing
     }
     }
     function consume_sym_orgid(var srsym:tsym;var srsymtable:TSymtable;var s : string):boolean;
     function consume_sym_orgid(var srsym:tsym;var srsymtable:TSymtable;var s : string):boolean;
+      var
+        t : ttoken;
       begin
       begin
         { first check for identifier }
         { first check for identifier }
         if token<>_ID then
         if token<>_ID then
@@ -220,7 +224,7 @@ implementation
           end;
           end;
         searchsym(pattern,srsym,srsymtable);
         searchsym(pattern,srsym,srsymtable);
         { handle unit specification like System.Writeln }
         { handle unit specification like System.Writeln }
-        try_consume_unitsym(srsym,srsymtable);
+        try_consume_unitsym(srsym,srsymtable,t);
         { if nothing found give error and return errorsym }
         { if nothing found give error and return errorsym }
         if assigned(srsym) then
         if assigned(srsym) then
           check_hints(srsym,srsym.symoptions)
           check_hints(srsym,srsym.symoptions)
@@ -231,13 +235,15 @@ implementation
             srsymtable:=nil;
             srsymtable:=nil;
           end;
           end;
         s:=orgpattern;
         s:=orgpattern;
-        consume(_ID);
+        consume(t);
         result:=assigned(srsym);
         result:=assigned(srsym);
       end;
       end;
 
 
-    function try_consume_unitsym(var srsym:tsym;var srsymtable:TSymtable):boolean;
+
+    function try_consume_unitsym(var srsym:tsym;var srsymtable:TSymtable;var tokentoconsume : ttoken):boolean;
       begin
       begin
         result:=false;
         result:=false;
+        tokentoconsume:=_ID;
         if assigned(srsym) and
         if assigned(srsym) and
            (srsym.typ=unitsym) then
            (srsym.typ=unitsym) then
           begin
           begin
@@ -249,7 +255,22 @@ implementation
               begin
               begin
                 consume(_ID);
                 consume(_ID);
                 consume(_POINT);
                 consume(_POINT);
-                searchsym_in_module(tunitsym(srsym).module,pattern,srsym,srsymtable);
+                case token of
+                  _ID:
+                     searchsym_in_module(tunitsym(srsym).module,pattern,srsym,srsymtable);
+                  _STRING:
+                    begin
+                      { system.string? }
+                      if tmodule(tunitsym(srsym).module).globalsymtable=systemunit then
+                        begin
+                          if cs_ansistrings in current_settings.localswitches then
+                            searchsym_in_module(tunitsym(srsym).module,'ANSISTRING',srsym,srsymtable)
+                          else
+                            searchsym_in_module(tunitsym(srsym).module,'SHORTSTRING',srsym,srsymtable);
+                          tokentoconsume:=_STRING;
+                        end;
+                    end
+                  end;
               end
               end
             else
             else
               begin
               begin

+ 3 - 2
compiler/pexpr.pas

@@ -1367,6 +1367,7 @@ implementation
            orgstoredpattern,
            orgstoredpattern,
            storedpattern : string;
            storedpattern : string;
            len   : longint;
            len   : longint;
+           t : ttoken;
          begin
          begin
            { allow post fix operators }
            { allow post fix operators }
            again:=true;
            again:=true;
@@ -1383,10 +1384,10 @@ implementation
                searchsym(pattern,srsym,srsymtable);
                searchsym(pattern,srsym,srsymtable);
 
 
                { handle unit specification like System.Writeln }
                { handle unit specification like System.Writeln }
-               unit_found:=try_consume_unitsym(srsym,srsymtable);
+               unit_found:=try_consume_unitsym(srsym,srsymtable,t);
                storedpattern:=pattern;
                storedpattern:=pattern;
                orgstoredpattern:=orgpattern;
                orgstoredpattern:=orgpattern;
-               consume(_ID);
+               consume(t);
 
 
                { named parameter support }
                { named parameter support }
                found_arg_name:=false;
                found_arg_name:=false;

+ 3 - 2
compiler/ptype.pas

@@ -277,6 +277,7 @@ implementation
         srsym : tsym;
         srsym : tsym;
         srsymtable : TSymtable;
         srsymtable : TSymtable;
         s,sorg : TIDString;
         s,sorg : TIDString;
+        t : ttoken;
       begin
       begin
          s:=pattern;
          s:=pattern;
          sorg:=orgpattern;
          sorg:=orgpattern;
@@ -299,8 +300,8 @@ implementation
            parameters }
            parameters }
          searchsym_type(s,srsym,srsymtable);
          searchsym_type(s,srsym,srsymtable);
          { handle unit specification like System.Writeln }
          { handle unit specification like System.Writeln }
-         is_unit_specific:=try_consume_unitsym(srsym,srsymtable);
-         consume(_ID);
+         is_unit_specific:=try_consume_unitsym(srsym,srsymtable,t);
+         consume(t);
          { Types are first defined with an error def before assigning
          { Types are first defined with an error def before assigning
            the real type so check if it's an errordef. if so then
            the real type so check if it's an errordef. if so then
            give an error. Only check for typesyms in the current symbol
            give an error. Only check for typesyms in the current symbol

+ 20 - 0
tests/webtbs/tw10489.pp

@@ -0,0 +1,20 @@
+{$mode objfpc}
+program test;
+
+uses
+  TypInfo;
+
+function GetTypeInfo(const i: Integer): PTypeInfo;
+begin
+  case i of
+    0: Result := TypeInfo(System.Integer);
+    1: Result := TypeInfo(System.Int64);
+    2: Result := TypeInfo(System.String); //syntax error
+    3: Result := TypeInfo(System.WideString);
+  else
+    Result := nil;
+  end;
+end;
+
+begin
+end.