* Support for enumerator operator

git-svn-id: trunk@34750 -
This commit is contained in:
michael 2016-10-22 08:25:33 +00:00
parent 1552f34251
commit 7ded54ad96
2 changed files with 10 additions and 8 deletions

View File

@ -866,7 +866,7 @@ type
otGreaterThan, otAssign,otNotEqual,otLessEqualThan,otGreaterEqualThan,otPower, otGreaterThan, otAssign,otNotEqual,otLessEqualThan,otGreaterEqualThan,otPower,
otSymmetricalDifference, otInc, otDec, otMod, otNegative, otPositive, otBitWiseOr, otDiv, otSymmetricalDifference, otInc, otDec, otMod, otNegative, otPositive, otBitWiseOr, otDiv,
otLeftShift, otLogicalOr, otBitwiseAnd, otbitwiseXor,otLogicalAnd,otLogicalNot,otLogicalXor, otLeftShift, otLogicalOr, otBitwiseAnd, otbitwiseXor,otLogicalAnd,otLogicalNot,otLogicalXor,
otRightShift); otRightShift,otEnumerator);
TOperatorTypes = set of TOperatorType; TOperatorTypes = set of TOperatorType;
TPasOperator = class(TPasFunction) TPasOperator = class(TPasFunction)
@ -887,7 +887,7 @@ type
function TypeName: string; override; function TypeName: string; override;
function GetDeclaration (full : boolean) : string; override; function GetDeclaration (full : boolean) : string; override;
Property OperatorType : TOperatorType Read FOperatorType Write FOperatorType; 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; Property TokenBased : Boolean Read FTokenBased Write FTokenBased;
end; end;
@ -1365,13 +1365,13 @@ const
'>',':=','<>','<=','>=','**', '>',':=','<>','<=','>=','**',
'><','Inc','Dec','mod','-','+','Or','div', '><','Inc','Dec','mod','-','+','Or','div',
'shl','or','and','xor','and','not','xor', 'shl','or','and','xor','and','not','xor',
'shr'); 'shr','enumerator');
OperatorNames : Array[TOperatorType] of string OperatorNames : Array[TOperatorType] of string
= ('','implicit','explicit','multiply','add','subtract','divide','lessthan','equal', = ('','implicit','explicit','multiply','add','subtract','divide','lessthan','equal',
'greaterthan','assign','notequal','lessthanorequal','greaterthanorequal','power', 'greaterthan','assign','notequal','lessthanorequal','greaterthanorequal','power',
'symmetricaldifference','inc','dec','modulus','negative','positive','bitwiseor','intdivide', 'symmetricaldifference','inc','dec','modulus','negative','positive','bitwiseor','intdivide',
'leftshift','logicalor','bitwiseand','bitwisexor','logicaland','logicalnot','logicalxor', 'leftshift','logicalor','bitwiseand','bitwisexor','logicaland','logicalnot','logicalxor',
'rightshift'); 'rightshift','enumerator');
AssignKindNames : Array[TAssignKind] of string = (':=','+=','-=','*=','/=' ); AssignKindNames : Array[TAssignKind] of string = (':=','+=','-=','*=','/=' );

View File

@ -1163,24 +1163,26 @@ procedure TTestProcedureFunction.TestOperatorTokens;
Var Var
t : TOperatorType; t : TOperatorType;
s : string;
begin begin
For t:=otMul to High(TOperatorType) do For t:=otMul to High(TOperatorType) do
// No way to distinguish between logical/bitwise or/and/Xor // No way to distinguish between logical/bitwise or/and/Xor
if not (t in [otBitwiseOr,otBitwiseAnd,otBitwiseXor]) then if not (t in [otBitwiseOr,otBitwiseAnd,otBitwiseXor]) then
begin begin
S:=GetEnumName(TypeInfo(TOperatorType),Ord(T));
ResetParser; ResetParser;
if t in UnaryOperators then if t in UnaryOperators then
AddDeclaration(Format('operator %s (a: Integer) : te',[OperatorTokens[t]])) AddDeclaration(Format('operator %s (a: Integer) : te',[OperatorTokens[t]]))
else else
AddDeclaration(Format('operator %s (a: Integer; b: integer) : te',[OperatorTokens[t]])); AddDeclaration(Format('operator %s (a: Integer; b: integer) : te',[OperatorTokens[t]]));
ParseOperator; ParseOperator;
AssertEquals('Token based',Not (T in [otInc,otDec]),FOperator.TokenBased); AssertEquals(S+': Token based ',Not (T in [otInc,otDec,otEnumerator]),FOperator.TokenBased);
AssertEquals('Correct operator type',T,FOperator.OperatorType); AssertEquals(S+': Correct operator type',T,FOperator.OperatorType);
if t in UnaryOperators then 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 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;
end; end;