소스 검색

compiler: don't treat TRUE and FALSE as keywords. They are predefined constants from this moment. This change is compatible with other pascal compilers. Fixes issue #0025030

git-svn-id: trunk@25497 -
paul 12 년 전
부모
커밋
0d8ad2a932
7개의 변경된 파일135개의 추가작업 그리고 116개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 77 89
      compiler/pdecvar.pas
  3. 0 22
      compiler/pexpr.pas
  4. 1 1
      compiler/pmodules.pas
  5. 2 0
      compiler/psystem.pas
  6. 0 4
      compiler/tokens.pas
  7. 54 0
      tests/webtbs/tw25030.pp

+ 1 - 0
.gitattributes

@@ -13576,6 +13576,7 @@ tests/webtbs/tw2494.pp svneol=native#text/plain
 tests/webtbs/tw24953.pp svneol=native#text/pascal
 tests/webtbs/tw25004.pp svneol=native#text/pascal
 tests/webtbs/tw2503.pp svneol=native#text/plain
+tests/webtbs/tw25030.pp svneol=native#text/pascal
 tests/webtbs/tw2504.pp svneol=native#text/plain
 tests/webtbs/tw2514.pp svneol=native#text/plain
 tests/webtbs/tw2525.pp svneol=native#text/plain

+ 77 - 89
compiler/pdecvar.pas

@@ -681,96 +681,84 @@ implementation
               begin
                 include(p.propoptions,ppo_stored);
                 p.propaccesslist[palt_stored].clear;
-                case token of
-                  _ID:
-                    begin
-                      { in the case that idtoken=_DEFAULT }
-                      { we have to do nothing except      }
-                      { setting ppo_stored, it's the same }
-                      { as stored true                    }
-                      if idtoken<>_DEFAULT then
-                       begin
-                         { parse_symlist cannot deal with constsyms, and
-                           we also don't want to put constsyms in symlists
-                           since they have to be evaluated immediately rather
-                           than each time the property is accessed
-
-                           The proper fix would be to always create a parse tree
-                           and then convert that one, if appropriate, to a symlist.
-                           Currently, we e.g. don't support any constant expressions
-                           yet either here, while Delphi does.
-
-                         }
-                         { make sure we don't let constants mask class fields/
-                           methods
-                         }
-                         if (not assigned(astruct) or
-                             (search_struct_member(astruct,pattern)=nil)) and
-                            searchsym(pattern,sym,srsymtable) and
-                            (sym.typ = constsym) then
-                           begin
-                              addsymref(sym);
-                              if not is_boolean(tconstsym(sym).constdef) then
-                                Message(parser_e_stored_property_must_be_boolean)
-                              else if (tconstsym(sym).value.valueord=0) then
-                                { same as for _FALSE }
-                                exclude(p.propoptions,ppo_stored)
-                              else
-                                { same as for _TRUE }
-                                p.default:=longint($80000000);
-                              consume(_ID);
-                            end
-                         else if parse_symlist(p.propaccesslist[palt_stored],def) then
-                          begin
-                            sym:=p.propaccesslist[palt_stored].firstsym^.sym;
-                            case sym.typ of
-                              procsym :
-                                begin
-                                   { Create a temporary procvardef to handle parameters }
-                                   storedprocdef:=tprocvardef.create(normal_function_level);
-                                   include(storedprocdef.procoptions,po_methodpointer);
-                                   { Return type must be boolean }
-                                   storedprocdef.returndef:=pasbool8type;
-                                   { Add index parameter if needed }
-                                   if ppo_indexed in p.propoptions then
-                                     begin
-                                       hparavs:=tparavarsym.create('$index',10,vs_value,p.indexdef,[]);
-                                       storedprocdef.parast.insert(hparavs);
-                                     end;
-
-                                   { Insert hidden parameters }
-                                   handle_calling_convention(storedprocdef);
-                                   p.propaccesslist[palt_stored].procdef:=Tprocsym(sym).Find_procdef_bypara(storedprocdef.paras,storedprocdef.returndef,[cpo_allowdefaults,cpo_ignorehidden]);
-                                   if not assigned(p.propaccesslist[palt_stored].procdef) then
-                                     message(parser_e_ill_property_storage_sym);
-                                   { Not needed anymore }
-                                   storedprocdef.owner.deletedef(storedprocdef);
-                                end;
-                              fieldvarsym :
-                                begin
-                                  if not assigned(def) then
-                                    internalerror(200310073);
-                                  if (ppo_hasparameters in p.propoptions) or
-                                     not(is_boolean(def)) then
-                                   Message(parser_e_stored_property_must_be_boolean);
-                                end;
-                              else
-                                Message(parser_e_ill_property_access_sym);
-                            end;
+                if token=_ID then
+                  begin
+                    { in the case that idtoken=_DEFAULT }
+                    { we have to do nothing except      }
+                    { setting ppo_stored, it's the same }
+                    { as stored true                    }
+                    if idtoken<>_DEFAULT then
+                     begin
+                       { parse_symlist cannot deal with constsyms, and
+                         we also don't want to put constsyms in symlists
+                         since they have to be evaluated immediately rather
+                         than each time the property is accessed
+
+                         The proper fix would be to always create a parse tree
+                         and then convert that one, if appropriate, to a symlist.
+                         Currently, we e.g. don't support any constant expressions
+                         yet either here, while Delphi does.
+
+                       }
+                       { make sure we don't let constants mask class fields/
+                         methods
+                       }
+                       if (not assigned(astruct) or
+                           (search_struct_member(astruct,pattern)=nil)) and
+                          searchsym(pattern,sym,srsymtable) and
+                          (sym.typ = constsym) then
+                         begin
+                            addsymref(sym);
+                            if not is_boolean(tconstsym(sym).constdef) then
+                              Message(parser_e_stored_property_must_be_boolean)
+                            else if (tconstsym(sym).value.valueord=0) then
+                              { same as for _FALSE }
+                              exclude(p.propoptions,ppo_stored)
+                            else
+                              { same as for _TRUE }
+                              p.default:=longint($80000000);
+                            consume(_ID);
+                          end
+                       else if parse_symlist(p.propaccesslist[palt_stored],def) then
+                        begin
+                          sym:=p.propaccesslist[palt_stored].firstsym^.sym;
+                          case sym.typ of
+                            procsym :
+                              begin
+                                 { Create a temporary procvardef to handle parameters }
+                                 storedprocdef:=tprocvardef.create(normal_function_level);
+                                 include(storedprocdef.procoptions,po_methodpointer);
+                                 { Return type must be boolean }
+                                 storedprocdef.returndef:=pasbool8type;
+                                 { Add index parameter if needed }
+                                 if ppo_indexed in p.propoptions then
+                                   begin
+                                     hparavs:=tparavarsym.create('$index',10,vs_value,p.indexdef,[]);
+                                     storedprocdef.parast.insert(hparavs);
+                                   end;
+
+                                 { Insert hidden parameters }
+                                 handle_calling_convention(storedprocdef);
+                                 p.propaccesslist[palt_stored].procdef:=Tprocsym(sym).Find_procdef_bypara(storedprocdef.paras,storedprocdef.returndef,[cpo_allowdefaults,cpo_ignorehidden]);
+                                 if not assigned(p.propaccesslist[palt_stored].procdef) then
+                                   message(parser_e_ill_property_storage_sym);
+                                 { Not needed anymore }
+                                 storedprocdef.owner.deletedef(storedprocdef);
+                              end;
+                            fieldvarsym :
+                              begin
+                                if not assigned(def) then
+                                  internalerror(200310073);
+                                if (ppo_hasparameters in p.propoptions) or
+                                   not(is_boolean(def)) then
+                                 Message(parser_e_stored_property_must_be_boolean);
+                              end;
+                            else
+                              Message(parser_e_ill_property_access_sym);
                           end;
-                       end;
-                    end;
-                  _FALSE:
-                    begin
-                      consume(_FALSE);
-                      exclude(p.propoptions,ppo_stored);
-                    end;
-                  _TRUE:
-                    begin
-                      p.default:=longint($80000000);
-                      consume(_TRUE);
-                    end;
-                end;
+                        end;
+                     end;
+                  end;
               end;
            end;
          if not is_record(astruct) and try_to_consume(_DEFAULT) then

+ 0 - 22
compiler/pexpr.pas

@@ -3280,28 +3280,6 @@ implementation
                  p1:=cnotnode.create(p1);
                end;
 
-             _TRUE :
-               begin
-                 consume(_TRUE);
-                 p1:=cordconstnode.create(1,pasbool8type,false);
-                 if token=_POINT then
-                   begin
-                     again:=true;
-                     postfixoperators(p1,again,getaddr);
-                   end;
-               end;
-
-             _FALSE :
-               begin
-                 consume(_FALSE);
-                 p1:=cordconstnode.create(0,pasbool8type,false);
-                 if token=_POINT then
-                   begin
-                     again:=true;
-                     postfixoperators(p1,again,getaddr);
-                   end;
-               end;
-
              _NIL :
                begin
                  consume(_NIL);

+ 1 - 1
compiler/pmodules.pas

@@ -281,8 +281,8 @@ implementation
          begin
            systemunit:=tglobalsymtable(current_module.localsymtable);
            { create system defines }
-           create_intern_symbols;
            create_intern_types;
+           create_intern_symbols;
            { Set the owner of errorsym and errortype to symtable to
              prevent crashes when accessing .owner }
            generrorsym.owner:=systemunit;

+ 2 - 0
compiler/psystem.pas

@@ -104,6 +104,8 @@ implementation
         systemunit.insert(tsyssym.create('ObjCSelector',in_objc_selector_x)); { objc only }
         systemunit.insert(tsyssym.create('ObjCEncode',in_objc_encode_x)); { objc only }
         systemunit.insert(tsyssym.create('Default',in_default_x));
+        systemunit.insert(tconstsym.create_ord('False',constord,0,pasbool8type));
+        systemunit.insert(tconstsym.create_ord('True',constord,1,pasbool8type));
       end;
 
 

+ 0 - 4
compiler/tokens.pas

@@ -141,7 +141,6 @@ type
     _SELF,
     _SYSV,
     _THEN,
-    _TRUE,
     _TYPE,
     _UNIT,
     _UNIV,
@@ -155,7 +154,6 @@ type
     _CLASS,
     _CONST,
     _EQUAL,
-    _FALSE,
     _FAR16,
     _FINAL,
     _INDEX,
@@ -459,7 +457,6 @@ const
       (str:'SELF'          ;special:false;keyword:[m_none];op:NOTOKEN), {set inside methods only PM }
       (str:'SYSV'          ;special:false;keyword:[m_none];op:NOTOKEN),   { Syscall variation on MorphOS }
       (str:'THEN'          ;special:false;keyword:alllanguagemodes;op:NOTOKEN),
-      (str:'TRUE'          ;special:false;keyword:alllanguagemodes;op:NOTOKEN),
       (str:'TYPE'          ;special:false;keyword:alllanguagemodes;op:NOTOKEN),
       (str:'UNIT'          ;special:false;keyword:alllanguagemodes-[m_iso];op:NOTOKEN),
       (str:'UNIV'          ;special:false;keyword:[m_mac];op:NOTOKEN),
@@ -473,7 +470,6 @@ const
       (str:'CLASS'         ;special:false;keyword:[m_class];op:NOTOKEN),
       (str:'CONST'         ;special:false;keyword:alllanguagemodes;op:NOTOKEN),
       (str:'EQUAL'         ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name }
-      (str:'FALSE'         ;special:false;keyword:alllanguagemodes;op:NOTOKEN),
       (str:'FAR16'         ;special:false;keyword:[m_none];op:NOTOKEN),
       (str:'FINAL'         ;special:false;keyword:[m_none];op:NOTOKEN),
       (str:'INDEX'         ;special:false;keyword:[m_none];op:NOTOKEN),

+ 54 - 0
tests/webtbs/tw25030.pp

@@ -0,0 +1,54 @@
+program tw25030;
+
+{$MODE DELPHI}
+
+type
+
+  { TInteger32Boolean }
+
+  TInteger32Boolean = record
+  public
+    Value: Integer;
+    const
+      FALSE = 0;
+      TRUE = 1;
+
+    class operator Implicit(const Operand: TInteger32Boolean): Boolean;
+    class operator Implicit(Operand: Boolean): TInteger32Boolean;
+    class operator LogicalNot(const Operand: TInteger32Boolean): TInteger32Boolean;
+  end;
+
+{ TInteger32Boolean }
+
+class operator TInteger32Boolean.Implicit(const Operand: TInteger32Boolean): Boolean;
+begin
+  Result := Operand.Value <> FALSE;
+end;
+
+class operator TInteger32Boolean.Implicit(Operand: Boolean): TInteger32Boolean;
+begin
+  if Operand then
+    Result.Value := TRUE
+  else
+    Result.Value := FALSE;
+end;
+
+class operator TInteger32Boolean.LogicalNot(const Operand: TInteger32Boolean): TInteger32Boolean;
+begin
+  if Operand then
+    Result.Value := FALSE
+  else
+    Result.Value := TRUE;
+end;
+
+var
+  IntegerBoolean: TInteger32Boolean;
+
+begin
+  IntegerBoolean := True;
+  if IntegerBoolean.Value<>1 then
+    halt(1);
+
+  if not IntegerBoolean then
+    halt(2);
+end.