|
@@ -47,36 +47,36 @@ type
|
|
protected
|
|
protected
|
|
FPackage: TPasPackage;
|
|
FPackage: TPasPackage;
|
|
public
|
|
public
|
|
- function CreateElement(AClass: TPTreeElement; const AName: String;
|
|
|
|
- AParent: TPasElement; const ASourceFilename: String;
|
|
|
|
|
|
+ function CreateElement(AClass: TPTreeElement; const AName: string;
|
|
|
|
+ AParent: TPasElement; const ASourceFilename: string;
|
|
ASourceLinenumber: Integer): TPasElement;
|
|
ASourceLinenumber: Integer): TPasElement;
|
|
- function CreateElement(AClass: TPTreeElement; const AName: String;
|
|
|
|
|
|
+ function CreateElement(AClass: TPTreeElement; const AName: string;
|
|
AParent: TPasElement; AVisibility: TPasMemberVisibility;
|
|
AParent: TPasElement; AVisibility: TPasMemberVisibility;
|
|
- const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
|
|
|
|
|
|
+ const ASourceFilename: string; ASourceLinenumber: Integer): TPasElement;
|
|
virtual; abstract;
|
|
virtual; abstract;
|
|
- function CreateFunctionType(const AName: String; AParent: TPasElement;
|
|
|
|
- UseParentAsResultParent: Boolean; const ASourceFilename: String;
|
|
|
|
|
|
+ function CreateFunctionType(const AName,resultname: string; AParent: TPasElement;
|
|
|
|
+ UseParentAsResultParent: Boolean; const ASourceFilename: string;
|
|
ASourceLinenumber: Integer): TPasFunctionType;
|
|
ASourceLinenumber: Integer): TPasFunctionType;
|
|
- function FindElement(const AName: String): TPasElement; virtual; abstract;
|
|
|
|
- function FindModule(const AName: String): TPasModule; virtual;
|
|
|
|
|
|
+ function FindElement(const AName: string): TPasElement; virtual; abstract;
|
|
|
|
+ function FindModule(const AName: string): TPasModule; virtual;
|
|
property Package: TPasPackage read FPackage;
|
|
property Package: TPasPackage read FPackage;
|
|
end;
|
|
end;
|
|
|
|
|
|
EParserError = class(Exception)
|
|
EParserError = class(Exception)
|
|
private
|
|
private
|
|
- FFilename: String;
|
|
|
|
|
|
+ FFilename: string;
|
|
FRow, FColumn: Integer;
|
|
FRow, FColumn: Integer;
|
|
public
|
|
public
|
|
- constructor Create(const AReason, AFilename: String;
|
|
|
|
|
|
+ constructor Create(const AReason, AFilename: string;
|
|
ARow, AColumn: Integer);
|
|
ARow, AColumn: Integer);
|
|
- property Filename: String read FFilename;
|
|
|
|
|
|
+ property Filename: string read FFilename;
|
|
property Row: Integer read FRow;
|
|
property Row: Integer read FRow;
|
|
property Column: Integer read FColumn;
|
|
property Column: Integer read FColumn;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
function ParseSource(AEngine: TPasTreeContainer;
|
|
function ParseSource(AEngine: TPasTreeContainer;
|
|
- const FPCCommandLine, OSTarget, CPUTarget: String): TPasModule;
|
|
|
|
|
|
+ const FPCCommandLine, OSTarget, CPUTarget: string): TPasModule;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
implementation
|
|
@@ -87,42 +87,44 @@ 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;
|
|
FScanner: TPascalScanner;
|
|
FScanner: TPascalScanner;
|
|
FEngine: TPasTreeContainer;
|
|
FEngine: TPasTreeContainer;
|
|
FCurToken: TToken;
|
|
FCurToken: TToken;
|
|
- FCurTokenString: String;
|
|
|
|
|
|
+ FCurTokenString: string;
|
|
// UngetToken support:
|
|
// UngetToken support:
|
|
FTokenBuffer: array[0..1] of TToken;
|
|
FTokenBuffer: array[0..1] of TToken;
|
|
- FTokenStringBuffer: array[0..1] of String;
|
|
|
|
|
|
+ FTokenStringBuffer: array[0..1] of string;
|
|
FTokenBufferIndex, FTokenBufferSize: Integer;
|
|
FTokenBufferIndex, FTokenBufferSize: Integer;
|
|
|
|
|
|
- procedure ParseExc(const Msg: String);
|
|
|
|
|
|
+ procedure ParseExc(const Msg: string);
|
|
protected
|
|
protected
|
|
- function CreateElement(AClass: TPTreeElement; const AName: String;
|
|
|
|
|
|
+ function CreateElement(AClass: TPTreeElement; const AName: string;
|
|
AParent: TPasElement): TPasElement;
|
|
AParent: TPasElement): TPasElement;
|
|
- function CreateElement(AClass: TPTreeElement; const AName: String;
|
|
|
|
|
|
+ function CreateElement(AClass: TPTreeElement; const AName: string;
|
|
AParent: TPasElement; AVisibility: TPasMemberVisibility): TPasElement;
|
|
AParent: TPasElement; AVisibility: TPasMemberVisibility): TPasElement;
|
|
public
|
|
public
|
|
constructor Create(AScanner: TPascalScanner; AFileResolver: TFileResolver;
|
|
constructor Create(AScanner: TPascalScanner; AFileResolver: TFileResolver;
|
|
AEngine: TPasTreeContainer);
|
|
AEngine: TPasTreeContainer);
|
|
- function CurTokenName: String;
|
|
|
|
- function CurTokenText: String;
|
|
|
|
|
|
+ function CurTokenName: string;
|
|
|
|
+ function CurTokenText: string;
|
|
procedure NextToken;
|
|
procedure NextToken;
|
|
procedure UngetToken;
|
|
procedure UngetToken;
|
|
procedure ExpectToken(tk: TToken);
|
|
procedure ExpectToken(tk: TToken);
|
|
- function ExpectIdentifier: String;
|
|
|
|
|
|
+ function ExpectIdentifier: string;
|
|
|
|
|
|
- function ParseType(Parent: TPasElement; Prefix : String): TPasType;
|
|
|
|
|
|
+ function ParseType(Parent: TPasElement; Prefix : string): TPasType;
|
|
function ParseType(Parent: TPasElement): TPasType;
|
|
function ParseType(Parent: TPasElement): TPasType;
|
|
function ParseComplexType: TPasType;
|
|
function ParseComplexType: TPasType;
|
|
procedure ParseArrayType(Element: TPasArrayType);
|
|
procedure ParseArrayType(Element: TPasArrayType);
|
|
- function ParseExpression: String;
|
|
|
|
|
|
+ function ParseExpression: string;
|
|
procedure AddProcOrFunction(ASection: TPasSection; AProc: TPasProcedure);
|
|
procedure AddProcOrFunction(ASection: TPasSection; AProc: TPasProcedure);
|
|
function CheckIfOverloaded(AOwner: TPasClassType;
|
|
function CheckIfOverloaded(AOwner: TPasClassType;
|
|
- const AName: String): TPasElement;
|
|
|
|
|
|
+ const AName: string): TPasElement;
|
|
|
|
|
|
procedure ParseMain(var Module: TPasModule);
|
|
procedure ParseMain(var Module: TPasModule);
|
|
procedure ParseUnit(var Module: TPasModule);
|
|
procedure ParseUnit(var Module: TPasModule);
|
|
@@ -136,11 +138,11 @@ 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;
|
|
procedure ParseProperty(Element:TPasElement);
|
|
procedure ParseProperty(Element:TPasElement);
|
|
|
|
|
|
@@ -149,21 +151,21 @@ type
|
|
property Engine: TPasTreeContainer read FEngine;
|
|
property Engine: TPasTreeContainer read FEngine;
|
|
|
|
|
|
property CurToken: TToken read FCurToken;
|
|
property CurToken: TToken read FCurToken;
|
|
- property CurTokenString: String read FCurTokenString;
|
|
|
|
|
|
+ property CurTokenString: string read FCurTokenString;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TPasTreeContainer.CreateElement(AClass: TPTreeElement;
|
|
function TPasTreeContainer.CreateElement(AClass: TPTreeElement;
|
|
- const AName: String; AParent: TPasElement; const ASourceFilename: String;
|
|
|
|
|
|
+ const AName: string; AParent: TPasElement; const ASourceFilename: string;
|
|
ASourceLinenumber: Integer): TPasElement;
|
|
ASourceLinenumber: Integer): TPasElement;
|
|
begin
|
|
begin
|
|
Result := CreateElement(AClass, AName, AParent, visDefault, ASourceFilename,
|
|
Result := CreateElement(AClass, AName, AParent, visDefault, ASourceFilename,
|
|
ASourceLinenumber);
|
|
ASourceLinenumber);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasTreeContainer.CreateFunctionType(const AName: String;
|
|
|
|
|
|
+function TPasTreeContainer.CreateFunctionType(const AName,resultname: string;
|
|
AParent: TPasElement; UseParentAsResultParent: Boolean;
|
|
AParent: TPasElement; UseParentAsResultParent: Boolean;
|
|
- const ASourceFilename: String; ASourceLinenumber: Integer): TPasFunctionType;
|
|
|
|
|
|
+ const ASourceFilename: string; ASourceLinenumber: Integer): TPasFunctionType;
|
|
var
|
|
var
|
|
ResultParent: TPasElement;
|
|
ResultParent: TPasElement;
|
|
begin
|
|
begin
|
|
@@ -176,16 +178,16 @@ begin
|
|
ResultParent := Result;
|
|
ResultParent := Result;
|
|
|
|
|
|
TPasFunctionType(Result).ResultEl :=
|
|
TPasFunctionType(Result).ResultEl :=
|
|
- TPasResultElement(CreateElement(TPasResultElement, 'Result', ResultParent,
|
|
|
|
|
|
+ TPasResultElement(CreateElement(TPasResultElement, resultname, ResultParent,
|
|
ASourceFilename, ASourceLinenumber));
|
|
ASourceFilename, ASourceLinenumber));
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasTreeContainer.FindModule(const AName: String): TPasModule;
|
|
|
|
|
|
+function TPasTreeContainer.FindModule(const AName: string): TPasModule;
|
|
begin
|
|
begin
|
|
Result := nil;
|
|
Result := nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
-constructor EParserError.Create(const AReason, AFilename: String;
|
|
|
|
|
|
+constructor EParserError.Create(const AReason, AFilename: string;
|
|
ARow, AColumn: Integer);
|
|
ARow, AColumn: Integer);
|
|
begin
|
|
begin
|
|
inherited Create(AReason);
|
|
inherited Create(AReason);
|
|
@@ -194,7 +196,7 @@ begin
|
|
FColumn := AColumn;
|
|
FColumn := AColumn;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TPasParser.ParseExc(const Msg: String);
|
|
|
|
|
|
+procedure TPasParser.ParseExc(const Msg: string);
|
|
begin
|
|
begin
|
|
raise EParserError.Create(Format(SParserErrorAtToken, [Msg, CurTokenName]),
|
|
raise EParserError.Create(Format(SParserErrorAtToken, [Msg, CurTokenName]),
|
|
Scanner.CurFilename, Scanner.CurRow, Scanner.CurColumn);
|
|
Scanner.CurFilename, Scanner.CurRow, Scanner.CurColumn);
|
|
@@ -209,7 +211,7 @@ begin
|
|
FEngine := AEngine;
|
|
FEngine := AEngine;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.CurTokenName: String;
|
|
|
|
|
|
+function TPasParser.CurTokenName: string;
|
|
begin
|
|
begin
|
|
if CurToken = tkIdentifier then
|
|
if CurToken = tkIdentifier then
|
|
Result := 'Identifier ' + Scanner.CurTokenString
|
|
Result := 'Identifier ' + Scanner.CurTokenString
|
|
@@ -217,7 +219,7 @@ begin
|
|
Result := TokenInfos[CurToken];
|
|
Result := TokenInfos[CurToken];
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.CurTokenText: String;
|
|
|
|
|
|
+function TPasParser.CurTokenText: string;
|
|
begin
|
|
begin
|
|
case CurToken of
|
|
case CurToken of
|
|
tkIdentifier, tkString, tkNumber, tkChar:
|
|
tkIdentifier, tkString, tkNumber, tkChar:
|
|
@@ -281,7 +283,7 @@ begin
|
|
ParseExc(Format(SParserExpectTokenError, [TokenInfos[tk]]));
|
|
ParseExc(Format(SParserExpectTokenError, [TokenInfos[tk]]));
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.ExpectIdentifier: String;
|
|
|
|
|
|
+function TPasParser.ExpectIdentifier: string;
|
|
begin
|
|
begin
|
|
ExpectToken(tkIdentifier);
|
|
ExpectToken(tkIdentifier);
|
|
Result := CurTokenString;
|
|
Result := CurTokenString;
|
|
@@ -293,7 +295,7 @@ begin
|
|
Result:=ParseType(Parent,'');
|
|
Result:=ParseType(Parent,'');
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.ParseType(Parent: TPasElement; Prefix : String): TPasType;
|
|
|
|
|
|
+function TPasParser.ParseType(Parent: TPasElement; Prefix : string): TPasType;
|
|
|
|
|
|
procedure ParseRange;
|
|
procedure ParseRange;
|
|
begin
|
|
begin
|
|
@@ -309,7 +311,7 @@ function TPasParser.ParseType(Parent: TPasElement; Prefix : String): TPasType;
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
- Name, s: String;
|
|
|
|
|
|
+ Name, s: string;
|
|
EnumValue: TPasEnumValue;
|
|
EnumValue: TPasEnumValue;
|
|
Ref: TPasElement;
|
|
Ref: TPasElement;
|
|
begin
|
|
begin
|
|
@@ -339,7 +341,7 @@ begin
|
|
else if s = 'LONGWORD' then Name := 'LongWord'
|
|
else if s = 'LONGWORD' then Name := 'LongWord'
|
|
else if s = 'SHORTINT' then Name := 'ShortInt'
|
|
else if s = 'SHORTINT' then Name := 'ShortInt'
|
|
else if s = 'SMALLINT' then Name := 'SmallInt'
|
|
else if s = 'SMALLINT' then Name := 'SmallInt'
|
|
- else if s = 'STRING' then Name := 'String'
|
|
|
|
|
|
+ else if s = 'string' then Name := 'string'
|
|
else if s = 'WORD' then Name := 'Word'
|
|
else if s = 'WORD' then Name := 'Word'
|
|
else
|
|
else
|
|
Ref := Engine.FindElement(Name);
|
|
Ref := Engine.FindElement(Name);
|
|
@@ -353,7 +355,7 @@ begin
|
|
Result := TPasUnresolvedTypeRef(CreateElement(TPasUnresolvedTypeRef, Name, nil));
|
|
Result := TPasUnresolvedTypeRef(CreateElement(TPasUnresolvedTypeRef, Name, nil));
|
|
|
|
|
|
// !!!: Doesn't make sense for resolved types
|
|
// !!!: Doesn't make sense for resolved types
|
|
- if Name = 'String' then
|
|
|
|
|
|
+ if Name = 'string' then
|
|
begin
|
|
begin
|
|
NextToken;
|
|
NextToken;
|
|
if CurToken = tkSquaredBraceOpen then
|
|
if CurToken = tkSquaredBraceOpen then
|
|
@@ -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('','result', 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('','result', 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
|
|
@@ -477,7 +479,7 @@ end;
|
|
procedure TPasParser.ParseArrayType(Element: TPasArrayType);
|
|
procedure TPasParser.ParseArrayType(Element: TPasArrayType);
|
|
|
|
|
|
Var
|
|
Var
|
|
- S : String;
|
|
|
|
|
|
+ S : string;
|
|
|
|
|
|
begin
|
|
begin
|
|
NextToken;
|
|
NextToken;
|
|
@@ -510,16 +512,16 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.ParseExpression: String;
|
|
|
|
|
|
+function TPasParser.ParseExpression: string;
|
|
var
|
|
var
|
|
BracketLevel: Integer;
|
|
BracketLevel: Integer;
|
|
MayAppendSpace, AppendSpace, NextAppendSpace: Boolean;
|
|
MayAppendSpace, AppendSpace, NextAppendSpace: Boolean;
|
|
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
|
|
@@ -601,7 +603,7 @@ end;
|
|
|
|
|
|
// Returns the parent for an element which is to be created
|
|
// Returns the parent for an element which is to be created
|
|
function TPasParser.CheckIfOverloaded(AOwner: TPasClassType;
|
|
function TPasParser.CheckIfOverloaded(AOwner: TPasClassType;
|
|
- const AName: String): TPasElement;
|
|
|
|
|
|
+ const AName: string): TPasElement;
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
Member: TPasElement;
|
|
Member: TPasElement;
|
|
@@ -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:
|
|
@@ -788,10 +782,10 @@ end;
|
|
// Starts after the "uses" token
|
|
// Starts after the "uses" token
|
|
procedure TPasParser.ParseUsesList(ASection: TPasSection);
|
|
procedure TPasParser.ParseUsesList(ASection: TPasSection);
|
|
var
|
|
var
|
|
- UnitName: String;
|
|
|
|
|
|
+ UnitName: string;
|
|
Element: TPasElement;
|
|
Element: TPasElement;
|
|
begin
|
|
begin
|
|
- while True do
|
|
|
|
|
|
+ while true do
|
|
begin
|
|
begin
|
|
UnitName := ExpectIdentifier;
|
|
UnitName := ExpectIdentifier;
|
|
|
|
|
|
@@ -849,7 +843,7 @@ end;
|
|
// Starts after the type name
|
|
// Starts after the type name
|
|
function TPasParser.ParseTypeDecl(Parent: TPasElement): TPasType;
|
|
function TPasParser.ParseTypeDecl(Parent: TPasElement): TPasType;
|
|
var
|
|
var
|
|
- TypeName: String;
|
|
|
|
|
|
+ TypeName: string;
|
|
|
|
|
|
procedure ParseRange;
|
|
procedure ParseRange;
|
|
begin
|
|
begin
|
|
@@ -867,19 +861,19 @@ var
|
|
|
|
|
|
var
|
|
var
|
|
EnumValue: TPasEnumValue;
|
|
EnumValue: TPasEnumValue;
|
|
- Prefix : String;
|
|
|
|
|
|
+ Prefix : string;
|
|
HadPackedModifier : Boolean; // 12/04/04 - Dave - Added
|
|
HadPackedModifier : Boolean; // 12/04/04 - Dave - Added
|
|
|
|
|
|
begin
|
|
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;
|
|
@@ -968,7 +962,7 @@ begin
|
|
ParseRange;
|
|
ParseRange;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
-{ _STRING, _FILE:
|
|
|
|
|
|
+{ _string, _FILE:
|
|
begin
|
|
begin
|
|
Result := TPasAliasType(CreateElement(TPasAliasType, TypeName, Parent));
|
|
Result := TPasAliasType(CreateElement(TPasAliasType, TypeName, Parent));
|
|
UngetToken;
|
|
UngetToken;
|
|
@@ -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, 'result', 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;
|
|
@@ -1128,10 +1122,10 @@ procedure TPasParser.ParseVarDecl(Parent: TPasElement; List: TList);
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
VarType: TPasType;
|
|
VarType: TPasType;
|
|
- 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
|
|
@@ -1229,19 +1223,19 @@ procedure TPasParser.ParseArgList(Parent: TPasElement; Args: TList; EndToken: TT
|
|
var
|
|
var
|
|
ArgNames: TStringList;
|
|
ArgNames: TStringList;
|
|
IsUntyped: Boolean;
|
|
IsUntyped: Boolean;
|
|
- Name, Value: String;
|
|
|
|
|
|
+ Name, Value: string;
|
|
i: Integer;
|
|
i: Integer;
|
|
Arg: TPasArgument;
|
|
Arg: TPasArgument;
|
|
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,54 @@ 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
|
|
|
|
+ ParseArgList(Parent, Element.Args, tkBraceClose);
|
|
|
|
+
|
|
|
|
+ TPasFunctionType(Element).ResultEl.name := ExpectIdentifier;
|
|
|
|
+
|
|
|
|
+ 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 +1363,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 +1386,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
|
|
@@ -1388,11 +1399,11 @@ end;
|
|
|
|
|
|
procedure TPasParser.ParseProperty(Element:TPasElement);
|
|
procedure TPasParser.ParseProperty(Element:TPasElement);
|
|
|
|
|
|
- function GetAccessorName: String;
|
|
|
|
|
|
+ function GetAccessorName: string;
|
|
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 +1465,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 +1504,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 +1518,35 @@ 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;
|
|
|
|
- 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
|
|
|
|
+ Name := ExpectIdentifier;
|
|
|
|
+ Result := TPasFunction(CreateElement(TPasFunction, Name, Parent));
|
|
|
|
+ Result.ProcType := Engine.CreateFunctionType('', 'result', Result, true,
|
|
|
|
+ Scanner.CurFilename, Scanner.CurRow);
|
|
|
|
+ end;
|
|
|
|
+ pt_procedure:
|
|
|
|
+ begin
|
|
|
|
+ Name := ExpectIdentifier;
|
|
|
|
+ Result := TPasProcedure(CreateElement(TPasProcedure, Name, Parent));
|
|
|
|
+ Result.ProcType := TPasProcedureType(CreateElement(TPasProcedureType, '',
|
|
|
|
+ Result));
|
|
|
|
+ end;
|
|
|
|
+ pt_operator:
|
|
|
|
+ begin
|
|
|
|
+ name := tokeninfos[curtoken];
|
|
|
|
+ Result := TPasOperator(CreateElement(TPasOperator, Name, Parent));
|
|
|
|
+ Result.ProcType := Engine.CreateFunctionType('', '__INVALID__', 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 +1557,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;
|
|
@@ -1562,15 +1584,16 @@ end;
|
|
|
|
|
|
// Starts after the "class" token
|
|
// Starts after the "class" token
|
|
function TPasParser.ParseClassDecl(Parent: TPasElement;
|
|
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
|
|
Owner: TPasElement;
|
|
Owner: TPasElement;
|
|
Proc: TPasProcedure;
|
|
Proc: TPasProcedure;
|
|
- s: String;
|
|
|
|
|
|
+ s: string;
|
|
begin
|
|
begin
|
|
ExpectIdentifier;
|
|
ExpectIdentifier;
|
|
Owner := CheckIfOverloaded(TPasClassType(Result), CurTokenString);
|
|
Owner := CheckIfOverloaded(TPasClassType(Result), CurTokenString);
|
|
@@ -1578,7 +1601,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( '', 'result', Proc, true,
|
|
Scanner.CurFilename, Scanner.CurRow);
|
|
Scanner.CurFilename, Scanner.CurRow);
|
|
end else
|
|
end else
|
|
begin
|
|
begin
|
|
@@ -1600,27 +1623,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;
|
|
@@ -1644,7 +1672,7 @@ var
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
- s, SourceFilename: String;
|
|
|
|
|
|
+ s, SourceFilename: string;
|
|
i, SourceLinenumber: Integer;
|
|
i, SourceLinenumber: Integer;
|
|
VarList: TList;
|
|
VarList: TList;
|
|
Element: TPasElement;
|
|
Element: TPasElement;
|
|
@@ -1677,7 +1705,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 +1754,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;
|
|
@@ -1752,14 +1780,14 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.CreateElement(AClass: TPTreeElement; const AName: String;
|
|
|
|
|
|
+function TPasParser.CreateElement(AClass: TPTreeElement; const AName: string;
|
|
AParent: TPasElement): TPasElement;
|
|
AParent: TPasElement): TPasElement;
|
|
begin
|
|
begin
|
|
Result := Engine.CreateElement(AClass, AName, AParent,
|
|
Result := Engine.CreateElement(AClass, AName, AParent,
|
|
Scanner.CurFilename, Scanner.CurRow);
|
|
Scanner.CurFilename, Scanner.CurRow);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPasParser.CreateElement(AClass: TPTreeElement; const AName: String;
|
|
|
|
|
|
+function TPasParser.CreateElement(AClass: TPTreeElement; const AName: string;
|
|
AParent: TPasElement; AVisibility: TPasMemberVisibility): TPasElement;
|
|
AParent: TPasElement; AVisibility: TPasMemberVisibility): TPasElement;
|
|
begin
|
|
begin
|
|
Result := Engine.CreateElement(AClass, AName, AParent, AVisibility,
|
|
Result := Engine.CreateElement(AClass, AName, AParent, AVisibility,
|
|
@@ -1768,18 +1796,18 @@ end;
|
|
|
|
|
|
|
|
|
|
function ParseSource(AEngine: TPasTreeContainer;
|
|
function ParseSource(AEngine: TPasTreeContainer;
|
|
- const FPCCommandLine, OSTarget, CPUTarget: String): TPasModule;
|
|
|
|
|
|
+ const FPCCommandLine, OSTarget, CPUTarget: string): TPasModule;
|
|
var
|
|
var
|
|
FileResolver: TFileResolver;
|
|
FileResolver: TFileResolver;
|
|
Parser: TPasParser;
|
|
Parser: TPasParser;
|
|
Start, CurPos: PChar;
|
|
Start, CurPos: PChar;
|
|
- Filename: String;
|
|
|
|
|
|
+ Filename: string;
|
|
Scanner: TPascalScanner;
|
|
Scanner: TPascalScanner;
|
|
|
|
|
|
procedure ProcessCmdLinePart;
|
|
procedure ProcessCmdLinePart;
|
|
var
|
|
var
|
|
l: Integer;
|
|
l: Integer;
|
|
- s: String;
|
|
|
|
|
|
+ s: string;
|
|
begin
|
|
begin
|
|
l := CurPos - Start;
|
|
l := CurPos - Start;
|
|
SetLength(s, l);
|
|
SetLength(s, l);
|
|
@@ -1804,7 +1832,7 @@ var
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
- s: String;
|
|
|
|
|
|
+ s: string;
|
|
begin
|
|
begin
|
|
Result := nil;
|
|
Result := nil;
|
|
FileResolver := nil;
|
|
FileResolver := nil;
|