|
@@ -162,12 +162,15 @@ type
|
|
|
{$ENDIF}
|
|
|
constructor Create(const AName: string; AParent: TPasElement); virtual;
|
|
|
destructor Destroy; override;
|
|
|
+ Class Function IsKeyWord(Const S : String) : Boolean;
|
|
|
+ Class Function EscapeKeyWord(Const S : String) : String;
|
|
|
procedure AddRef{$IFDEF CheckPasTreeRefCount}(const aId: string){$ENDIF};
|
|
|
procedure Release{$IFDEF CheckPasTreeRefCount}(const aId: string){$ENDIF};
|
|
|
procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
|
|
|
const Arg: Pointer); virtual;
|
|
|
procedure ForEachChildCall(const aMethodCall: TOnForEachPasElement;
|
|
|
const Arg: Pointer; Child: TPasElement; CheckParent: boolean); virtual;
|
|
|
+ Function SafeName : String; // Name but with & prepended if name is a keyword.
|
|
|
function FullPath: string; // parent's names, until parent is not TPasDeclarations
|
|
|
function ParentPath: string; // parent's names
|
|
|
function FullName: string; virtual; // FullPath + Name
|
|
@@ -2551,7 +2554,7 @@ function TPasType.FixTypeDecl(aDecl: String): String;
|
|
|
begin
|
|
|
Result:=aDecl;
|
|
|
if (Name<>'') then
|
|
|
- Result:=Name+' = '+Result;
|
|
|
+ Result:=SafeName+' = '+Result;
|
|
|
ProcessHints(false,Result);
|
|
|
end;
|
|
|
|
|
@@ -2829,6 +2832,30 @@ begin
|
|
|
inherited Destroy;
|
|
|
end;
|
|
|
|
|
|
+class function TPasElement.IsKeyWord(const S: String): Boolean;
|
|
|
+
|
|
|
+Const
|
|
|
+ KW=';absolute;and;array;asm;begin;case;const;constructor;destructor;div;do;'+
|
|
|
+ 'downto;else;end;file;for;function;goto;if;implementation;in;inherited;'+
|
|
|
+ 'inline;interface;label;mod;nil;not;object;of;on;operator;or;packed;'+
|
|
|
+ 'procedure;program;record;reintroduce;repeat;self;set;shl;shr;string;then;'+
|
|
|
+ 'to;type;unit;until;uses;var;while;with;xor;dispose;exit;false;new;true;'+
|
|
|
+ 'as;class;dispinterface;except;exports;finalization;finally;initialization;'+
|
|
|
+ 'inline;is;library;on;out;packed;property;raise;resourcestring;threadvar;try;'+
|
|
|
+ 'private;published;length;setlength;';
|
|
|
+
|
|
|
+begin
|
|
|
+ Result:=Pos(';'+lowercase(S)+';',KW)<>0;
|
|
|
+end;
|
|
|
+
|
|
|
+class function TPasElement.EscapeKeyWord(const S: String): String;
|
|
|
+begin
|
|
|
+ Result:=S;
|
|
|
+ If IsKeyWord(Result) then
|
|
|
+ Result:='&'+Result
|
|
|
+
|
|
|
+end;
|
|
|
+
|
|
|
procedure TPasElement.AddRef{$IFDEF CheckPasTreeRefCount}(const aId: string){$ENDIF};
|
|
|
begin
|
|
|
{$ifdef EnablePasTreeGlobalRefCount}
|
|
@@ -2918,6 +2945,13 @@ begin
|
|
|
Child.ForEachCall(aMethodCall,Arg);
|
|
|
end;
|
|
|
|
|
|
+function TPasElement.SafeName: String;
|
|
|
+begin
|
|
|
+ Result:=Name;
|
|
|
+ if IsKeyWord(Result) then
|
|
|
+ Result:='&'+Result;
|
|
|
+end;
|
|
|
+
|
|
|
function TPasElement.FullPath: string;
|
|
|
|
|
|
var
|
|
@@ -2996,7 +3030,7 @@ function TPasElement.GetDeclaration(full: Boolean): string;
|
|
|
|
|
|
begin
|
|
|
if Full then
|
|
|
- Result := Name
|
|
|
+ Result := SafeName
|
|
|
else
|
|
|
Result := '';
|
|
|
end;
|
|
@@ -4016,7 +4050,7 @@ end;
|
|
|
|
|
|
function TPasModule.GetDeclaration(full : boolean): string;
|
|
|
begin
|
|
|
- Result := 'Unit ' + Name;
|
|
|
+ Result := 'Unit ' + SafeName;
|
|
|
if full then ;
|
|
|
end;
|
|
|
|
|
@@ -4043,7 +4077,7 @@ begin
|
|
|
Result:=Expr.GetDeclaration(true);
|
|
|
If Full Then
|
|
|
begin
|
|
|
- Result:=Name+' = '+Result;
|
|
|
+ Result:=SafeName+' = '+Result;
|
|
|
ProcessHints(False,Result);
|
|
|
end;
|
|
|
end;
|
|
@@ -4063,10 +4097,10 @@ end;
|
|
|
|
|
|
function TPasPointerType.GetDeclaration(full: Boolean): string;
|
|
|
begin
|
|
|
- Result:='^'+DestType.Name;
|
|
|
+ Result:='^'+DestType.SafeName;
|
|
|
If Full then
|
|
|
begin
|
|
|
- Result:=Name+' = '+Result;
|
|
|
+ Result:=SafeName+' = '+Result;
|
|
|
ProcessHints(False,Result);
|
|
|
end;
|
|
|
end;
|
|
@@ -4086,7 +4120,7 @@ end;
|
|
|
|
|
|
function TPasAliasType.GetDeclaration(full: Boolean): string;
|
|
|
begin
|
|
|
- Result:=DestType.Name;
|
|
|
+ Result:=DestType.SafeName;
|
|
|
If Full then
|
|
|
Result:=FixTypeDecl(Result);
|
|
|
end;
|
|
@@ -4107,7 +4141,7 @@ end;
|
|
|
|
|
|
function TPasClassOfType.GetDeclaration (full : boolean) : string;
|
|
|
begin
|
|
|
- Result:='Class of '+DestType.Name;
|
|
|
+ Result:='Class of '+DestType.SafeName;
|
|
|
If Full then
|
|
|
Result:=FixTypeDecl(Result);
|
|
|
end;
|
|
@@ -4158,7 +4192,7 @@ begin
|
|
|
If IsPacked then
|
|
|
Result := 'packed '+Result; // 12/04/04 Dave - Added
|
|
|
If Assigned(Eltype) then
|
|
|
- Result:=Result+ElType.Name
|
|
|
+ Result:=Result+ElType.SafeName
|
|
|
else
|
|
|
Result:=Result+'const';
|
|
|
end;
|
|
@@ -4186,7 +4220,7 @@ function TPasFileType.GetDeclaration (full : boolean) : string;
|
|
|
begin
|
|
|
Result:='File';
|
|
|
If Assigned(Eltype) then
|
|
|
- Result:=Result+' of '+ElType.Name;
|
|
|
+ Result:=Result+' of '+ElType.SafeName;
|
|
|
If Full Then
|
|
|
Result:=FixTypeDecl(Result);
|
|
|
end;
|
|
@@ -4207,13 +4241,13 @@ begin
|
|
|
S:=TStringList.Create;
|
|
|
Try
|
|
|
If Full and (Name<>'') then
|
|
|
- S.Add(Name+' = (')
|
|
|
+ S.Add(SafeName+' = (')
|
|
|
else
|
|
|
S.Add('(');
|
|
|
GetEnumNames(S);
|
|
|
S[S.Count-1]:=S[S.Count-1]+')';
|
|
|
If Full then
|
|
|
- Result:=IndentStrings(S,Length(Name)+4)
|
|
|
+ Result:=IndentStrings(S,Length(SafeName)+4)
|
|
|
else
|
|
|
Result:=IndentStrings(S,1);
|
|
|
if Full then
|
|
@@ -4241,7 +4275,7 @@ begin
|
|
|
S:=TStringList.Create;
|
|
|
Try
|
|
|
If Full and (Name<>'') then
|
|
|
- S.Add(Name+'= Set of (')
|
|
|
+ S.Add(SafeName+'= Set of (')
|
|
|
else
|
|
|
S.Add('Set of (');
|
|
|
TPasEnumType(EnumType).GetEnumNames(S);
|
|
@@ -4254,9 +4288,9 @@ begin
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
- Result:='Set of '+EnumType.Name;
|
|
|
+ Result:='Set of '+EnumType.SafeName;
|
|
|
If Full then
|
|
|
- Result:=Name+' = '+Result;
|
|
|
+ Result:=SafeName+' = '+Result;
|
|
|
end;
|
|
|
If Full then
|
|
|
ProcessHints(False,Result);
|
|
@@ -4393,9 +4427,9 @@ begin
|
|
|
If Full and (Name<>'') then
|
|
|
begin
|
|
|
if GenericTemplateTypes.Count>0 then
|
|
|
- Temp:=Name+GenericTemplateTypesAsString(GenericTemplateTypes)+' = '+Temp
|
|
|
+ Temp:=SafeName+GenericTemplateTypesAsString(GenericTemplateTypes)+' = '+Temp
|
|
|
else
|
|
|
- Temp:=Name+' = '+Temp;
|
|
|
+ Temp:=SafeName+' = '+Temp;
|
|
|
end;
|
|
|
S.Add(Temp);
|
|
|
GetMembers(S);
|
|
@@ -4467,7 +4501,7 @@ begin
|
|
|
S:=TStringList.Create;
|
|
|
Try
|
|
|
If Full then
|
|
|
- S.Add(Format('%s = ',[Name]));
|
|
|
+ S.Add(Format('%s = ',[SafeName]));
|
|
|
S.Add(TypeName);
|
|
|
GetArguments(S);
|
|
|
If IsOfObject then
|
|
@@ -4493,14 +4527,14 @@ begin
|
|
|
S:=TStringList.Create;
|
|
|
Try
|
|
|
If Full then
|
|
|
- S.Add(Format('%s = ',[Name]));
|
|
|
+ S.Add(Format('%s = ',[SafeName]));
|
|
|
S.Add(TypeName);
|
|
|
GetArguments(S);
|
|
|
If Assigned(ResultEl) then
|
|
|
begin
|
|
|
T:=' : ';
|
|
|
If (ResultEl.ResultType.Name<>'') then
|
|
|
- T:=T+ResultEl.ResultType.Name
|
|
|
+ T:=T+ResultEl.ResultType.SafeName
|
|
|
else
|
|
|
T:=T+ResultEl.ResultType.GetDeclaration(False);
|
|
|
S.Add(T);
|
|
@@ -4534,7 +4568,7 @@ begin
|
|
|
If VarType.Name='' then
|
|
|
Result:=VarType.GetDeclaration(False)
|
|
|
else
|
|
|
- Result:=VarType.Name;
|
|
|
+ Result:=VarType.SafeName;
|
|
|
Result:=Result+Modifiers;
|
|
|
if (Value<>'') then
|
|
|
Result:=Result+' = '+Value;
|
|
@@ -4543,7 +4577,7 @@ begin
|
|
|
Result:=Value;
|
|
|
If Full then
|
|
|
begin
|
|
|
- Result:=Name+' '+Seps[Assigned(VarType)]+' '+Result;
|
|
|
+ Result:=SafeName+' '+Seps[Assigned(VarType)]+' '+Result;
|
|
|
Result:=Result+HintsString;
|
|
|
end;
|
|
|
end;
|
|
@@ -4584,7 +4618,7 @@ begin
|
|
|
If VarType.Name='' then
|
|
|
Result:=VarType.GetDeclaration(False)
|
|
|
else
|
|
|
- Result:=VarType.Name;
|
|
|
+ Result:=VarType.SafeName;
|
|
|
end
|
|
|
else if Assigned(Expr) then
|
|
|
Result:=Expr.GetDeclaration(True);
|
|
@@ -4604,9 +4638,9 @@ begin
|
|
|
S:=' ';
|
|
|
If Full then
|
|
|
begin
|
|
|
- Result:=Name+S+': '+Result;
|
|
|
+ Result:=SafeName+S+': '+Result;
|
|
|
If (ImplementsName<>'') then
|
|
|
- Result:=Result+' implements '+ImplementsName;
|
|
|
+ Result:=Result+' implements '+EscapeKeyWord(ImplementsName);
|
|
|
end;
|
|
|
If IsDefault then
|
|
|
Result:=Result+'; default';
|
|
@@ -4836,7 +4870,7 @@ begin
|
|
|
end;
|
|
|
end
|
|
|
else if Name<>'' then
|
|
|
- T:=T+' '+Name;
|
|
|
+ T:=T+' '+SafeName;
|
|
|
S.Add(T);
|
|
|
end;
|
|
|
ProcType.GetArguments(S);
|
|
@@ -4846,7 +4880,7 @@ begin
|
|
|
begin
|
|
|
T:=' : ';
|
|
|
If (Name<>'') then
|
|
|
- T:=T+Name
|
|
|
+ T:=T+SafeName
|
|
|
else
|
|
|
T:=T+GetDeclaration(False);
|
|
|
S.Add(T);
|
|
@@ -4902,7 +4936,7 @@ begin
|
|
|
begin
|
|
|
T:=' : ';
|
|
|
If (Name<>'') then
|
|
|
- T:=T+Name
|
|
|
+ T:=T+SafeName
|
|
|
else
|
|
|
T:=T+GetDeclaration(False);
|
|
|
S.Add(T);
|
|
@@ -4970,14 +5004,14 @@ begin
|
|
|
If Assigned(ArgType) then
|
|
|
begin
|
|
|
If ArgType.Name<>'' then
|
|
|
- Result:=ArgType.Name
|
|
|
+ Result:=ArgType.SafeName
|
|
|
else
|
|
|
Result:=ArgType.GetDeclaration(False);
|
|
|
If Full and (Name<>'') then
|
|
|
- Result:=Name+': '+Result;
|
|
|
+ Result:=SafeName+': '+Result;
|
|
|
end
|
|
|
else If Full then
|
|
|
- Result:=Name
|
|
|
+ Result:=SafeName
|
|
|
else
|
|
|
Result:='';
|
|
|
end;
|
|
@@ -5637,7 +5671,7 @@ begin
|
|
|
begin
|
|
|
If Result<>'' then
|
|
|
Result:=Result+'; ';
|
|
|
- Result:=Result+Fields[I].Name+': '+Fields[i].ValueExp.getDeclaration(Full);
|
|
|
+ Result:=Result+EscapeKeyWord(Fields[I].Name)+': '+Fields[i].ValueExp.getDeclaration(Full);
|
|
|
end;
|
|
|
Result:='('+Result+')';
|
|
|
end;
|