mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-11-04 12:49:42 +01:00 
			
		
		
		
	codetools: fixed using the right keyword DoIt function
git-svn-id: trunk@14290 -
This commit is contained in:
		
							parent
							
								
									84a959ff17
								
							
						
					
					
						commit
						e033e82e6d
					
				@ -50,6 +50,7 @@ const
 | 
			
		||||
  ccnRoot      =  1+ccnBase;
 | 
			
		||||
  ccnDirective =  2+ccnBase;// e.g. "#define a" ,can be multiple lines, without line end
 | 
			
		||||
  ccnExtern    =  3+ccnBase;// e.g. extern "C" {}
 | 
			
		||||
  ccnEnum      =  4+ccnBase;// e.g. enum {};
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
  TCCodeParserTool = class;
 | 
			
		||||
@ -72,6 +73,7 @@ type
 | 
			
		||||
    function OtherToken: boolean;
 | 
			
		||||
    function DirectiveToken: boolean;
 | 
			
		||||
    function ExternToken: boolean;
 | 
			
		||||
    function EnumToken: boolean;
 | 
			
		||||
    procedure InitKeyWordList;
 | 
			
		||||
 | 
			
		||||
    procedure InitParser;
 | 
			
		||||
@ -79,6 +81,8 @@ type
 | 
			
		||||
    procedure EndChildNode;
 | 
			
		||||
    procedure CloseNodes;
 | 
			
		||||
    
 | 
			
		||||
    procedure ReadConstant;
 | 
			
		||||
    
 | 
			
		||||
    procedure RaiseException(const AMessage: string);
 | 
			
		||||
    procedure RaiseExpectedButAtomFound(const AToken: string);
 | 
			
		||||
  public
 | 
			
		||||
@ -117,8 +121,10 @@ type
 | 
			
		||||
  
 | 
			
		||||
function CCNodeDescAsString(Desc: TCCodeNodeDesc): string;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function CCNodeDescAsString(Desc: TCCodeNodeDesc): string;
 | 
			
		||||
begin
 | 
			
		||||
  case Desc of
 | 
			
		||||
@ -168,6 +174,31 @@ begin
 | 
			
		||||
    RaiseExpectedButAtomFound('{');
 | 
			
		||||
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;
 | 
			
		||||
begin
 | 
			
		||||
  if FDefaultTokenList=nil then begin
 | 
			
		||||
@ -175,6 +206,7 @@ begin
 | 
			
		||||
    with FDefaultTokenList do begin
 | 
			
		||||
      Add('#',{$ifdef FPC}@{$endif}DirectiveToken);
 | 
			
		||||
      Add('extern',{$ifdef FPC}@{$endif}ExternToken);
 | 
			
		||||
      Add('enum',{$ifdef FPC}@{$endif}EnumToken);
 | 
			
		||||
      DefaultKeyWordFunction:={$ifdef FPC}@{$endif}OtherToken;
 | 
			
		||||
    end;
 | 
			
		||||
  end;
 | 
			
		||||
@ -227,6 +259,11 @@ begin
 | 
			
		||||
  end;
 | 
			
		||||
end;
 | 
			
		||||
 | 
			
		||||
procedure TCCodeParserTool.ReadConstant;
 | 
			
		||||
begin
 | 
			
		||||
 | 
			
		||||
end;
 | 
			
		||||
 | 
			
		||||
procedure TCCodeParserTool.RaiseException(const AMessage: string);
 | 
			
		||||
begin
 | 
			
		||||
  CloseNodes;
 | 
			
		||||
@ -268,7 +305,7 @@ begin
 | 
			
		||||
  repeat
 | 
			
		||||
    ReadNextAtom;
 | 
			
		||||
    if SrcPos<=SrcLen then begin
 | 
			
		||||
      FDefaultTokenList.DoIt(Src,AtomStart,SrcPos-AtomStart);
 | 
			
		||||
      FDefaultTokenList.DoItCaseSensitive(Src,AtomStart,SrcPos-AtomStart);
 | 
			
		||||
    end else begin
 | 
			
		||||
      break;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
@ -2340,9 +2340,9 @@ var
 | 
			
		||||
      end;
 | 
			
		||||
 | 
			
		||||
      // check for compiler built in operators, constants and types
 | 
			
		||||
      if IsWordBuiltInFunc.DoIt(Identifier) then exit;
 | 
			
		||||
      if WordIsBinaryOperator.DoIt(Identifier) then exit;
 | 
			
		||||
      if WordIsPredefinedFPCIdentifier.DoIt(Identifier) then exit;
 | 
			
		||||
      if IsWordBuiltInFunc.DoItCaseInsensitive(Identifier) then exit;
 | 
			
		||||
      if WordIsBinaryOperator.DoItCaseInsensitive(Identifier) then exit;
 | 
			
		||||
      if WordIsPredefinedFPCIdentifier.DoItCaseInsensitive(Identifier) then exit;
 | 
			
		||||
      Result:=false;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1719,7 +1719,7 @@ begin
 | 
			
		||||
        // compiler directive
 | 
			
		||||
        DirectiveName:=@Src[AtomStart+2];
 | 
			
		||||
        //DebugLn(['ParseCompilerDirectives ',GetIdentifier(DirectiveName)]);
 | 
			
		||||
        FDefaultDirectiveFuncList.DoIt(DirectiveName);
 | 
			
		||||
        FDefaultDirectiveFuncList.DoItCaseInsensitive(DirectiveName);
 | 
			
		||||
      end;
 | 
			
		||||
    end else begin
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
@ -26,10 +26,10 @@
 | 
			
		||||
    </RunParams>
 | 
			
		||||
    <RequiredPackages Count="2">
 | 
			
		||||
      <Item1>
 | 
			
		||||
        <PackageName Value="CodeTools"/>
 | 
			
		||||
        <PackageName Value="LCL"/>
 | 
			
		||||
      </Item1>
 | 
			
		||||
      <Item2>
 | 
			
		||||
        <PackageName Value="LCL"/>
 | 
			
		||||
        <PackageName Value="CodeTools"/>
 | 
			
		||||
      </Item2>
 | 
			
		||||
    </RequiredPackages>
 | 
			
		||||
    <Units Count="1">
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
(*
 | 
			
		||||
{
 | 
			
		||||
 ***************************************************************************
 | 
			
		||||
 *                                                                         *
 | 
			
		||||
 *   This source is free software; you can redistribute it and/or modify   *
 | 
			
		||||
@ -25,7 +25,7 @@
 | 
			
		||||
    
 | 
			
		||||
  Usage:
 | 
			
		||||
    h2pastest [filename.h]
 | 
			
		||||
*)
 | 
			
		||||
}
 | 
			
		||||
program H2PasTest;
 | 
			
		||||
 | 
			
		||||
{$mode objfpc}{$H+}
 | 
			
		||||
 | 
			
		||||
@ -933,7 +933,7 @@ begin
 | 
			
		||||
    Result:=xtConstOrdInteger
 | 
			
		||||
  else if CompareIdentifiers(Identifier,'VARIANT')=0 then
 | 
			
		||||
    Result:=xtVariant
 | 
			
		||||
  else if IsWordBuiltInFunc.DoIt(Identifier) then
 | 
			
		||||
  else if IsWordBuiltInFunc.DoItCaseInsensitive(Identifier) then
 | 
			
		||||
    Result:=xtCompilerFunc
 | 
			
		||||
 | 
			
		||||
  // the delphi compiler special types
 | 
			
		||||
@ -2324,7 +2324,8 @@ var
 | 
			
		||||
    if not (fdfExceptionOnNotFound in Params.Flags) then exit;
 | 
			
		||||
    if (Params.Identifier<>nil)
 | 
			
		||||
    and not (fdfExceptionOnPredefinedIdent in Params.Flags)
 | 
			
		||||
    and WordIsPredefinedIdentifier.DoIt(Params.Identifier) then begin
 | 
			
		||||
    and WordIsPredefinedIdentifier.DoItCaseInsensitive(Params.Identifier)
 | 
			
		||||
    then begin
 | 
			
		||||
      Params.SetResult(nil,nil);
 | 
			
		||||
      exit;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
@ -68,11 +68,11 @@ type
 | 
			
		||||
    function KeyWordToHashIndex(Start: PChar; Len: integer): integer;
 | 
			
		||||
  public
 | 
			
		||||
    DefaultKeyWordFunction: TKeyWordFunction;
 | 
			
		||||
    function DoIt(const AKeyWord: shortstring): boolean;
 | 
			
		||||
    function DoItCaseSensitive(const AKeyWord: shortstring): boolean;
 | 
			
		||||
    function DoItCaseInsensitive(const AKeyWord: shortstring): boolean;
 | 
			
		||||
    function DoItCaseInsensitive(const ASource: string;
 | 
			
		||||
                           KeyWordStart, KeyWordLen: integer): boolean;
 | 
			
		||||
    function DoIt(const ASource: string;
 | 
			
		||||
    function DoItCaseSensitive(const ASource: string;
 | 
			
		||||
                           KeyWordStart, KeyWordLen: integer): boolean;
 | 
			
		||||
    function DoItUppercase(const AnUpperSource: string;
 | 
			
		||||
                           KeyWordStart, KeyWordLen: integer): boolean;
 | 
			
		||||
@ -263,7 +263,7 @@ begin
 | 
			
		||||
  if Result>FMaxHashIndex then Result:=-1;
 | 
			
		||||
end;
 | 
			
		||||
 | 
			
		||||
function TKeyWordFunctionList.DoIt(const AKeyWord: shortstring): boolean;
 | 
			
		||||
function TKeyWordFunctionList.DoItCaseSensitive(const AKeyWord: shortstring): boolean;
 | 
			
		||||
var
 | 
			
		||||
  i: integer;
 | 
			
		||||
  KeyWordFuncItem: PKeyWordFunctionListItem;
 | 
			
		||||
@ -329,8 +329,8 @@ begin
 | 
			
		||||
  Result:=DefaultKeyWordFunction();
 | 
			
		||||
end;
 | 
			
		||||
 | 
			
		||||
function TKeyWordFunctionList.DoIt(const ASource: string; KeyWordStart,
 | 
			
		||||
  KeyWordLen: integer): boolean;
 | 
			
		||||
function TKeyWordFunctionList.DoItCaseSensitive(const ASource: string;
 | 
			
		||||
  KeyWordStart, KeyWordLen: integer): boolean;
 | 
			
		||||
// ! does not test if length(ASource) >= KeyWordStart+KeyWordLen -1
 | 
			
		||||
var
 | 
			
		||||
  i, KeyPos, WordPos: integer;
 | 
			
		||||
 | 
			
		||||
@ -117,7 +117,7 @@ begin
 | 
			
		||||
  Add(TCustomImage,'Picture');
 | 
			
		||||
  Add(TCustomImage,'Align');
 | 
			
		||||
  Add(TCustomNotebook,'Align');
 | 
			
		||||
  Add(TCustomScrollBox,'Align');
 | 
			
		||||
  Add(TScrollBox,'Align');
 | 
			
		||||
  Add(TCustomGrid,'Align');
 | 
			
		||||
  Add(TCustomGrid,'Options');
 | 
			
		||||
  Add(TCustomGrid,'Columns');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user