mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 00:09:25 +02:00
* Support for enumerator operator
git-svn-id: trunk@34750 -
This commit is contained in:
parent
1552f34251
commit
7ded54ad96
@ -866,7 +866,7 @@ type
|
||||
otGreaterThan, otAssign,otNotEqual,otLessEqualThan,otGreaterEqualThan,otPower,
|
||||
otSymmetricalDifference, otInc, otDec, otMod, otNegative, otPositive, otBitWiseOr, otDiv,
|
||||
otLeftShift, otLogicalOr, otBitwiseAnd, otbitwiseXor,otLogicalAnd,otLogicalNot,otLogicalXor,
|
||||
otRightShift);
|
||||
otRightShift,otEnumerator);
|
||||
TOperatorTypes = set of TOperatorType;
|
||||
|
||||
TPasOperator = class(TPasFunction)
|
||||
@ -887,7 +887,7 @@ type
|
||||
function TypeName: string; override;
|
||||
function GetDeclaration (full : boolean) : string; override;
|
||||
Property OperatorType : TOperatorType Read FOperatorType Write FOperatorType;
|
||||
// True if the declaration was using a token instead of a
|
||||
// True if the declaration was using a token instead of an identifier
|
||||
Property TokenBased : Boolean Read FTokenBased Write FTokenBased;
|
||||
end;
|
||||
|
||||
@ -1365,13 +1365,13 @@ const
|
||||
'>',':=','<>','<=','>=','**',
|
||||
'><','Inc','Dec','mod','-','+','Or','div',
|
||||
'shl','or','and','xor','and','not','xor',
|
||||
'shr');
|
||||
'shr','enumerator');
|
||||
OperatorNames : Array[TOperatorType] of string
|
||||
= ('','implicit','explicit','multiply','add','subtract','divide','lessthan','equal',
|
||||
'greaterthan','assign','notequal','lessthanorequal','greaterthanorequal','power',
|
||||
'symmetricaldifference','inc','dec','modulus','negative','positive','bitwiseor','intdivide',
|
||||
'leftshift','logicalor','bitwiseand','bitwisexor','logicaland','logicalnot','logicalxor',
|
||||
'rightshift');
|
||||
'rightshift','enumerator');
|
||||
|
||||
AssignKindNames : Array[TAssignKind] of string = (':=','+=','-=','*=','/=' );
|
||||
|
||||
|
@ -1163,24 +1163,26 @@ procedure TTestProcedureFunction.TestOperatorTokens;
|
||||
|
||||
Var
|
||||
t : TOperatorType;
|
||||
s : string;
|
||||
|
||||
begin
|
||||
For t:=otMul to High(TOperatorType) do
|
||||
// No way to distinguish between logical/bitwise or/and/Xor
|
||||
if not (t in [otBitwiseOr,otBitwiseAnd,otBitwiseXor]) then
|
||||
begin
|
||||
S:=GetEnumName(TypeInfo(TOperatorType),Ord(T));
|
||||
ResetParser;
|
||||
if t in UnaryOperators then
|
||||
AddDeclaration(Format('operator %s (a: Integer) : te',[OperatorTokens[t]]))
|
||||
else
|
||||
AddDeclaration(Format('operator %s (a: Integer; b: integer) : te',[OperatorTokens[t]]));
|
||||
ParseOperator;
|
||||
AssertEquals('Token based',Not (T in [otInc,otDec]),FOperator.TokenBased);
|
||||
AssertEquals('Correct operator type',T,FOperator.OperatorType);
|
||||
AssertEquals(S+': Token based ',Not (T in [otInc,otDec,otEnumerator]),FOperator.TokenBased);
|
||||
AssertEquals(S+': Correct operator type',T,FOperator.OperatorType);
|
||||
if t in UnaryOperators then
|
||||
AssertEquals('Correct operator name',format('%s(Integer):te',[OperatorNames[t]]),FOperator.Name)
|
||||
AssertEquals(S+': Correct operator name',format('%s(Integer):te',[OperatorNames[t]]),FOperator.Name)
|
||||
else
|
||||
AssertEquals('Correct operator name',format('%s(Integer,Integer):te',[OperatorNames[t]]),FOperator.Name);
|
||||
AssertEquals(S+': Correct operator name',format('%s(Integer,Integer):te',[OperatorNames[t]]),FOperator.Name);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user