codetools: fixed using the right keyword DoIt function

git-svn-id: trunk@14290 -
This commit is contained in:
mattias 2008-02-27 20:15:49 +00:00
parent 84a959ff17
commit e033e82e6d
8 changed files with 55 additions and 17 deletions

View File

@ -50,6 +50,7 @@ const
ccnRoot = 1+ccnBase; ccnRoot = 1+ccnBase;
ccnDirective = 2+ccnBase;// e.g. "#define a" ,can be multiple lines, without line end ccnDirective = 2+ccnBase;// e.g. "#define a" ,can be multiple lines, without line end
ccnExtern = 3+ccnBase;// e.g. extern "C" {} ccnExtern = 3+ccnBase;// e.g. extern "C" {}
ccnEnum = 4+ccnBase;// e.g. enum {};
type type
TCCodeParserTool = class; TCCodeParserTool = class;
@ -72,6 +73,7 @@ type
function OtherToken: boolean; function OtherToken: boolean;
function DirectiveToken: boolean; function DirectiveToken: boolean;
function ExternToken: boolean; function ExternToken: boolean;
function EnumToken: boolean;
procedure InitKeyWordList; procedure InitKeyWordList;
procedure InitParser; procedure InitParser;
@ -79,6 +81,8 @@ type
procedure EndChildNode; procedure EndChildNode;
procedure CloseNodes; procedure CloseNodes;
procedure ReadConstant;
procedure RaiseException(const AMessage: string); procedure RaiseException(const AMessage: string);
procedure RaiseExpectedButAtomFound(const AToken: string); procedure RaiseExpectedButAtomFound(const AToken: string);
public public
@ -117,8 +121,10 @@ type
function CCNodeDescAsString(Desc: TCCodeNodeDesc): string; function CCNodeDescAsString(Desc: TCCodeNodeDesc): string;
implementation implementation
function CCNodeDescAsString(Desc: TCCodeNodeDesc): string; function CCNodeDescAsString(Desc: TCCodeNodeDesc): string;
begin begin
case Desc of case Desc of
@ -168,6 +174,31 @@ begin
RaiseExpectedButAtomFound('{'); RaiseExpectedButAtomFound('{');
end; end;
function TCCodeParserTool.EnumToken: boolean;
begin
Result:=true;
CreateChildNode(ccnExtern);
ReadNextAtom;
if not AtomIs('{') then
RaiseExpectedButAtomFound('{');
// read enums. Examples
// name,
// name = constant,
ReadNextAtom;
repeat
if AtomIsIdentifier then begin
ReadNextAtom;
if AtomIs('=') then begin
ReadNextAtom;
ReadConstant;
end;
end else if AtomIs('}') then begin
break;
end else
RaiseExpectedButAtomFound('{');
until false;
end;
procedure TCCodeParserTool.InitKeyWordList; procedure TCCodeParserTool.InitKeyWordList;
begin begin
if FDefaultTokenList=nil then begin if FDefaultTokenList=nil then begin
@ -175,6 +206,7 @@ begin
with FDefaultTokenList do begin with FDefaultTokenList do begin
Add('#',{$ifdef FPC}@{$endif}DirectiveToken); Add('#',{$ifdef FPC}@{$endif}DirectiveToken);
Add('extern',{$ifdef FPC}@{$endif}ExternToken); Add('extern',{$ifdef FPC}@{$endif}ExternToken);
Add('enum',{$ifdef FPC}@{$endif}EnumToken);
DefaultKeyWordFunction:={$ifdef FPC}@{$endif}OtherToken; DefaultKeyWordFunction:={$ifdef FPC}@{$endif}OtherToken;
end; end;
end; end;
@ -227,6 +259,11 @@ begin
end; end;
end; end;
procedure TCCodeParserTool.ReadConstant;
begin
end;
procedure TCCodeParserTool.RaiseException(const AMessage: string); procedure TCCodeParserTool.RaiseException(const AMessage: string);
begin begin
CloseNodes; CloseNodes;
@ -268,7 +305,7 @@ begin
repeat repeat
ReadNextAtom; ReadNextAtom;
if SrcPos<=SrcLen then begin if SrcPos<=SrcLen then begin
FDefaultTokenList.DoIt(Src,AtomStart,SrcPos-AtomStart); FDefaultTokenList.DoItCaseSensitive(Src,AtomStart,SrcPos-AtomStart);
end else begin end else begin
break; break;
end; end;

View File

@ -2340,9 +2340,9 @@ var
end; end;
// check for compiler built in operators, constants and types // check for compiler built in operators, constants and types
if IsWordBuiltInFunc.DoIt(Identifier) then exit; if IsWordBuiltInFunc.DoItCaseInsensitive(Identifier) then exit;
if WordIsBinaryOperator.DoIt(Identifier) then exit; if WordIsBinaryOperator.DoItCaseInsensitive(Identifier) then exit;
if WordIsPredefinedFPCIdentifier.DoIt(Identifier) then exit; if WordIsPredefinedFPCIdentifier.DoItCaseInsensitive(Identifier) then exit;
Result:=false; Result:=false;
end; end;

View File

@ -1719,7 +1719,7 @@ begin
// compiler directive // compiler directive
DirectiveName:=@Src[AtomStart+2]; DirectiveName:=@Src[AtomStart+2];
//DebugLn(['ParseCompilerDirectives ',GetIdentifier(DirectiveName)]); //DebugLn(['ParseCompilerDirectives ',GetIdentifier(DirectiveName)]);
FDefaultDirectiveFuncList.DoIt(DirectiveName); FDefaultDirectiveFuncList.DoItCaseInsensitive(DirectiveName);
end; end;
end else begin end else begin
break; break;

View File

@ -26,10 +26,10 @@
</RunParams> </RunParams>
<RequiredPackages Count="2"> <RequiredPackages Count="2">
<Item1> <Item1>
<PackageName Value="CodeTools"/> <PackageName Value="LCL"/>
</Item1> </Item1>
<Item2> <Item2>
<PackageName Value="LCL"/> <PackageName Value="CodeTools"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="1"> <Units Count="1">

View File

@ -1,4 +1,4 @@
(* {
*************************************************************************** ***************************************************************************
* * * *
* This source is free software; you can redistribute it and/or modify * * This source is free software; you can redistribute it and/or modify *
@ -25,7 +25,7 @@
Usage: Usage:
h2pastest [filename.h] h2pastest [filename.h]
*) }
program H2PasTest; program H2PasTest;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}

View File

@ -933,7 +933,7 @@ begin
Result:=xtConstOrdInteger Result:=xtConstOrdInteger
else if CompareIdentifiers(Identifier,'VARIANT')=0 then else if CompareIdentifiers(Identifier,'VARIANT')=0 then
Result:=xtVariant Result:=xtVariant
else if IsWordBuiltInFunc.DoIt(Identifier) then else if IsWordBuiltInFunc.DoItCaseInsensitive(Identifier) then
Result:=xtCompilerFunc Result:=xtCompilerFunc
// the delphi compiler special types // the delphi compiler special types
@ -2324,7 +2324,8 @@ var
if not (fdfExceptionOnNotFound in Params.Flags) then exit; if not (fdfExceptionOnNotFound in Params.Flags) then exit;
if (Params.Identifier<>nil) if (Params.Identifier<>nil)
and not (fdfExceptionOnPredefinedIdent in Params.Flags) and not (fdfExceptionOnPredefinedIdent in Params.Flags)
and WordIsPredefinedIdentifier.DoIt(Params.Identifier) then begin and WordIsPredefinedIdentifier.DoItCaseInsensitive(Params.Identifier)
then begin
Params.SetResult(nil,nil); Params.SetResult(nil,nil);
exit; exit;
end; end;

View File

@ -68,11 +68,11 @@ type
function KeyWordToHashIndex(Start: PChar; Len: integer): integer; function KeyWordToHashIndex(Start: PChar; Len: integer): integer;
public public
DefaultKeyWordFunction: TKeyWordFunction; DefaultKeyWordFunction: TKeyWordFunction;
function DoIt(const AKeyWord: shortstring): boolean; function DoItCaseSensitive(const AKeyWord: shortstring): boolean;
function DoItCaseInsensitive(const AKeyWord: shortstring): boolean; function DoItCaseInsensitive(const AKeyWord: shortstring): boolean;
function DoItCaseInsensitive(const ASource: string; function DoItCaseInsensitive(const ASource: string;
KeyWordStart, KeyWordLen: integer): boolean; KeyWordStart, KeyWordLen: integer): boolean;
function DoIt(const ASource: string; function DoItCaseSensitive(const ASource: string;
KeyWordStart, KeyWordLen: integer): boolean; KeyWordStart, KeyWordLen: integer): boolean;
function DoItUppercase(const AnUpperSource: string; function DoItUppercase(const AnUpperSource: string;
KeyWordStart, KeyWordLen: integer): boolean; KeyWordStart, KeyWordLen: integer): boolean;
@ -263,7 +263,7 @@ begin
if Result>FMaxHashIndex then Result:=-1; if Result>FMaxHashIndex then Result:=-1;
end; end;
function TKeyWordFunctionList.DoIt(const AKeyWord: shortstring): boolean; function TKeyWordFunctionList.DoItCaseSensitive(const AKeyWord: shortstring): boolean;
var var
i: integer; i: integer;
KeyWordFuncItem: PKeyWordFunctionListItem; KeyWordFuncItem: PKeyWordFunctionListItem;
@ -329,8 +329,8 @@ begin
Result:=DefaultKeyWordFunction(); Result:=DefaultKeyWordFunction();
end; end;
function TKeyWordFunctionList.DoIt(const ASource: string; KeyWordStart, function TKeyWordFunctionList.DoItCaseSensitive(const ASource: string;
KeyWordLen: integer): boolean; KeyWordStart, KeyWordLen: integer): boolean;
// ! does not test if length(ASource) >= KeyWordStart+KeyWordLen -1 // ! does not test if length(ASource) >= KeyWordStart+KeyWordLen -1
var var
i, KeyPos, WordPos: integer; i, KeyPos, WordPos: integer;

View File

@ -117,7 +117,7 @@ begin
Add(TCustomImage,'Picture'); Add(TCustomImage,'Picture');
Add(TCustomImage,'Align'); Add(TCustomImage,'Align');
Add(TCustomNotebook,'Align'); Add(TCustomNotebook,'Align');
Add(TCustomScrollBox,'Align'); Add(TScrollBox,'Align');
Add(TCustomGrid,'Align'); Add(TCustomGrid,'Align');
Add(TCustomGrid,'Options'); Add(TCustomGrid,'Options');
Add(TCustomGrid,'Columns'); Add(TCustomGrid,'Columns');