mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-09 04:36:42 +02:00
codetools: implemented extracting c function types
git-svn-id: trunk@14525 -
This commit is contained in:
parent
abd08bc5f4
commit
095053bca9
@ -152,6 +152,7 @@ type
|
||||
function MainFilename: string;
|
||||
|
||||
procedure MoveCursorToPos(p: integer);
|
||||
procedure MoveCursorToNode(Node: TCodeTreeNode);
|
||||
procedure ReadNextAtom;
|
||||
procedure ReadNextAtomSkipDirectives;
|
||||
procedure UndoReadNextAtom;
|
||||
@ -167,6 +168,9 @@ type
|
||||
function ExtractCode(StartPos, EndPos: integer;
|
||||
WithDirectives: boolean = false): string;// extract code without comments
|
||||
|
||||
function ExtractVariableName(Node: TCodeTreeNode): string;
|
||||
function ExtractVariableType(Node: TCodeTreeNode): string;
|
||||
|
||||
procedure Replace(FromPos, ToPos: integer; const NewSrc: string);
|
||||
|
||||
procedure IncreaseChangeStep;
|
||||
@ -917,6 +921,11 @@ begin
|
||||
LastSrcPos:=0;
|
||||
end;
|
||||
|
||||
procedure TCCodeParserTool.MoveCursorToNode(Node: TCodeTreeNode);
|
||||
begin
|
||||
MoveCursorToPos(Node.StartPos);
|
||||
end;
|
||||
|
||||
procedure TCCodeParserTool.ReadNextAtom;
|
||||
begin
|
||||
//DebugLn(['TCCodeParserTool.ReadNextAtom START ',AtomStart,'-',SrcPos,' ',Src[SrcPos]]);
|
||||
@ -1129,6 +1138,35 @@ begin
|
||||
Result:=s;
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.ExtractVariableName(Node: TCodeTreeNode): string;
|
||||
var
|
||||
NameNode: TCodeTreeNode;
|
||||
begin
|
||||
NameNode:=Node.FirstChild;
|
||||
if (NameNode=nil) or (NameNode.Desc<>ccnVariableName) then
|
||||
Result:=''
|
||||
else
|
||||
Result:=copy(Src,NameNode.StartPos,NameNode.EndPos-NameNode.StartPos);
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.ExtractVariableType(Node: TCodeTreeNode): string;
|
||||
var
|
||||
NameNode: TCodeTreeNode;
|
||||
begin
|
||||
NameNode:=Node.FirstChild;
|
||||
if (NameNode=nil) or (NameNode.Desc<>ccnVariableName) then
|
||||
Result:=''
|
||||
else begin
|
||||
Result:=ExtractCode(Node.StartPos,NameNode.StartPos,true);
|
||||
if (NameNode.NextBrother<>nil)
|
||||
and (NameNode.NextBrother.Desc=ccnFuncParamList) then begin
|
||||
// this is a function. The name is in between.
|
||||
// The type is result type + parameter list
|
||||
Result:=Result+ExtractCode(NameNode.EndPos,NameNode.NextBrother.EndPos,true);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.GetAtom: string;
|
||||
begin
|
||||
Result:=copy(Src,AtomStart,SrcPos-AtomStart);
|
||||
|
@ -94,8 +94,6 @@ type
|
||||
function Convert(CCode, PascalCode: TCodeBuffer): boolean;
|
||||
procedure BuildH2PTree;
|
||||
|
||||
function ExtractCVariableName(CVarNode: TCodeTreeNode): string;
|
||||
function ExtractCVariableType(CVarNode: TCodeTreeNode): string;
|
||||
function HasCVariableSimplePascalType(CVarNode: TCodeTreeNode): boolean;
|
||||
|
||||
procedure WriteDebugReport;
|
||||
@ -138,8 +136,8 @@ begin
|
||||
case CNode.Desc of
|
||||
ccnVariable:
|
||||
begin
|
||||
VarName:=ExtractCVariableName(CNode);
|
||||
VarType:=ExtractCVariableType(CNode);
|
||||
VarName:=CTool.ExtractVariableName(CNode);
|
||||
VarType:=CTool.ExtractVariableType(CNode);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree Variable Name="',VarName,'" Type="',VarType,'"']);
|
||||
end;
|
||||
|
||||
@ -148,38 +146,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TH2PasTool.ExtractCVariableName(CVarNode: TCodeTreeNode): string;
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
Node:=CVarNode.FirstChild;
|
||||
if (Node=nil) or (Node.Desc<>ccnVariableName) then
|
||||
Result:=''
|
||||
else
|
||||
Result:=copy(CTool.Src,Node.StartPos,Node.EndPos-node.StartPos);
|
||||
end;
|
||||
|
||||
function TH2PasTool.ExtractCVariableType(CVarNode: TCodeTreeNode): string;
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
Node:=CVarNode.FirstChild;
|
||||
if (Node=nil) or (Node.Desc<>ccnVariableName) then
|
||||
Result:=''
|
||||
else begin
|
||||
Result:=CTool.ExtractCode(CVarNode.StartPos,Node.StartPos,true);
|
||||
if System.Pos('(',Result)>0 then begin
|
||||
// this is a function
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TH2PasTool.HasCVariableSimplePascalType(
|
||||
CVarNode: TCodeTreeNode): boolean;
|
||||
var
|
||||
VarType: String;
|
||||
begin
|
||||
VarType:=ExtractCVariableType(CVarNode);
|
||||
VarType:=CTool.ExtractVariableType(CVarNode);
|
||||
if VarType='' then
|
||||
exit(false);
|
||||
Result:=IsValidIdent(VarType);
|
||||
|
Loading…
Reference in New Issue
Block a user