codetools: fixed parsing (* comments

git-svn-id: trunk@14115 -
This commit is contained in:
mattias 2008-02-12 17:51:41 +00:00
parent ac191520f1
commit 746753524e
2 changed files with 24 additions and 23 deletions

View File

@ -1626,7 +1626,7 @@ begin
end; end;
end; end;
'/': // comment or real division '/': // comment or real division
if (Position<Len) and (Source[Position]='/') then begin if (Position<Len) and (Source[Position+1]='/') then begin
// comment start -> read til line end // comment start -> read til line end
inc(Position); inc(Position);
while (Position<=Len) and (not (Source[Position] in [#10,#13])) do while (Position<=Len) and (not (Source[Position] in [#10,#13])) do
@ -1634,7 +1634,7 @@ begin
end else end else
break; break;
'(': // comment, bracket or compiler directive '(': // comment, bracket or compiler directive
if (Position<Len) and (Source[Position]='*') then begin if (Position<Len) and (Source[Position+1]='*') then begin
if (Position+2<=Len) and (Source[Position]='$') then if (Position+2<=Len) and (Source[Position]='$') then
// compiler directive // compiler directive
break break

View File

@ -1371,7 +1371,7 @@ procedure TCompilerDirectivesTree.DisableIfNode(Node: TCodeTreeNode;
procedure RaiseImpossible; procedure RaiseImpossible;
begin begin
raise ECDirectiveParserException.Create(Self,'TCompilerDirectivesTree.DisableIfNode'); raise ECDirectiveParserException.Create(Self,'TCompilerDirectivesTree.DisableIfNode impossible');
end; end;
function GetExpr(ExprNode: TCodeTreeNode; out Negated: boolean): string; function GetExpr(ExprNode: TCodeTreeNode; out Negated: boolean): string;
@ -1616,27 +1616,28 @@ var
procedure CheckNode; procedure CheckNode;
begin begin
//DebugLn(['CheckNode ',Node.Desc=cdnIf,' ',(Node.NextBrother<>nil),' ',(Node.FirstChild=nil),' ',GetDirective(Node)]);
case Node.Desc of case Node.Desc of
cdnIf,cdnElse,cdnElseIf: ; cdnIf,cdnElseIf,cdnElse:
else exit; if (Node.NextBrother<>nil) and (Node.FirstChild=nil) then begin
end; case Node.NextBrother.Desc of
cdnEnd,cdnElseIf,cdnElse:
if (Node.NextBrother=nil) or (Node.FirstChild<>nil) then exit; begin
case Node.NextBrother.Desc of //DebugLn(['CheckNode Checking if empty ...']);
cdnEnd,cdnElse,cdnElseIf: MoveCursorToPos(Node.StartPos);
if Node.FirstChild=nil then begin // skip directive
MoveCursorToPos(Node.StartPos); ReadNextAtom;
// skip directive // read the following atom (token or directive)
ReadNextAtom; ReadNextAtom;
// read the following atom (token or directive) if AtomStart=Node.NextBrother.StartPos then begin
ReadNextAtom; // node is empty
if AtomStart=Node.NextBrother.StartPos then begin NextNode:=Node.NextBrother;
// node is empty if NextNode.Desc=cdnEnd then
NextNode:=Node.NextBrother; NextNode:=NextNode.NextSkipChilds;
if NextNode.Desc=cdnEnd then DebugLn(['TCompilerDirectivesTree.RemoveEmptyNodes node only contains spaces and comments ',GetDirective(Node)]);
NextNode:=NextNode.NextSkipChilds; DisableIfNode(Node,true,Changed);
DebugLn(['TCompilerDirectivesTree.RemoveEmptyNodes node only contains spaces and comments ',GetDirective(Node)]); end;
DisableIfNode(Node,true,Changed); end;
end; end;
end; end;
end; end;