* Keep variable information in a more structured way

git-svn-id: trunk@21946 -
This commit is contained in:
michael 2012-07-22 14:57:30 +00:00
parent 9672f0537a
commit 5b3026d0ce
2 changed files with 31 additions and 5 deletions

View File

@ -616,6 +616,8 @@ type
end; end;
{ TPasVariable } { TPasVariable }
TVariableModifier = (vmCVar, vmExternal, vmPublic, vmExport);
TVariableModifiers = set of TVariableModifier;
TPasVariable = class(TPasElement) TPasVariable = class(TPasElement)
public public
@ -625,6 +627,8 @@ type
public public
VarType: TPasType; VarType: TPasType;
Value: string; Value: string;
VarModifiers : TVariableModifiers;
LibraryName,ExportName : string;
Modifiers : string; Modifiers : string;
AbsoluteLocation : String; AbsoluteLocation : String;
Expr: TPasExpr; Expr: TPasExpr;

View File

@ -131,7 +131,7 @@ type
FTokenBufferSize: Integer; // maximum valid index in FTokenBuffer FTokenBufferSize: Integer; // maximum valid index in FTokenBuffer
function CheckOverloadList(AList: TFPList; AName: String; out OldMember: TPasElement): TPasOverloadedProc; function CheckOverloadList(AList: TFPList; AName: String; out OldMember: TPasElement): TPasOverloadedProc;
procedure DumpCurToken(Const Msg : String); procedure DumpCurToken(Const Msg : String);
function GetVariableModifiers(Parent: TPasElement): string; function GetVariableModifiers(Parent: TPasElement; Out VarMods : TVariableModifiers; Out Libname,ExportName : string): string;
function GetVariableValueAndLocation(Parent : TPasElement; out Value, Location: String): Boolean; function GetVariableValueAndLocation(Parent : TPasElement; out Value, Location: String): Boolean;
procedure ParseVarList(Parent: TPasElement; VarList: TFPList; AVisibility: TPasMemberVisibility; Full: Boolean); procedure ParseVarList(Parent: TPasElement; VarList: TFPList; AVisibility: TPasMemberVisibility; Full: Boolean);
protected protected
@ -2218,6 +2218,8 @@ Var
E : TPasExportSymbol; E : TPasExportSymbol;
begin begin
Repeat Repeat
if List.Count<>0 then
ExpectIdentifier;
E:=TPasExportSymbol(CreateElement(TPasExportSymbol,CurtokenString,Parent)); E:=TPasExportSymbol(CreateElement(TPasExportSymbol,CurtokenString,Parent));
List.Add(E); List.Add(E);
NextToken; NextToken;
@ -2304,16 +2306,18 @@ begin
UngetToken; UngetToken;
end; end;
Function TPasParser.GetVariableModifiers(Parent : TPasElement) : string; Function TPasParser.GetVariableModifiers(Parent : TPasElement; Out Varmods : TVariableModifiers; Out Libname,ExportName : string) : string;
Var Var
S : String; S : String;
begin begin
Result := ''; Result := '';
VarMods := [];
NextToken; NextToken;
If CurTokenIsIdentifier('cvar') then If CurTokenIsIdentifier('cvar') then
begin begin
Result:=';cvar'; Result:=';cvar';
Include(VarMods,vmcvar);
ExpectToken(tkSemicolon); ExpectToken(tkSemicolon);
NextToken; NextToken;
end; end;
@ -2322,16 +2326,24 @@ begin
UngetToken UngetToken
else else
begin begin
if s='external' then
Include(VarMods,vmexternal)
else if (s='public') then
Include(varMods,vmpublic)
else if (s='export') then
Include(varMods,vmexport);
Result:=Result+';'+CurTokenText; Result:=Result+';'+CurTokenText;
NextToken; NextToken;
if (Curtoken<>tksemicolon) then if (Curtoken<>tksemicolon) then
begin begin
if (s='external') then if (s='external') then
begin begin
Include(VarMods,vmexternal);
if (CurToken in [tkString,tkIdentifier]) if (CurToken in [tkString,tkIdentifier])
and Not (CurTokenIsIdentifier('name')) then and Not (CurTokenIsIdentifier('name')) then
begin begin
Result := Result + ' ' + CurTokenText; Result := Result + ' ' + CurTokenText;
LibName:=CurTokenText;
NextToken; NextToken;
end; end;
end; end;
@ -2343,6 +2355,7 @@ begin
Result := Result + CurTokenText Result := Result + CurTokenText
else else
ParseExc(SParserSyntaxError); ParseExc(SParserSyntaxError);
ExportName:=CurTokenText;
NextToken; NextToken;
end end
else else
@ -2361,7 +2374,8 @@ var
VarType: TPasType; VarType: TPasType;
VarEl: TPasVariable; VarEl: TPasVariable;
H : TPasMemberHints; H : TPasMemberHints;
Mods,Value,Loc : string; varmods: TVariableModifiers;
Mods,Value,Loc,alibname,aexpname : string;
begin begin
VarNames := TStringList.Create; VarNames := TStringList.Create;
@ -2382,16 +2396,24 @@ begin
GetVariableValueAndLocation(Parent,Value,Loc); GetVariableValueAndLocation(Parent,Value,Loc);
H:=CheckHint(Nil,Full); H:=CheckHint(Nil,Full);
if full then if full then
Mods:=GetVariableModifiers(Parent) Mods:=GetVariableModifiers(Parent,varmods,alibname,aexpname)
else else
NextToken; NextToken;
for i := 0 to VarNames.Count - 1 do for i := 0 to VarNames.Count - 1 do
begin begin
VarEl:=TPasVariable(CreateElement(TPasVariable,VarNames[i],Parent,AVisibility)); VarEl:=TPasVariable(CreateElement(TPasVariable,VarNames[i],Parent,AVisibility));
VarEl.VarType := VarType; VarEl.VarType := VarType;
VarEl.Hints:=H; // Procedure declaration eats the hints.
if Assigned(VarType) and (VarType is TPasprocedureType) then
VarEl.Hints:=VarType.Hints
else
VarEl.Hints:=H;
Varel.Modifiers:=Mods;
Varel.VarModifiers:=VarMods;
VarEl.Value:=Value; VarEl.Value:=Value;
VarEl.AbsoluteLocation:=Loc; VarEl.AbsoluteLocation:=Loc;
VarEl.LibraryName:=alibName;
VarEl.ExportName:=aexpname;
if (i>0) then if (i>0) then
VarType.AddRef; VarType.AddRef;
VarList.Add(VarEl); VarList.Add(VarEl);