mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 21:42:51 +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;
|
function MainFilename: string;
|
||||||
|
|
||||||
procedure MoveCursorToPos(p: integer);
|
procedure MoveCursorToPos(p: integer);
|
||||||
|
procedure MoveCursorToNode(Node: TCodeTreeNode);
|
||||||
procedure ReadNextAtom;
|
procedure ReadNextAtom;
|
||||||
procedure ReadNextAtomSkipDirectives;
|
procedure ReadNextAtomSkipDirectives;
|
||||||
procedure UndoReadNextAtom;
|
procedure UndoReadNextAtom;
|
||||||
@ -167,6 +168,9 @@ type
|
|||||||
function ExtractCode(StartPos, EndPos: integer;
|
function ExtractCode(StartPos, EndPos: integer;
|
||||||
WithDirectives: boolean = false): string;// extract code without comments
|
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 Replace(FromPos, ToPos: integer; const NewSrc: string);
|
||||||
|
|
||||||
procedure IncreaseChangeStep;
|
procedure IncreaseChangeStep;
|
||||||
@ -917,6 +921,11 @@ begin
|
|||||||
LastSrcPos:=0;
|
LastSrcPos:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCCodeParserTool.MoveCursorToNode(Node: TCodeTreeNode);
|
||||||
|
begin
|
||||||
|
MoveCursorToPos(Node.StartPos);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCCodeParserTool.ReadNextAtom;
|
procedure TCCodeParserTool.ReadNextAtom;
|
||||||
begin
|
begin
|
||||||
//DebugLn(['TCCodeParserTool.ReadNextAtom START ',AtomStart,'-',SrcPos,' ',Src[SrcPos]]);
|
//DebugLn(['TCCodeParserTool.ReadNextAtom START ',AtomStart,'-',SrcPos,' ',Src[SrcPos]]);
|
||||||
@ -1129,6 +1138,35 @@ begin
|
|||||||
Result:=s;
|
Result:=s;
|
||||||
end;
|
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;
|
function TCCodeParserTool.GetAtom: string;
|
||||||
begin
|
begin
|
||||||
Result:=copy(Src,AtomStart,SrcPos-AtomStart);
|
Result:=copy(Src,AtomStart,SrcPos-AtomStart);
|
||||||
|
@ -94,8 +94,6 @@ type
|
|||||||
function Convert(CCode, PascalCode: TCodeBuffer): boolean;
|
function Convert(CCode, PascalCode: TCodeBuffer): boolean;
|
||||||
procedure BuildH2PTree;
|
procedure BuildH2PTree;
|
||||||
|
|
||||||
function ExtractCVariableName(CVarNode: TCodeTreeNode): string;
|
|
||||||
function ExtractCVariableType(CVarNode: TCodeTreeNode): string;
|
|
||||||
function HasCVariableSimplePascalType(CVarNode: TCodeTreeNode): boolean;
|
function HasCVariableSimplePascalType(CVarNode: TCodeTreeNode): boolean;
|
||||||
|
|
||||||
procedure WriteDebugReport;
|
procedure WriteDebugReport;
|
||||||
@ -138,8 +136,8 @@ begin
|
|||||||
case CNode.Desc of
|
case CNode.Desc of
|
||||||
ccnVariable:
|
ccnVariable:
|
||||||
begin
|
begin
|
||||||
VarName:=ExtractCVariableName(CNode);
|
VarName:=CTool.ExtractVariableName(CNode);
|
||||||
VarType:=ExtractCVariableType(CNode);
|
VarType:=CTool.ExtractVariableType(CNode);
|
||||||
DebugLn(['TH2PasTool.BuildH2PTree Variable Name="',VarName,'" Type="',VarType,'"']);
|
DebugLn(['TH2PasTool.BuildH2PTree Variable Name="',VarName,'" Type="',VarType,'"']);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -148,38 +146,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
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(
|
function TH2PasTool.HasCVariableSimplePascalType(
|
||||||
CVarNode: TCodeTreeNode): boolean;
|
CVarNode: TCodeTreeNode): boolean;
|
||||||
var
|
var
|
||||||
VarType: String;
|
VarType: String;
|
||||||
begin
|
begin
|
||||||
VarType:=ExtractCVariableType(CVarNode);
|
VarType:=CTool.ExtractVariableType(CVarNode);
|
||||||
if VarType='' then
|
if VarType='' then
|
||||||
exit(false);
|
exit(false);
|
||||||
Result:=IsValidIdent(VarType);
|
Result:=IsValidIdent(VarType);
|
||||||
|
Loading…
Reference in New Issue
Block a user