From 48b149acd49e8872d183eedeababbf852a5ec751 Mon Sep 17 00:00:00 2001 From: maciej-izak Date: Sat, 18 Feb 2017 18:12:45 +0000 Subject: [PATCH] New tokens for new management operators: Initialize, Finalize, AddRef and Copy. Small code adjustment for parser (pdecobj.pas, pstatmnt.pas, psub.pas, ptype.pas) was required because few of old token has from now value which is outside range of set: _CONSTRUCTOR, _FINALIZATION. New tokens for operators: * _OP_INITIALIZE, _OP_FINALIZE, _OP_ADDREF, _OP_COPY New tokens: * _INITIALIZE, _FINALIZE, _ADDREF, _COPY git-svn-id: trunk@35438 - --- compiler/pdecobj.pas | 2 +- compiler/pstatmnt.pas | 4 ++-- compiler/psub.pas | 2 +- compiler/ptype.pas | 2 +- compiler/symtable.pas | 4 ++++ compiler/tokens.pas | 16 ++++++++++++++++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 3316c32b38..bf5748e337 100644 --- a/compiler/pdecobj.pas +++ b/compiler/pdecobj.pas @@ -1060,7 +1060,7 @@ implementation consume(_CLASS); { class modifier is only allowed for procedures, functions, } { constructors, destructors, fields and properties } - if not(token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_CONSTRUCTOR,_DESTRUCTOR]) then + if not((token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_DESTRUCTOR]) or (token=_CONSTRUCTOR)) then Message(parser_e_procedure_or_function_expected); { Java interfaces can contain final class vars } diff --git a/compiler/pstatmnt.pas b/compiler/pstatmnt.pas index 0f3e232b7b..f1f7ea60ce 100644 --- a/compiler/pstatmnt.pas +++ b/compiler/pstatmnt.pas @@ -1355,7 +1355,7 @@ implementation filepos:=current_tokenpos; consume(starttoken); - while not(token in [_END,_FINALIZATION]) do + while not((token=_END) or (token=_FINALIZATION)) do begin if first=nil then begin @@ -1367,7 +1367,7 @@ implementation tstatementnode(last).right:=cstatementnode.create(statement,nil); last:=tstatementnode(last).right; end; - if (token in [_END,_FINALIZATION]) then + if ((token=_END) or (token=_FINALIZATION)) then break else begin diff --git a/compiler/psub.pas b/compiler/psub.pas index d804adeb26..9b0e7d209e 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -2420,7 +2420,7 @@ implementation begin { class modifier is only allowed for procedures, functions, } { constructors, destructors } - if not(token in [_FUNCTION,_PROCEDURE,_CONSTRUCTOR,_DESTRUCTOR,_OPERATOR]) and + if not((token in [_FUNCTION,_PROCEDURE,_DESTRUCTOR,_OPERATOR]) or (token=_CONSTRUCTOR)) and not((token=_ID) and (idtoken=_OPERATOR)) then Message(parser_e_procedure_or_function_expected); diff --git a/compiler/ptype.pas b/compiler/ptype.pas index d9264611d3..3d3087fcd6 100644 --- a/compiler/ptype.pas +++ b/compiler/ptype.pas @@ -859,7 +859,7 @@ implementation { class modifier is only allowed for procedures, functions, } { constructors, destructors, fields and properties } if (hadgeneric and not (token in [_FUNCTION,_PROCEDURE])) or - (not hadgeneric and (not (token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_CONSTRUCTOR,_DESTRUCTOR,_OPERATOR]) and + (not hadgeneric and (not ((token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_DESTRUCTOR,_OPERATOR]) or (token=_CONSTRUCTOR)) and not((token=_ID) and (idtoken=_OPERATOR)))) then Message(parser_e_procedure_or_function_expected); diff --git a/compiler/symtable.pas b/compiler/symtable.pas index 37e80a283b..ad5d9e7107 100644 --- a/compiler/symtable.pas +++ b/compiler/symtable.pas @@ -423,6 +423,10 @@ interface { _ASSIGNMENT } 'assign', { _OP_EXPLICIT } 'explicit', { _OP_ENUMERATOR } 'enumerator', + { _OP_INITIALIZE } 'initialize', + { _OP_FINALIZE } 'finalize', + { _OP_ADDREF } 'addref', + { _OP_COPY } 'copy', { _OP_INC } 'inc', { _OP_DEC } 'dec'); diff --git a/compiler/tokens.pas b/compiler/tokens.pas index 9fa2051304..5ea3b7f21f 100644 --- a/compiler/tokens.pas +++ b/compiler/tokens.pas @@ -56,6 +56,10 @@ type _ASSIGNMENT, _OP_EXPLICIT, _OP_ENUMERATOR, + _OP_INITIALIZE, + _OP_FINALIZE, + _OP_ADDREF, + _OP_COPY, _OP_INC, _OP_DEC, { special chars } @@ -129,6 +133,7 @@ type _VAR, _XOR, _CASE, + _COPY, _CVAR, _ELSE, _EXIT, @@ -164,6 +169,7 @@ type _UNTIL, _WHILE, _WRITE, + _ADDREF, _DISPID, _DIVIDE, _DOWNTO, @@ -222,6 +228,7 @@ type _CPPCLASS, _EXPLICIT, _EXTERNAL, + _FINALIZE, _FUNCTION, _IMPLICIT, _LESSTHAN, @@ -273,6 +280,7 @@ type _DESTRUCTOR, _ENUMERATOR, _IMPLEMENTS, + _INITIALIZE, _INTERNPROC, _LOGICALAND, _LOGICALNOT, @@ -385,6 +393,10 @@ const (str:':=' ;special:true ;keyword:[m_none];op:NOTOKEN), (str:'explicit' ;special:true ;keyword:[m_none];op:NOTOKEN), (str:'enumerator' ;special:true ;keyword:[m_none];op:NOTOKEN), + (str:'initialize' ;special:true ;keyword:[m_none];op:NOTOKEN), + (str:'finalize' ;special:true ;keyword:[m_none];op:NOTOKEN), + (str:'addref' ;special:true ;keyword:[m_none];op:NOTOKEN), + (str:'copy' ;special:true ;keyword:[m_none];op:NOTOKEN), (str:'inc' ;special:true ;keyword:[m_none];op:NOTOKEN), (str:'dec' ;special:true ;keyword:[m_none];op:NOTOKEN), { Special chars } @@ -458,6 +470,7 @@ const (str:'VAR' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), (str:'XOR' ;special:false;keyword:alllanguagemodes;op:_OP_XOR), (str:'CASE' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), + (str:'COPY' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'CVAR' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'ELSE' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), (str:'EXIT' ;special:false;keyword:[m_none];op:NOTOKEN), @@ -493,6 +506,7 @@ const (str:'UNTIL' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), (str:'WHILE' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), (str:'WRITE' ;special:false;keyword:[m_none];op:NOTOKEN), + (str:'ADDREF' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'DISPID' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'DIVIDE' ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name } (str:'DOWNTO' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), @@ -551,6 +565,7 @@ const (str:'CPPCLASS' ;special:false;keyword:[m_fpc];op:NOTOKEN), (str:'EXPLICIT' ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name } (str:'EXTERNAL' ;special:false;keyword:[m_none];op:NOTOKEN), + (str:'FINALIZE' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'FUNCTION' ;special:false;keyword:alllanguagemodes;op:NOTOKEN), (str:'IMPLICIT' ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name } (str:'LESSTHAN' ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name } @@ -602,6 +617,7 @@ const (str:'DESTRUCTOR' ;special:false;keyword:alllanguagemodes-[m_iso,m_extpas];op:NOTOKEN), (str:'ENUMERATOR' ;special:false;keyword:[m_none];op:_OP_ENUMERATOR), (str:'IMPLEMENTS' ;special:false;keyword:[m_none];op:NOTOKEN), + (str:'INITIALIZE' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'INTERNPROC' ;special:false;keyword:[m_none];op:NOTOKEN), (str:'LOGICALAND' ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name } (str:'LOGICALNOT' ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name }