mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 08:58:23 +02:00
Jedi code format: issue #40612 Accept and "or xor class, ..." operators and improved formatting of operator overloads.
This commit is contained in:
parent
7eb6be5a2c
commit
dedb2622b3
@ -115,7 +115,6 @@ type
|
||||
procedure RecogniseProcedureDeclSection;
|
||||
procedure RecogniseClassOperator(const pbHasBody: boolean);
|
||||
procedure RecogniseOperator(const pbHasBody: boolean);
|
||||
procedure RecogniseOperatorSymbol;
|
||||
|
||||
// set pbAnon = true if the proc has no name
|
||||
procedure RecogniseProcedureHeading(const pbAnon, pbCanInterfaceMap: boolean);
|
||||
@ -2605,7 +2604,7 @@ begin
|
||||
Recognise(ttOperator);
|
||||
|
||||
CheckEnumeratorToken();
|
||||
RecogniseOperatorSymbol();
|
||||
RecogniseMethodName(False);
|
||||
|
||||
if fcTokenList.FirstSolidTokenType = ttOpenBracket then
|
||||
RecogniseFormalParameters;
|
||||
@ -2635,16 +2634,6 @@ begin
|
||||
PopNode;
|
||||
end;
|
||||
|
||||
procedure TBuildParseTree.RecogniseOperatorSymbol;
|
||||
const
|
||||
OperatorTokens: TTokenTypeSet = [ttPlus, ttMinus, ttTimes, ttFloatDiv, ttExponent,
|
||||
ttEquals, ttGreaterThan, ttLessThan, ttGreaterThanOrEqual, ttLessThanOrEqual,
|
||||
ttAssign, ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign, ttXor,
|
||||
ttAnd, ttOr, ttEnumerator, ttNot, ttDiv, ttMod, ttIn, ttShl, ttShr];
|
||||
begin
|
||||
Recognise(OperatorTokens);
|
||||
end;
|
||||
|
||||
procedure TBuildParseTree.RecogniseVarDecl(aVarType: TVarType=vtNormal);
|
||||
const
|
||||
VariableModifiers: TTokenTypeSet = [ttExternal, ttExport, ttPublic];
|
||||
@ -5443,11 +5432,12 @@ begin
|
||||
exit;
|
||||
end
|
||||
else
|
||||
if IsSymbolOperator(fcTokenList.FirstSolidToken) then begin
|
||||
PushNode(nIdentifier);
|
||||
Recognise(Operators);
|
||||
PopNode;
|
||||
exit;
|
||||
if fcTokenList.FirstSolidTokenType in operators then
|
||||
begin
|
||||
PushNode(nIdentifier);
|
||||
Recognise(Operators);
|
||||
PopNode;
|
||||
exit;
|
||||
end;
|
||||
if not (IdentifierNext(idAllowDirectives)) then
|
||||
RaiseParseError('Expected identifier', fcTokenList.FirstSolidToken);
|
||||
|
@ -314,16 +314,15 @@ type
|
||||
ttGreaterThanOrEqual,
|
||||
ttLessThanOrEqual,
|
||||
ttNotEqual,
|
||||
ttSetSymDif,
|
||||
ttBackSlash, { legal in char literals }
|
||||
|
||||
// FreePascal c-style operators
|
||||
ttPlusAssign, // +=
|
||||
ttMinusAssign, // -=
|
||||
ttTimesAssign, // *=
|
||||
ttFloatDivAssign, // /=
|
||||
ttShl_ll, // <<
|
||||
ttShr_gg // >>
|
||||
ttShr_gg, // >>
|
||||
ttSetSymDif,
|
||||
ttBackSlash { legal in char literals }
|
||||
);
|
||||
|
||||
TTokenTypeSet = set of TTokenType;
|
||||
|
@ -67,6 +67,9 @@ begin
|
||||
if pt = nil then
|
||||
exit;
|
||||
|
||||
if (pt.TokenType in operators) and pt.HasParentNode(nIdentifier,1) then //operator orverloading identifier;
|
||||
Exit(True);
|
||||
|
||||
{ if the next thing is a comment, leave well enough alone }
|
||||
if ptNext.TokenType = ttComment then
|
||||
exit;
|
||||
|
@ -132,12 +132,8 @@ begin
|
||||
|
||||
if (FormattingSettings.Spaces.SpaceForOperator = eNever) then
|
||||
begin
|
||||
if IsSymbolOperator(pt) then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (pt.TokenType in Operators) and (not pt.HasParentNode(nIdentifier,1)) and IsSymbolOperator(pt) then
|
||||
exit(True);
|
||||
end;
|
||||
|
||||
{ '[' of array property definition }
|
||||
|
@ -78,7 +78,10 @@ begin
|
||||
|
||||
Result := False;
|
||||
|
||||
if (pt.TokenType=ttClass) and (pt.NextSolidTokenType in SingleSpaceAfterClass) then
|
||||
if (pt.TokenType in operators) and pt.HasParentNode(nIdentifier,1) then //operator orverloading identifier;
|
||||
Exit(False);
|
||||
|
||||
if (pt.TokenType=ttClass) and (pt.NextSolidTokenType in SingleSpaceAfterClass) then
|
||||
Exit(True);
|
||||
|
||||
if pt.HasParentNode(nLiteralString) then
|
||||
|
@ -81,6 +81,11 @@ begin
|
||||
if pt.HasParentNode(nGeneric, 1) then
|
||||
exit;
|
||||
|
||||
if (pt.TokenType in operators) and pt.HasParentNode(nIdentifier,1) then
|
||||
begin
|
||||
exit(pt.PriorSolidTokenType<>ttDot);
|
||||
end;
|
||||
|
||||
if pt.TokenType = ttCloseBracket then
|
||||
begin
|
||||
if FormattingSettings.Spaces.SpaceBeforeCloseBrackets then
|
||||
@ -147,7 +152,7 @@ begin
|
||||
begin
|
||||
if (pt.TokenType in SingleSpaceOperators) then
|
||||
begin
|
||||
Result := True;
|
||||
Result := not pt.HasParentNode(nIdentifier,1); //can be an overloaded operator identifier.
|
||||
end;
|
||||
|
||||
{ 'a := --3;' and 'lc := ptr^;'
|
||||
@ -158,8 +163,7 @@ begin
|
||||
(IsUnaryOperator(pt) and IsUnaryOperator(pt.PriorSolidToken)) then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
|
||||
Result := not pt.HasParentNode(nIdentifier,1); //can be an overloaded operator identifier.
|
||||
exit;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user