Forráskód Böngészése

* Add operator support

git-svn-id: trunk@193 -
daniel 20 éve
szülő
commit
cd01ab8935
3 módosított fájl, 189 hozzáadás és 164 törlés
  1. 12 12
      fcl/passrc/paswrite.pp
  2. 130 105
      fcl/passrc/pparser.pp
  3. 47 47
      fcl/passrc/pscanner.pp

+ 12 - 12
fcl/passrc/paswrite.pp

@@ -26,18 +26,18 @@ type
   private
   private
     FStream: TStream;
     FStream: TStream;
     IsStartOfLine: Boolean;
     IsStartOfLine: Boolean;
-    Indent, CurDeclSection: String;
+    Indent, CurDeclSection: string;
     DeclSectionStack: TList;
     DeclSectionStack: TList;
     procedure IncIndent;
     procedure IncIndent;
     procedure DecIndent;
     procedure DecIndent;
     procedure IncDeclSectionLevel;
     procedure IncDeclSectionLevel;
     procedure DecDeclSectionLevel;
     procedure DecDeclSectionLevel;
-    procedure PrepareDeclSection(const ADeclSection: String);
+    procedure PrepareDeclSection(const ADeclSection: string);
   public
   public
     constructor Create(AStream: TStream);
     constructor Create(AStream: TStream);
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure wrt(const s: String);
-    procedure wrtln(const s: String);
+    procedure wrt(const s: string);
+    procedure wrtln(const s: string);
     procedure wrtln;
     procedure wrtln;
 
 
     procedure WriteElement(AElement: TPasElement);
     procedure WriteElement(AElement: TPasElement);
@@ -60,7 +60,7 @@ type
   end;
   end;
 
 
 
 
-procedure WritePasFile(AElement: TPasElement; const AFilename: String);
+procedure WritePasFile(AElement: TPasElement; const AFilename: string);
 procedure WritePasFile(AElement: TPasElement; AStream: TStream);
 procedure WritePasFile(AElement: TPasElement; AStream: TStream);
 
 
 
 
@@ -72,7 +72,7 @@ uses SysUtils;
 type
 type
   PDeclSectionStackElement = ^TDeclSectionStackElement;
   PDeclSectionStackElement = ^TDeclSectionStackElement;
   TDeclSectionStackElement = record
   TDeclSectionStackElement = record
-    LastDeclSection, LastIndent: String;
+    LastDeclSection, LastIndent: string;
   end;
   end;
 
 
 constructor TPasWriter.Create(AStream: TStream);
 constructor TPasWriter.Create(AStream: TStream);
@@ -96,7 +96,7 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPasWriter.wrt(const s: String);
+procedure TPasWriter.wrt(const s: string);
 begin
 begin
   if IsStartOfLine then
   if IsStartOfLine then
   begin
   begin
@@ -108,9 +108,9 @@ begin
 end;
 end;
 
 
 const
 const
-  LF: String = #10;
+  LF: string = #10;
 
 
-procedure TPasWriter.wrtln(const s: String);
+procedure TPasWriter.wrtln(const s: string);
 begin
 begin
   wrt(s);
   wrt(s);
   Stream.Write(LF[1], 1);
   Stream.Write(LF[1], 1);
@@ -468,7 +468,7 @@ end;
 procedure TPasWriter.WriteImplCommands(ACommands: TPasImplCommands);
 procedure TPasWriter.WriteImplCommands(ACommands: TPasImplCommands);
 var
 var
   i: Integer;
   i: Integer;
-  s: String;
+  s: string;
 begin
 begin
   for i := 0 to ACommands.Commands.Count - 1 do
   for i := 0 to ACommands.Commands.Count - 1 do
   begin
   begin
@@ -572,7 +572,7 @@ begin
   Dispose(El);
   Dispose(El);
 end;
 end;
 
 
-procedure TPasWriter.PrepareDeclSection(const ADeclSection: String);
+procedure TPasWriter.PrepareDeclSection(const ADeclSection: string);
 begin
 begin
   if ADeclSection <> CurDeclSection then
   if ADeclSection <> CurDeclSection then
   begin
   begin
@@ -588,7 +588,7 @@ begin
 end;
 end;
 
 
 
 
-procedure WritePasFile(AElement: TPasElement; const AFilename: String);
+procedure WritePasFile(AElement: TPasElement; const AFilename: string);
 var
 var
   Stream: TFileStream;
   Stream: TFileStream;
 begin
 begin

+ 130 - 105
fcl/passrc/pparser.pp

@@ -87,6 +87,8 @@ type
 
 
   TDeclType = (declNone, declConst, declResourcestring, declType, declVar);
   TDeclType = (declNone, declConst, declResourcestring, declType, declVar);
 
 
+  Tproctype = (pt_procedure,pt_function,pt_operator);
+
   TPasParser = class
   TPasParser = class
   private
   private
     FFileResolver: TFileResolver;
     FFileResolver: TFileResolver;
@@ -136,9 +138,9 @@ type
     procedure ParseVarDecl(Parent: TPasElement; List: TList);
     procedure ParseVarDecl(Parent: TPasElement; List: TList);
     procedure ParseArgList(Parent: TPasElement; Args: TList; EndToken: TToken);
     procedure ParseArgList(Parent: TPasElement; Args: TList; EndToken: TToken);
     procedure ParseProcedureOrFunctionHeader(Parent: TPasElement;
     procedure ParseProcedureOrFunctionHeader(Parent: TPasElement;
-      Element: TPasProcedureType; IsFunction, OfObjectPossible: Boolean);
+      Element: TPasProcedureType; proctype:Tproctype; OfObjectPossible: Boolean);
     function ParseProcedureOrFunctionDecl(Parent: TPasElement;
     function ParseProcedureOrFunctionDecl(Parent: TPasElement;
-      IsFunction: Boolean): TPasProcedure;
+      proctype:Tproctype): TPasProcedure;
     procedure ParseRecordDecl(Parent: TPasRecordType);
     procedure ParseRecordDecl(Parent: TPasRecordType);
     function ParseClassDecl(Parent: TPasElement; const AClassName: String;
     function ParseClassDecl(Parent: TPasElement; const AClassName: String;
       AObjKind: TPasObjKind): TPasType;
       AObjKind: TPasObjKind): TPasType;
@@ -379,7 +381,7 @@ begin
     tkBraceOpen:
     tkBraceOpen:
       begin
       begin
         Result := TPasEnumType(CreateElement(TPasEnumType, '', Parent));
         Result := TPasEnumType(CreateElement(TPasEnumType, '', Parent));
-        while True do
+        while true do
         begin
         begin
           NextToken;
           NextToken;
           EnumValue := TPasEnumValue(CreateElement(TPasEnumValue,
           EnumValue := TPasEnumValue(CreateElement(TPasEnumValue,
@@ -418,8 +420,8 @@ begin
         Result := TPasProcedureType(
         Result := TPasProcedureType(
           CreateElement(TPasProcedureType, '', Parent));
           CreateElement(TPasProcedureType, '', Parent));
         try
         try
-          ParseProcedureOrFunctionHeader(Result,
-            TPasProcedureType(Result), False, True);
+          ParseProcedureOrFunctionHeader(Result,TPasProcedureType(Result),
+                                         pt_procedure, true);
         except
         except
           Result.Free;
           Result.Free;
           raise;
           raise;
@@ -427,11 +429,11 @@ begin
       end;
       end;
     tkFunction:
     tkFunction:
       begin
       begin
-        Result := Engine.CreateFunctionType('', Parent, False,
+        Result := Engine.CreateFunctionType('', Parent, false,
           Scanner.CurFilename, Scanner.CurRow);
           Scanner.CurFilename, Scanner.CurRow);
         try
         try
-          ParseProcedureOrFunctionHeader(Result,
-            TPasFunctionType(Result), True, True);
+          ParseProcedureOrFunctionHeader(Result,TPasFunctionType(Result),
+                                         pt_function, true);
         except
         except
           Result.Free;
           Result.Free;
           raise;
           raise;
@@ -453,16 +455,16 @@ begin
     tkProcedure:
     tkProcedure:
       begin
       begin
         Result := TPasProcedureType(CreateElement(TPasProcedureType, '', nil));
         Result := TPasProcedureType(CreateElement(TPasProcedureType, '', nil));
-        ParseProcedureOrFunctionHeader(Result,
-          TPasProcedureType(Result), False, True);
+        ParseProcedureOrFunctionHeader(Result, TPasProcedureType(Result),
+                                       pt_procedure, true);
         UngetToken;        // Unget semicolon
         UngetToken;        // Unget semicolon
       end;
       end;
     tkFunction:
     tkFunction:
       begin
       begin
-        Result := Engine.CreateFunctionType('', nil, False, Scanner.CurFilename,
+        Result := Engine.CreateFunctionType('', nil, false, Scanner.CurFilename,
           Scanner.CurRow);
           Scanner.CurRow);
-        ParseProcedureOrFunctionHeader(Result,
-          TPasFunctionType(Result), True, True);
+        ParseProcedureOrFunctionHeader(Result, TPasFunctionType(Result),
+                                       pt_function, true);
         UngetToken;        // Unget semicolon
         UngetToken;        // Unget semicolon
       end;
       end;
     else
     else
@@ -517,9 +519,9 @@ var
 begin
 begin
   SetLength(Result, 0);
   SetLength(Result, 0);
   BracketLevel := 0;
   BracketLevel := 0;
-  MayAppendSpace := False;
-  AppendSpace := False;
-  while True do
+  MayAppendSpace := false;
+  AppendSpace := false;
+  while true do
   begin
   begin
     NextToken;
     NextToken;
     { !!!: Does not detect when normal brackets and square brackets are mixed
     { !!!: Does not detect when normal brackets and square brackets are mixed
@@ -537,7 +539,7 @@ begin
 
 
     if MayAppendSpace then
     if MayAppendSpace then
     begin
     begin
-      NextAppendSpace := False;
+      NextAppendSpace := false;
       case CurToken of
       case CurToken of
         tkBraceOpen, tkBraceClose, tkDivision, tkEqual, tkCaret, tkAnd, tkAs,
         tkBraceOpen, tkBraceClose, tkDivision, tkEqual, tkCaret, tkAnd, tkAs,
           tkDiv, tkIn, tkIs, tkMinus, tkMod, tkMul, tkNot, tkOf, tkOn,
           tkDiv, tkIn, tkIs, tkMinus, tkMod, tkMul, tkNot, tkOf, tkOn,
@@ -545,15 +547,15 @@ begin
 {        tkPlus.._ASSIGNMENT, _UNEQUAL, tkPlusASN.._XORASN, _AS, _AT, _IN, _IS,
 {        tkPlus.._ASSIGNMENT, _UNEQUAL, tkPlusASN.._XORASN, _AS, _AT, _IN, _IS,
           tkOf, _ON, _OR, _AND, _DIV, _MOD, _NOT, _SHL, _SHR, _XOR:}
           tkOf, _ON, _OR, _AND, _DIV, _MOD, _NOT, _SHL, _SHR, _XOR:}
           begin
           begin
-            AppendSpace := True;
-            NextAppendSpace := True;
+            AppendSpace := true;
+            NextAppendSpace := true;
           end;
           end;
       end;
       end;
       if AppendSpace then
       if AppendSpace then
         Result := Result + ' ';
         Result := Result + ' ';
       AppendSpace := NextAppendSpace;
       AppendSpace := NextAppendSpace;
     end else
     end else
-      MayAppendSpace := True;
+      MayAppendSpace := true;
     if CurToken=tkString then
     if CurToken=tkString then
       begin
       begin
       If (Length(CurTokenText)>0) and (CurTokenText[1]=#0) then
       If (Length(CurTokenText)>0) and (CurTokenText[1]=#0) then
@@ -663,7 +665,7 @@ begin
   Section := TPasSection(CreateElement(TPasSection, '', Module));
   Section := TPasSection(CreateElement(TPasSection, '', Module));
   Module.InterfaceSection := Section;
   Module.InterfaceSection := Section;
   CurBlock := declNone;
   CurBlock := declNone;
-  while True do
+  while true do
   begin
   begin
     NextToken;
     NextToken;
     if CurToken = tkImplementation then
     if CurToken = tkImplementation then
@@ -681,12 +683,12 @@ begin
         CurBlock := declVar;
         CurBlock := declVar;
       tkProcedure:
       tkProcedure:
         begin
         begin
-          AddProcOrFunction(Section, ParseProcedureOrFunctionDecl(Section, False));
+          AddProcOrFunction(Section, ParseProcedureOrFunctionDecl(Section, pt_procedure));
           CurBlock := declNone;
           CurBlock := declNone;
         end;
         end;
       tkFunction:
       tkFunction:
         begin
         begin
-          AddProcOrFunction(Section, ParseProcedureOrFunctionDecl(Section, True));
+          AddProcOrFunction(Section, ParseProcedureOrFunctionDecl(Section, pt_function));
           CurBlock := declNone;
           CurBlock := declNone;
         end;
         end;
       tkProperty:
       tkProperty:
@@ -696,15 +698,7 @@ begin
         end;
         end;
       tkOperator:
       tkOperator:
         begin
         begin
-          // !!!: Not supported yet
-          i := 0;
-          repeat
-            NextToken;
-            if CurToken = tkBraceOpen then
-              Inc(i)
-            else if CurToken = tkBraceClose then
-              Dec(i);
-          until (CurToken = tkSemicolon) and (i = 0);
+          AddProcOrFunction(Section, ParseProcedureOrFunctionDecl(Section, pt_operator));
           CurBlock := declNone;
           CurBlock := declNone;
         end;
         end;
       tkIdentifier:
       tkIdentifier:
@@ -791,7 +785,7 @@ var
   UnitName: String;
   UnitName: String;
   Element: TPasElement;
   Element: TPasElement;
 begin
 begin
-  while True do
+  while true do
   begin
   begin
     UnitName := ExpectIdentifier;
     UnitName := ExpectIdentifier;
 
 
@@ -874,12 +868,12 @@ begin
   TypeName := CurTokenString;
   TypeName := CurTokenString;
   ExpectToken(tkEqual);
   ExpectToken(tkEqual);
   NextToken;
   NextToken;
-  HadPackedModifier := False;     { Assume not present }
+  HadPackedModifier := false;     { Assume not present }
   if CurToken = tkPacked then     { If PACKED modifier }
   if CurToken = tkPacked then     { If PACKED modifier }
      begin                        { Handle PACKED modifier for all situations }
      begin                        { Handle PACKED modifier for all situations }
      NextToken;                   { Move to next token for rest of parse }
      NextToken;                   { Move to next token for rest of parse }
      if CurToken in [tkArray, tkRecord, tkObject, tkClass] then  { If allowed }
      if CurToken in [tkArray, tkRecord, tkObject, tkClass] then  { If allowed }
-       HadPackedModifier := True  { rememeber for later }
+       HadPackedModifier := true  { rememeber for later }
      else                         { otherwise, syntax error }
      else                         { otherwise, syntax error }
        ParseExc(Format(SParserExpectTokenError,['ARRAY, RECORD, OBJECT or CLASS']))
        ParseExc(Format(SParserExpectTokenError,['ARRAY, RECORD, OBJECT or CLASS']))
      end;
      end;
@@ -1003,7 +997,7 @@ begin
       begin
       begin
         Result := TPasEnumType(CreateElement(TPasEnumType, TypeName, Parent));
         Result := TPasEnumType(CreateElement(TPasEnumType, TypeName, Parent));
         try
         try
-          while True do
+          while true do
           begin
           begin
             NextToken;
             NextToken;
             EnumValue := TPasEnumValue(CreateElement(TPasEnumValue,
             EnumValue := TPasEnumValue(CreateElement(TPasEnumValue,
@@ -1035,8 +1029,8 @@ begin
         Result := TPasProcedureType(CreateElement(TPasProcedureType, TypeName,
         Result := TPasProcedureType(CreateElement(TPasProcedureType, TypeName,
           Parent));
           Parent));
         try
         try
-          ParseProcedureOrFunctionHeader(Result,
-            TPasProcedureType(Result), False, True);
+          ParseProcedureOrFunctionHeader(Result,TPasProcedureType(Result),
+                                         pt_procedure, true);
         except
         except
           Result.Free;
           Result.Free;
           raise;
           raise;
@@ -1044,11 +1038,11 @@ begin
       end;
       end;
     tkFunction:
     tkFunction:
       begin
       begin
-        Result := Engine.CreateFunctionType(TypeName, Parent, False,
+        Result := Engine.CreateFunctionType(TypeName, Parent, false,
           Scanner.CurFilename, Scanner.CurRow);
           Scanner.CurFilename, Scanner.CurRow);
         try
         try
-          ParseProcedureOrFunctionHeader(Result,
-            TPasFunctionType(Result), True, True);
+          ParseProcedureOrFunctionHeader(Result, TPasFunctionType(Result),
+                                         pt_function, true);
         except
         except
           Result.Free;
           Result.Free;
           raise;
           raise;
@@ -1091,7 +1085,7 @@ var
 begin
 begin
   VarNames := TStringList.Create;
   VarNames := TStringList.Create;
   try
   try
-    while True do
+    while true do
     begin
     begin
       VarNames.Add(CurTokenString);
       VarNames.Add(CurTokenString);
       NextToken;
       NextToken;
@@ -1131,7 +1125,7 @@ var
   Value, S: String;
   Value, S: String;
   M: string;
   M: string;
 begin
 begin
-  while True do
+  while true do
   begin
   begin
     List.Add(CreateElement(TPasVariable, CurTokenString, Parent));
     List.Add(CreateElement(TPasVariable, CurTokenString, Parent));
     NextToken;
     NextToken;
@@ -1168,7 +1162,7 @@ begin
 
 
   ExpectToken(tkSemicolon);
   ExpectToken(tkSemicolon);
   M := '';
   M := '';
-  while True do
+  while true do
   begin
   begin
     NextToken;
     NextToken;
     if CurToken = tkIdentifier then
     if CurToken = tkIdentifier then
@@ -1235,13 +1229,13 @@ var
   Access: TArgumentAccess;
   Access: TArgumentAccess;
   ArgType: TPasType;
   ArgType: TPasType;
 begin
 begin
-  while True do
+  while true do
   begin
   begin
     ArgNames := TStringList.Create;
     ArgNames := TStringList.Create;
     Access := argDefault;
     Access := argDefault;
-    IsUntyped := False;
+    IsUntyped := false;
     ArgType := nil;
     ArgType := nil;
-    while True do
+    while true do
     begin
     begin
       NextToken;
       NextToken;
       if CurToken = tkConst then
       if CurToken = tkConst then
@@ -1269,7 +1263,7 @@ begin
       begin
       begin
         // found an untyped const or var argument
         // found an untyped const or var argument
         UngetToken;
         UngetToken;
-        IsUntyped := True;
+        IsUntyped := true;
         break
         break
       end
       end
       else if CurToken <> tkComma then
       else if CurToken <> tkComma then
@@ -1308,37 +1302,53 @@ end;
 // Next token is expected to be a "(", ";" or for a function ":". The caller
 // Next token is expected to be a "(", ";" or for a function ":". The caller
 // will get the token after the final ";" as next token.
 // will get the token after the final ";" as next token.
 procedure TPasParser.ParseProcedureOrFunctionHeader(Parent: TPasElement;
 procedure TPasParser.ParseProcedureOrFunctionHeader(Parent: TPasElement;
-  Element: TPasProcedureType; IsFunction, OfObjectPossible: Boolean);
+  Element: TPasProcedureType; proctype:Tproctype; OfObjectPossible: Boolean);
 begin
 begin
   NextToken;
   NextToken;
-  if IsFunction then
-  begin
-    if CurToken = tkBraceOpen then
-    begin
-      ParseArgList(Parent, Element.Args, tkBraceClose);
-      ExpectToken(tkColon);
-    end else if CurToken <> tkColon then
-      ParseExc(SParserExpectedLBracketColon);
-    if Assigned(Element) then        // !!!
-      TPasFunctionType(Element).ResultEl.ResultType := ParseType(Parent)
-    else
-      ParseType(nil);
-  end else
-  begin
-    if CurToken = tkBraceOpen then
-    begin
-      ParseArgList(Element, Element.Args, tkBraceClose);
-    end else if (CurToken = tkSemicolon) or (OfObjectPossible and (CurToken = tkOf)) then
-      UngetToken
-    else
-      ParseExc(SParserExpectedLBracketSemicolon);
+  case proctype of
+    pt_function:
+      begin
+        if CurToken = tkBraceOpen then
+        begin
+          ParseArgList(Parent, Element.Args, tkBraceClose);
+          ExpectToken(tkColon);
+        end else if CurToken <> tkColon then
+          ParseExc(SParserExpectedLBracketColon);
+        if Assigned(Element) then        // !!!
+          TPasFunctionType(Element).ResultEl.ResultType := ParseType(Parent)
+        else
+          ParseType(nil);
+      end;
+    pt_procedure:
+      begin
+        if CurToken = tkBraceOpen then
+        begin
+          ParseArgList(Element, Element.Args, tkBraceClose);
+        end else if (CurToken = tkSemicolon) or (OfObjectPossible and (CurToken = tkOf)) then
+          UngetToken
+        else
+          ParseExc(SParserExpectedLBracketSemicolon);
+      end;
+    pt_operator:
+      begin
+        if CurToken = tkBraceOpen then
+        begin
+          ParseArgList(Parent, Element.Args, tkBraceClose);
+          ExpectToken(tkColon);
+        end else if CurToken <> tkColon then
+          ParseExc(SParserExpectedLBracketColon);
+        if Assigned(Element) then        // !!!
+          TPasFunctionType(Element).ResultEl.ResultType := ParseType(Parent)
+        else
+          ParseType(nil);
+      end;
   end;
   end;
 
 
   NextToken;
   NextToken;
   if OfObjectPossible and (CurToken = tkOf) then
   if OfObjectPossible and (CurToken = tkOf) then
   begin
   begin
     ExpectToken(tkObject);
     ExpectToken(tkObject);
-    Element.IsOfObject := True;
+    Element.IsOfObject := true;
   end else
   end else
     UngetToken;
     UngetToken;
 
 
@@ -1352,7 +1362,7 @@ begin
 
 
   ExpectToken(tkSemicolon);
   ExpectToken(tkSemicolon);
 
 
-  while True do
+  while true do
   begin
   begin
     NextToken;
     NextToken;
     if (CurToken = tkIdentifier) and (UpperCase(CurTokenString) = 'CDECL') then
     if (CurToken = tkIdentifier) and (UpperCase(CurTokenString) = 'CDECL') then
@@ -1375,7 +1385,7 @@ begin
     end else if Parent.InheritsFrom(TPasProcedure) and
     end else if Parent.InheritsFrom(TPasProcedure) and
       (CurToken = tkIdentifier) and (UpperCase(CurTokenString) = 'OVERLOAD') then
       (CurToken = tkIdentifier) and (UpperCase(CurTokenString) = 'OVERLOAD') then
     begin
     begin
-      TPasProcedure(Parent).IsOverload := True;
+      TPasProcedure(Parent).IsOverload := true;
       ExpectToken(tkSemicolon);
       ExpectToken(tkSemicolon);
     end else
     end else
     begin
     begin
@@ -1392,7 +1402,7 @@ procedure TPasParser.ParseProperty(Element:TPasElement);
   begin
   begin
     ExpectIdentifier;
     ExpectIdentifier;
     Result := CurTokenString;
     Result := CurTokenString;
-    while True do
+    while true do
     begin
     begin
       NextToken;
       NextToken;
       if CurToken = tkDot then
       if CurToken = tkDot then
@@ -1454,9 +1464,9 @@ begin
   begin
   begin
           NextToken;
           NextToken;
           if CurToken = tkTrue then
           if CurToken = tkTrue then
-          TPasProperty(Element).StoredAccessorName := 'True'
+          TPasProperty(Element).StoredAccessorName := 'true'
           else if CurToken = tkFalse then
           else if CurToken = tkFalse then
-          TPasProperty(Element).StoredAccessorName := 'False'
+          TPasProperty(Element).StoredAccessorName := 'false'
           else if CurToken = tkIdentifier then
           else if CurToken = tkIdentifier then
           TPasProperty(Element).StoredAccessorName := CurTokenString
           TPasProperty(Element).StoredAccessorName := CurTokenString
           else
           else
@@ -1493,8 +1503,8 @@ begin
   NextToken;
   NextToken;
   if CurToken = tkSemicolon then
   if CurToken = tkSemicolon then
   begin
   begin
-          TPasProperty(Element).IsDefault := True;
-          UngetToken;
+  TPasProperty(Element).IsDefault := true;
+  UngetToken;
   end else
   end else
   begin
   begin
           UngetToken;
           UngetToken;
@@ -1507,24 +1517,33 @@ end;
 
 
 // Starts after the "procedure" or "function" token
 // Starts after the "procedure" or "function" token
 function TPasParser.ParseProcedureOrFunctionDecl(Parent: TPasElement;
 function TPasParser.ParseProcedureOrFunctionDecl(Parent: TPasElement;
-  IsFunction: Boolean): TPasProcedure;
+  proctype: Tproctype): TPasProcedure;
 var
 var
   Name: String;
   Name: String;
 begin
 begin
   Name := ExpectIdentifier;
   Name := ExpectIdentifier;
-  if IsFunction then
-  begin
-    Result := TPasFunction(CreateElement(TPasFunction, Name, Parent));
-    Result.ProcType := Engine.CreateFunctionType('', Result, True,
-      Scanner.CurFilename, Scanner.CurRow);
-  end else
-  begin
-    Result := TPasProcedure(CreateElement(TPasProcedure, Name, Parent));
-    Result.ProcType := TPasProcedureType(CreateElement(TPasProcedureType, '',
-      Result));
+  case proctype of
+    pt_function:
+      begin
+        Result := TPasFunction(CreateElement(TPasFunction, Name, Parent));
+        Result.ProcType := Engine.CreateFunctionType('', Result, true,
+           Scanner.CurFilename, Scanner.CurRow);
+      end;
+    pt_procedure:
+      begin
+        Result := TPasProcedure(CreateElement(TPasProcedure, Name, Parent));
+        Result.ProcType := TPasProcedureType(CreateElement(TPasProcedureType, '',
+           Result));
+      end;
+    pt_operator:
+      begin
+        Result := TPasOperator(CreateElement(TPasOperator, Name, Parent));
+        Result.ProcType := Engine.CreateFunctionType('', Result, true,
+           Scanner.CurFilename, Scanner.CurRow);
+      end;
   end;
   end;
 
 
-  ParseProcedureOrFunctionHeader(Result, Result.ProcType, IsFunction, False);
+  ParseProcedureOrFunctionHeader(Result, Result.ProcType, proctype, false);
 end;
 end;
 
 
 // Starts after the "record" token
 // Starts after the "record" token
@@ -1535,7 +1554,7 @@ Var
   CCount : Integer;
   CCount : Integer;
 
 
 begin
 begin
-  while True do
+  while true do
   begin
   begin
     if CurToken = tkEnd then
     if CurToken = tkEnd then
       break;
       break;
@@ -1565,6 +1584,7 @@ function TPasParser.ParseClassDecl(Parent: TPasElement;
   const AClassName: String; AObjKind: TPasObjKind): TPasType;
   const AClassName: String; AObjKind: TPasObjKind): TPasType;
 var
 var
   CurVisibility: TPasMemberVisibility;
   CurVisibility: TPasMemberVisibility;
+  pt: Tproctype;
 
 
   procedure ProcessMethod(const MethodTypeName: String; HasReturnValue: Boolean);
   procedure ProcessMethod(const MethodTypeName: String; HasReturnValue: Boolean);
   var
   var
@@ -1578,7 +1598,7 @@ var
     begin
     begin
       Proc := TPasFunction(CreateElement(TPasFunction, CurTokenString, Owner,
       Proc := TPasFunction(CreateElement(TPasFunction, CurTokenString, Owner,
         CurVisibility));
         CurVisibility));
-      Proc.ProcType := Engine.CreateFunctionType( '', Proc, True,
+      Proc.ProcType := Engine.CreateFunctionType( '', Proc, true,
         Scanner.CurFilename, Scanner.CurRow);
         Scanner.CurFilename, Scanner.CurRow);
     end else
     end else
     begin
     begin
@@ -1600,27 +1620,32 @@ var
     else
     else
       TPasClassType(Result).Members.Add(Proc);
       TPasClassType(Result).Members.Add(Proc);
 
 
-    ParseProcedureOrFunctionHeader(Proc, Proc.ProcType, HasReturnValue, False);
+    if hasreturnvalue then
+      pt:=pt_function
+    else
+      pt:=pt_procedure;
+
+    ParseProcedureOrFunctionHeader(Proc, Proc.ProcType, pt, false);
 
 
-    while True do
+    while true do
     begin
     begin
       NextToken;
       NextToken;
       if CurToken = tkIdentifier then
       if CurToken = tkIdentifier then
       begin
       begin
         s := UpperCase(CurTokenString);
         s := UpperCase(CurTokenString);
         if s = 'VIRTUAL' then
         if s = 'VIRTUAL' then
-          Proc.IsVirtual := True
+          Proc.IsVirtual := true
         else if s = 'DYNAMIC' then
         else if s = 'DYNAMIC' then
-          Proc.IsDynamic := True
+          Proc.IsDynamic := true
         else if s = 'ABSTRACT' then
         else if s = 'ABSTRACT' then
-          Proc.IsAbstract := True
+          Proc.IsAbstract := true
         else if s = 'OVERRIDE' then
         else if s = 'OVERRIDE' then
-          Proc.IsOverride := True
+          Proc.IsOverride := true
         else if s = 'OVERLOAD' then
         else if s = 'OVERLOAD' then
-          Proc.IsOverload := True
+          Proc.IsOverload := true
         else if s = 'MESSAGE' then
         else if s = 'MESSAGE' then
         begin
         begin
-          Proc.IsMessage := True;
+          Proc.IsMessage := true;
           repeat
           repeat
             NextToken;
             NextToken;
           until CurToken = tkSemicolon;
           until CurToken = tkSemicolon;
@@ -1677,7 +1702,7 @@ begin
     if CurToken = tkBraceOpen then
     if CurToken = tkBraceOpen then
     begin
     begin
       TPasClassType(Result).AncestorType := ParseType(nil);
       TPasClassType(Result).AncestorType := ParseType(nil);
-      while True do
+      while true do
       begin
       begin
         NextToken;
         NextToken;
         if CurToken = tkBraceClose then
         if CurToken = tkBraceClose then
@@ -1726,13 +1751,13 @@ begin
               end;
               end;
             end;
             end;
           tkProcedure:
           tkProcedure:
-            ProcessMethod('procedure', False);
+            ProcessMethod('procedure', false);
           tkFunction:
           tkFunction:
-            ProcessMethod('function', True);
+            ProcessMethod('function', true);
           tkConstructor:
           tkConstructor:
-            ProcessMethod('constructor', False);
+            ProcessMethod('constructor', false);
           tkDestructor:
           tkDestructor:
-            ProcessMethod('destructor', False);
+            ProcessMethod('destructor', false);
           tkProperty:
           tkProperty:
             begin
             begin
               ExpectIdentifier;
               ExpectIdentifier;

+ 47 - 47
fcl/passrc/pscanner.pp

@@ -23,7 +23,7 @@ uses SysUtils, Classes;
 
 
 resourcestring
 resourcestring
   SErrInvalidCharacter = 'Invalid character ''%s''';
   SErrInvalidCharacter = 'Invalid character ''%s''';
-  SErrOpenString = 'String exceeds end of line';
+  SErrOpenString = 'string exceeds end of line';
   SErrIncludeFileNotFound = 'Could not find include file ''%s''';
   SErrIncludeFileNotFound = 'Could not find include file ''%s''';
   SErrIfXXXNestingLimitReached = 'Nesting of $IFxxx too deep';
   SErrIfXXXNestingLimitReached = 'Nesting of $IFxxx too deep';
   SErrInvalidPPElse = '$ELSE without matching $IFxxx';
   SErrInvalidPPElse = '$ELSE without matching $IFxxx';
@@ -133,7 +133,7 @@ type
   TLineReader = class
   TLineReader = class
   public
   public
     function IsEOF: Boolean; virtual; abstract;
     function IsEOF: Boolean; virtual; abstract;
-    function ReadLine: String; virtual; abstract;
+    function ReadLine: string; virtual; abstract;
   end;
   end;
 
 
   TFileLineReader = class(TLineReader)
   TFileLineReader = class(TLineReader)
@@ -141,10 +141,10 @@ type
     FTextFile: Text;
     FTextFile: Text;
     FileOpened: Boolean;
     FileOpened: Boolean;
   public
   public
-    constructor Create(const AFilename: String);
+    constructor Create(const AFilename: string);
     destructor Destroy; override;
     destructor Destroy; override;
     function IsEOF: Boolean; override;
     function IsEOF: Boolean; override;
-    function ReadLine: String; override;
+    function ReadLine: string; override;
   end;
   end;
 
 
   TFileResolver = class
   TFileResolver = class
@@ -153,9 +153,9 @@ type
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure AddIncludePath(const APath: String);
-    function FindSourceFile(const AName: String): TLineReader;
-    function FindIncludeFile(const AName: String): TLineReader;
+    procedure AddIncludePath(const APath: string);
+    function FindSourceFile(const AName: string): TLineReader;
+    function FindIncludeFile(const AName: string): TLineReader;
   end;
   end;
 
 
   EScannerError       = class(Exception);
   EScannerError       = class(Exception);
@@ -168,11 +168,11 @@ type
   private
   private
     FFileResolver: TFileResolver;
     FFileResolver: TFileResolver;
     FCurSourceFile: TLineReader;
     FCurSourceFile: TLineReader;
-    FCurFilename: String;
+    FCurFilename: string;
     FCurRow: Integer;
     FCurRow: Integer;
     FCurToken: TToken;
     FCurToken: TToken;
-    FCurTokenString: String;
-    FCurLine: String;
+    FCurTokenString: string;
+    FCurLine: string;
     FDefines: TStrings;
     FDefines: TStrings;
     TokenStr: PChar;
     TokenStr: PChar;
     FIncludeStack: TList;
     FIncludeStack: TList;
@@ -186,36 +186,36 @@ type
 
 
     function GetCurColumn: Integer;
     function GetCurColumn: Integer;
   protected
   protected
-    procedure Error(const Msg: String);
-    procedure Error(const Msg: String; Args: array of Const);
+    procedure Error(const Msg: string);
+    procedure Error(const Msg: string; Args: array of Const);
     function DoFetchToken: TToken;
     function DoFetchToken: TToken;
   public
   public
     constructor Create(AFileResolver: TFileResolver);
     constructor Create(AFileResolver: TFileResolver);
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure OpenFile(const AFilename: String);
+    procedure OpenFile(const AFilename: string);
     function FetchToken: TToken;
     function FetchToken: TToken;
 
 
     property FileResolver: TFileResolver read FFileResolver;
     property FileResolver: TFileResolver read FFileResolver;
     property CurSourceFile: TLineReader read FCurSourceFile;
     property CurSourceFile: TLineReader read FCurSourceFile;
-    property CurFilename: String read FCurFilename;
+    property CurFilename: string read FCurFilename;
 
 
-    property CurLine: String read FCurLine;
+    property CurLine: string read FCurLine;
     property CurRow: Integer read FCurRow;
     property CurRow: Integer read FCurRow;
     property CurColumn: Integer read GetCurColumn;
     property CurColumn: Integer read GetCurColumn;
 
 
     property CurToken: TToken read FCurToken;
     property CurToken: TToken read FCurToken;
-    property CurTokenString: String read FCurTokenString;
+    property CurTokenString: string read FCurTokenString;
 
 
     property Defines: TStrings read FDefines;
     property Defines: TStrings read FDefines;
   end;
   end;
 
 
 const
 const
-  TokenInfos: array[TToken] of String = (
+  TokenInfos: array[TToken] of string = (
     'EOF',
     'EOF',
     'Whitespace',
     'Whitespace',
     'Comment',
     'Comment',
     'Identifier',
     'Identifier',
-    'String',
+    'string',
     'Number',
     'Number',
     'Character',
     'Character',
     '(',
     '(',
@@ -314,21 +314,21 @@ implementation
 type
 type
   TIncludeStackItem = class
   TIncludeStackItem = class
     SourceFile: TLineReader;
     SourceFile: TLineReader;
-    Filename: String;
+    Filename: string;
     Token: TToken;
     Token: TToken;
-    TokenString: String;
-    Line: String;
+    TokenString: string;
+    Line: string;
     Row: Integer;
     Row: Integer;
     TokenStr: PChar;
     TokenStr: PChar;
   end;
   end;
 
 
 
 
-constructor TFileLineReader.Create(const AFilename: String);
+constructor TFileLineReader.Create(const AFilename: string);
 begin
 begin
   inherited Create;
   inherited Create;
   Assign(FTextFile, AFilename);
   Assign(FTextFile, AFilename);
   Reset(FTextFile);
   Reset(FTextFile);
-  FileOpened := True;
+  FileOpened := true;
 end;
 end;
 
 
 destructor TFileLineReader.Destroy;
 destructor TFileLineReader.Destroy;
@@ -343,7 +343,7 @@ begin
   Result := EOF(FTextFile);
   Result := EOF(FTextFile);
 end;
 end;
 
 
-function TFileLineReader.ReadLine: String;
+function TFileLineReader.ReadLine: string;
 begin
 begin
   ReadLn(FTextFile, Result);
   ReadLn(FTextFile, Result);
 end;
 end;
@@ -361,12 +361,12 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TFileResolver.AddIncludePath(const APath: String);
+procedure TFileResolver.AddIncludePath(const APath: string);
 begin
 begin
   FIncludePaths.Add(IncludeTrailingPathDelimiter(ExpandFileName(APath)));
   FIncludePaths.Add(IncludeTrailingPathDelimiter(ExpandFileName(APath)));
 end;
 end;
 
 
-function TFileResolver.FindSourceFile(const AName: String): TLineReader;
+function TFileResolver.FindSourceFile(const AName: string): TLineReader;
 begin
 begin
   if not FileExists(AName) then
   if not FileExists(AName) then
     Raise EFileNotFoundError.create(Aname)
     Raise EFileNotFoundError.create(Aname)
@@ -378,10 +378,10 @@ begin
     end;
     end;
 end;
 end;
 
 
-function TFileResolver.FindIncludeFile(const AName: String): TLineReader;
+function TFileResolver.FindIncludeFile(const AName: string): TLineReader;
 var
 var
   i: Integer;
   i: Integer;
-  FN : String;
+  FN : string;
 
 
 begin
 begin
   Result := nil;
   Result := nil;
@@ -428,7 +428,7 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPascalScanner.OpenFile(const AFilename: String);
+procedure TPascalScanner.OpenFile(const AFilename: string);
 begin
 begin
   FCurSourceFile := FileResolver.FindSourceFile(AFilename);
   FCurSourceFile := FileResolver.FindSourceFile(AFilename);
   FCurFilename := AFilename;
   FCurFilename := AFilename;
@@ -438,7 +438,7 @@ function TPascalScanner.FetchToken: TToken;
 var
 var
   IncludeStackItem: TIncludeStackItem;
   IncludeStackItem: TIncludeStackItem;
 begin
 begin
-  while True do
+  while true do
   begin
   begin
     Result := DoFetchToken;
     Result := DoFetchToken;
     if FCurToken = tkEOF then
     if FCurToken = tkEOF then
@@ -465,12 +465,12 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TPascalScanner.Error(const Msg: String);
+procedure TPascalScanner.Error(const Msg: string);
 begin
 begin
   raise EScannerError.Create(Msg);
   raise EScannerError.Create(Msg);
 end;
 end;
 
 
-procedure TPascalScanner.Error(const Msg: String; Args: array of Const);
+procedure TPascalScanner.Error(const Msg: string; Args: array of Const);
 begin
 begin
   raise EScannerError.CreateFmt(Msg, Args);
   raise EScannerError.CreateFmt(Msg, Args);
 end;
 end;
@@ -483,12 +483,12 @@ function TPascalScanner.DoFetchToken: TToken;
     begin
     begin
       FCurLine := '';
       FCurLine := '';
       TokenStr := nil;
       TokenStr := nil;
-      Result := False;
+      Result := false;
     end else
     end else
     begin
     begin
       FCurLine := CurSourceFile.ReadLine;
       FCurLine := CurSourceFile.ReadLine;
       TokenStr := PChar(CurLine);
       TokenStr := PChar(CurLine);
-      Result := True;
+      Result := true;
       Inc(FCurRow);
       Inc(FCurRow);
     end;
     end;
   end;
   end;
@@ -497,7 +497,7 @@ var
   TokenStart, CurPos: PChar;
   TokenStart, CurPos: PChar;
   i: TToken;
   i: TToken;
   OldLength, SectionLength, NestingLevel, Index: Integer;
   OldLength, SectionLength, NestingLevel, Index: Integer;
-  Directive, Param: String;
+  Directive, Param: string;
   IncludeStackItem: TIncludeStackItem;
   IncludeStackItem: TIncludeStackItem;
 begin
 begin
   if TokenStr = nil then
   if TokenStr = nil then
@@ -581,7 +581,7 @@ begin
         OldLength := 0;
         OldLength := 0;
         FCurTokenString := '';
         FCurTokenString := '';
 
 
-        while True do
+        while true do
         begin
         begin
           if TokenStr[0] = '''' then
           if TokenStr[0] = '''' then
             if TokenStr[1] = '''' then
             if TokenStr[1] = '''' then
@@ -692,7 +692,7 @@ begin
     '0'..'9':
     '0'..'9':
       begin
       begin
         TokenStart := TokenStr;
         TokenStart := TokenStr;
-        while True do
+        while true do
         begin
         begin
           Inc(TokenStr);
           Inc(TokenStr);
           case TokenStr[0] of
           case TokenStr[0] of
@@ -894,7 +894,7 @@ begin
               if PPIsSkipping then
               if PPIsSkipping then
               begin
               begin
                 PPSkipMode := ppSkipAll;
                 PPSkipMode := ppSkipAll;
-                PPIsSkipping := True;
+                PPIsSkipping := true;
               end else
               end else
               begin
               begin
                 Param := UpperCase(Param);
                 Param := UpperCase(Param);
@@ -902,7 +902,7 @@ begin
                 if Index < 0 then
                 if Index < 0 then
                 begin
                 begin
                   PPSkipMode := ppSkipIfBranch;
                   PPSkipMode := ppSkipIfBranch;
-                  PPIsSkipping := True;
+                  PPIsSkipping := true;
                 end else
                 end else
                   PPSkipMode := ppSkipElseBranch;
                   PPSkipMode := ppSkipElseBranch;
               end;
               end;
@@ -916,7 +916,7 @@ begin
               if PPIsSkipping then
               if PPIsSkipping then
               begin
               begin
                 PPSkipMode := ppSkipAll;
                 PPSkipMode := ppSkipAll;
-                PPIsSkipping := True;
+                PPIsSkipping := true;
               end else
               end else
               begin
               begin
                 Param := UpperCase(Param);
                 Param := UpperCase(Param);
@@ -924,7 +924,7 @@ begin
                 if Index >= 0 then
                 if Index >= 0 then
                 begin
                 begin
                   PPSkipMode := ppSkipIfBranch;
                   PPSkipMode := ppSkipIfBranch;
-                  PPIsSkipping := True;
+                  PPIsSkipping := true;
                 end else
                 end else
                   PPSkipMode := ppSkipElseBranch;
                   PPSkipMode := ppSkipElseBranch;
               end;
               end;
@@ -938,13 +938,13 @@ begin
               if PPIsSkipping then
               if PPIsSkipping then
               begin
               begin
                 PPSkipMode := ppSkipAll;
                 PPSkipMode := ppSkipAll;
-                PPIsSkipping := True;
+                PPIsSkipping := true;
               end else
               end else
               begin
               begin
                 { !!!: Currently, options are not supported, so they are just
                 { !!!: Currently, options are not supported, so they are just
                   assumed as not being set. }
                   assumed as not being set. }
                 PPSkipMode := ppSkipIfBranch;
                 PPSkipMode := ppSkipIfBranch;
-                PPIsSkipping := True;
+                PPIsSkipping := true;
               end;
               end;
             end else if Directive = 'IF' then
             end else if Directive = 'IF' then
             begin
             begin
@@ -956,22 +956,22 @@ begin
               if PPIsSkipping then
               if PPIsSkipping then
               begin
               begin
                 PPSkipMode := ppSkipAll;
                 PPSkipMode := ppSkipAll;
-                PPIsSkipping := True;
+                PPIsSkipping := true;
               end else
               end else
               begin
               begin
                 { !!!: Currently, expressions are not supported, so they are
                 { !!!: Currently, expressions are not supported, so they are
                   just assumed as evaluating to false. }
                   just assumed as evaluating to false. }
                 PPSkipMode := ppSkipIfBranch;
                 PPSkipMode := ppSkipIfBranch;
-                PPIsSkipping := True;
+                PPIsSkipping := true;
               end;
               end;
             end else if Directive = 'ELSE' then
             end else if Directive = 'ELSE' then
             begin
             begin
               if PPSkipStackIndex = 0 then
               if PPSkipStackIndex = 0 then
                 Error(SErrInvalidPPElse);
                 Error(SErrInvalidPPElse);
               if PPSkipMode = ppSkipIfBranch then
               if PPSkipMode = ppSkipIfBranch then
-                PPIsSkipping := False
+                PPIsSkipping := false
               else if PPSkipMode = ppSkipElseBranch then
               else if PPSkipMode = ppSkipElseBranch then
-                PPIsSkipping := True;
+                PPIsSkipping := true;
             end else if Directive = 'ENDIF' then
             end else if Directive = 'ENDIF' then
             begin
             begin
               if PPSkipStackIndex = 0 then
               if PPSkipStackIndex = 0 then