2012-10-02 09:12:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/****************************************************************************
  
						 
					
						
							
								
									
										
										
										
											2009-03-20 14:57:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  
						 
					
						
							
								
									
										
										
										
											2015-01-14 18:07:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  Copyright  ( C )  2015  The  Qt  Company  Ltd .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  Contact :  http : //www.qt.io/licensing
  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								* *  
						 
					
						
							
								
									
										
										
										
											2012-10-02 09:12:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  This  file  is  part  of  Qt  Creator .  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								* *  
						 
					
						
							
								
									
										
										
										
											2012-10-02 09:12:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  Commercial  License  Usage  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  Licensees  holding  valid  commercial  Qt  licenses  may  use  this  file  in  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  accordance  with  the  commercial  license  agreement  provided  with  the  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  Software  or ,  alternatively ,  in  accordance  with  the  terms  contained  in  
						 
					
						
							
								
									
										
										
										
											2015-01-14 18:07:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  a  written  agreement  between  you  and  The  Qt  Company .   For  licensing  terms  and  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  conditions  see  http : //www.qt.io/terms-conditions.  For further information
  
						 
					
						
							
								
									
										
										
										
											2014-10-01 13:21:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  use  the  contact  form  at  http : //www.qt.io/contact-us.
  
						 
					
						
							
								
									
										
										
										
											2008-12-02 14:17:16 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  
						 
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  GNU  Lesser  General  Public  License  Usage  
						 
					
						
							
								
									
										
										
										
											2012-10-02 09:12:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  Alternatively ,  this  file  may  be  used  under  the  terms  of  the  GNU  Lesser  
						 
					
						
							
								
									
										
										
										
											2014-10-01 13:21:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  General  Public  License  version  2.1  or  version  3  as  published  by  the  Free  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  Software  Foundation  and  appearing  in  the  file  LICENSE . LGPLv21  and  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  LICENSE . LGPLv3  included  in  the  packaging  of  this  file .   Please  review  the  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  following  information  to  ensure  the  GNU  Lesser  General  Public  License  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  requirements  will  be  met :  https : //www.gnu.org/licenses/lgpl.html and
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  http : //www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  
						 
					
						
							
								
									
										
										
										
											2012-10-02 09:12:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  
						 
					
						
							
								
									
										
										
										
											2015-01-14 18:07:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  In  addition ,  as  a  special  exception ,  The  Qt  Company  gives  you  certain  additional  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  rights .   These  rights  are  described  in  The  Qt  Company  LGPL  Exception  
						 
					
						
							
								
									
										
										
										
											2010-12-17 16:01:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* *  version  1.1 ,  included  in  the  file  LGPL_EXCEPTION . txt  in  this  package .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* *  
						 
					
						
							
								
									
										
										
										
											2012-10-02 09:12:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Copyright  2005  Roberto  Raggi  < roberto @ kdevelop . org > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Permission  to  use ,  copy ,  modify ,  distribute ,  and  sell  this  software  and  its 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  documentation  for  any  purpose  is  hereby  granted  without  fee ,  provided  that 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  the  above  copyright  notice  appear  in  all  copies  and  that  both  that 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  copyright  notice  and  this  permission  notice  appear  in  supporting 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  documentation . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The  above  copyright  notice  and  this  permission  notice  shall  be  included  in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  all  copies  or  substantial  portions  of  the  Software . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  THE  SOFTWARE  IS  PROVIDED  " AS IS " ,  WITHOUT  WARRANTY  OF  ANY  KIND ,  EXPRESS  OR 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  IMPLIED ,  INCLUDING  BUT  NOT  LIMITED  TO  THE  WARRANTIES  OF  MERCHANTABILITY , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  FITNESS  FOR  A  PARTICULAR  PURPOSE  AND  NONINFRINGEMENT .   IN  NO  EVENT  SHALL  THE 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  KDEVELOP  TEAM  BE  LIABLE  FOR  ANY  CLAIM ,  DAMAGES  OR  OTHER  LIABILITY ,  WHETHER  IN 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  AN  ACTION  OF  CONTRACT ,  TORT  OR  OTHERWISE ,  ARISING  FROM ,  OUT  OF  OR  IN 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  CONNECTION  WITH  THE  SOFTWARE  OR  THE  USE  OR  OTHER  DEALINGS  IN  THE  SOFTWARE . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "pp.h" 
  
						 
					
						
							
								
									
										
										
										
											2009-05-15 16:01:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "pp-cctype.h" 
  
						 
					
						
							
								
									
										
										
										
											2008-12-02 15:08:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-27 18:54:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <cplusplus/Control.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <cplusplus/Lexer.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <cplusplus/Token.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <cplusplus/Literals.h> 
  
						 
					
						
							
								
									
										
										
										
											2009-03-02 19:03:07 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-13 14:37:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <utils/scopedswap.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-08-06 13:42:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <QDebug> 
  
						 
					
						
							
								
									
										
										
										
											2012-02-15 10:42:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <QList> 
  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <QDate> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <QTime> 
  
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <QPair> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-03-27 18:54:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <cctype> 
  
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <list> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <algorithm> 
  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define NO_DEBUG 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef NO_DEBUG 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#   include <iostream> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // NO_DEBUG
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 18:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <deque> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-13 14:37:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								using  namespace  Utils ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								namespace  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								enum  {  
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    MAX_TOKEN_EXPANSION_COUNT  =  5000 , 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-20 21:11:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    MAX_TOKEN_BUFFER_DEPTH  =  16000  // for when macros are using some kind of right-folding, this is the list of "delayed" buffers waiting to be expanded after the current one.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  {  
						 
					
						
							
								
									
										
										
										
											2013-04-16 18:10:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  bool  same ( const  char  * a ,  const  char  * b ,  int  size )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  strncmp ( a ,  b ,  size )  = =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  bool  isQtReservedWord ( const  char  * name ,  int  size )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( size  <  4 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  c  =  name [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( c  = =  ' Q ' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( name [ 1 ]  = =  ' _ ' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name  + =  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            size  - =  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            switch  ( size )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  name [ 2 ]  = =  ' D '  | |  name [ 2 ]  = =  ' Q ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  4 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " SLOT " ,  size )  | |  same ( name ,  " EMIT " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  5 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " SLOTS " ,  size )  | |  same ( name ,  " ENUMS " ,  size ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        | |  same ( name ,  " FLAGS " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  6 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " SIGNAL " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  7 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " SIGNALS " ,  size )  | |  same ( name ,  " FOREACH " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  8 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " PROPERTY " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  9 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " INVOKABLE " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  10 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " INTERFACES " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            case  16 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  same ( name ,  " PRIVATE_PROPERTY " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( c  = =  ' S ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( size  = =  6  & &  same ( name ,  " SIGNAL " ,  size ) )  | |  ( size  = =  4  & &  same ( name ,  " SLOT " ,  size ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( c  = =  ' s ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  ( size  = =  7  & &  same ( name ,  " signals " ,  size ) )  | |  ( size  = =  5  & &  same ( name ,  " slots " ,  size ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( c  = =  ' f ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  size  = =  7  & &  same ( name ,  " foreach " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( c  = =  ' e ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  size  = =  4  & &  same ( name ,  " emit " ,  size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-02-03 09:10:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  void  nestingTooDeep ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef NO_DEBUG 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        std : : cerr  < <  " *** WARNING #if / #ifdef nesting exceeded the max level  "  < <  MAX_LEVEL  < <  std : : endl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2013-04-16 18:10:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  // anonymous namespace
  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:41:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								namespace  CPlusPlus  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								namespace  Internal  {  
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/// Buffers tokens for the Preprocessor::lex() to read next. Do not use  this
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// class directly, but use Preprocessor::State::pushTokenBuffer .
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								///
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// New tokens are added when undoing look-ahead, or after expanding a macro.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// When macro expansion happened, the macro is passed in, and blocked until
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// all tokens generated by it (and by subsequent expansion of those generated
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// tokens) are read from the buffer. See Preprocessor::lex() for details on
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// exactly when the buffer (and subsequently a blocking macro) is removed.
  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  TokenBuffer  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-04-18 18:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    std : : deque < PPToken >  tokens ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  Macro  * macro ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    TokenBuffer  * next ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    TokenBuffer ( const  PPToken  * start ,  const  PPToken  * end ,  const  Macro  * macro ,  TokenBuffer  * next ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        :  tokens ( start ,  end ) ,  macro ( macro ) ,  next ( next ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    bool  isBlocked ( const  Macro  * macro )  const  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! macro ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        for  ( const  TokenBuffer  * it  =  this ;  it ;  it  =  it - > next ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( it - > macro ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( it - > macro  = =  macro  | |  ( it - > macro - > name ( )  = =  macro - > name ( ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:41:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  Value  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    enum  Kind  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Kind_Long , 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-27 21:47:03 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Kind_ULong 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:41:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Kind  kind ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    union  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        long  l ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unsigned  long  ul ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Value ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        :  kind ( Kind_Long ) ,  l ( 0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  bool  is_ulong  ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  return  kind  = =  Kind_ULong ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  void  set_ulong  ( unsigned  long  v ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ul  =  v ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        kind  =  Kind_ULong ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  void  set_long  ( long  v ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        l  =  v ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        kind  =  Kind_Long ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  bool  is_zero  ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  return  l  = =  0 ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define PP_DEFINE_BIN_OP(name, op) \ 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  Value  operator  op ( const  Value  & other )  const  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Value  v  =  * this ;  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( v . is_ulong  ( )  | |  other . is_ulong  ( ) )  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            v . set_ulong  ( v . ul  op  other . ul ) ;  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            v . set_long  ( v . l  op  other . l ) ;  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  v ;  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_add ,  + ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_sub ,  - ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_mult ,  * ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_div ,  / ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_mod ,  % ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_lhs ,  < < ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_rhs ,  > > ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_lt ,  < ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_gt ,  > ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_le ,  < = ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_ge ,  > = ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_eq ,  = = ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_ne ,  ! = ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_bit_and ,  & ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_bit_or ,  | ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_bit_xor ,  ^ ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_and ,  & & ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PP_DEFINE_BIN_OP ( op_or ,  | | ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# undef PP_DEFINE_BIN_OP 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  // namespace Internal
  
						 
					
						
							
								
									
										
										
										
											2011-02-04 09:52:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  // namespace CPlusPlus
  
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:41:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								using  namespace  CPlusPlus ;  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								using  namespace  CPlusPlus : : Internal ;  
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:41:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								namespace  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								inline  bool  isContinuationToken ( const  PPToken  & tk )  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  tk . isNot ( T_EOF_SYMBOL )  & &  ( !  tk . newline ( )  | |  tk . joined ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Macro  * macroDefinition ( const  ByteArrayRef  & name ,  
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                       unsigned  bytesOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                       unsigned  utf16charsOffset , 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                       unsigned  line , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                       Environment  * env , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                       Client  * client ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-09-25 16:00:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Macro  * m  =  env - > resolve ( name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( client )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            client - > passedMacroDefinitionCheck ( bytesOffset ,  utf16charsOffset ,  line ,  * m ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-09-25 16:00:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        else 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            client - > failedMacroDefinitionCheck ( bytesOffset ,  utf16charsOffset ,  name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-09-25 16:00:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-12 15:24:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  m ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-09-25 16:00:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								class  RangeLexer  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  Token  * first ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  Token  * last ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Token  trivial ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  RangeLexer ( const  Token  * first ,  const  Token  * last ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        :  first ( first ) ,  last ( last ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // WARN: `last' must be a valid iterator.
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        trivial . byteOffset  =  last - > byteOffset ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        trivial . utf16charOffset  =  last - > utf16charOffset ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-02 13:23:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    inline  explicit  operator  bool ( )  const 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    {  return  first  ! =  last ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  bool  isValid ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  return  first  ! =  last ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  int  size ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  return  std : : distance ( first ,  last ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  const  Token  * dot ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  return  first ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  const  Token  & operator * ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( first  ! =  last ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  * first ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  trivial ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  const  Token  * operator - > ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( first  ! =  last ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  first ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  & trivial ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  RangeLexer  & operator + + ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        + + first ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  * this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  ExpressionEvaluator  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ExpressionEvaluator ( const  ExpressionEvaluator  & other ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    void  operator  =  ( const  ExpressionEvaluator  & other ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2009-09-25 16:00:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ExpressionEvaluator ( Client  * client ,  Environment  * env ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        :  client ( client ) ,  env ( env ) ,  _lex ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    {  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Value  operator ( ) ( const  Token  * firstToken ,  const  Token  * lastToken , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                     const  QByteArray  & source ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this - > source  =  source ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  Value  previousValue  =  switchValue ( Value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        RangeLexer  tmp ( firstToken ,  lastToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        RangeLexer  * previousLex  =  _lex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        _lex  =  & tmp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        process_expression ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        _lex  =  previousLex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  switchValue ( previousValue ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								protected :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Value  switchValue ( const  Value  & value ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Value  previousValue  =  _value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        _value  =  value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  previousValue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bool  isTokenDefined ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ( * _lex ) - > isNot ( T_IDENTIFIER ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:28:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  ByteArrayRef  spell  =  tokenSpell ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        if  ( spell . size ( )  ! =  7 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  spell  = =  " defined " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  char  * tokenPosition ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  source . constData ( )  +  ( * _lex ) - > byteOffset ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    int  tokenLength ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  ( * _lex ) - > f . bytes ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:28:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ByteArrayRef  tokenSpell ( )  const 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:28:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  ByteArrayRef ( tokenPosition ( ) ,  tokenLength ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    inline  void  process_expression ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {  process_constant_expression ( ) ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    void  process_primary ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-10 15:44:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ( * _lex ) - > is ( T_NUMERIC_LITERAL ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  char  * spell  =  tokenPosition ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            int  len  =  tokenLength ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            while  ( len )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const  char  ch  =  spell [ len  -  1 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-04-29 12:33:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( !  ( ch  = =  ' u '  | |  ch  = =  ' U '  | |  ch  = =  ' l '  | |  ch  = =  ' L ' ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-04-29 12:33:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                - - len ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-04-29 12:33:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 17:10:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  char  * end  =  spell  +  len ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            char  * vend  =  const_cast < char  * > ( end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _value . set_long ( strtol ( spell ,  & vend ,  0 ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-07 15:24:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // TODO: if (vend != end) error(NaN)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // TODO: binary literals
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // TODO: float literals
 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( isTokenDefined ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ( * _lex ) - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                _value . set_long ( macroDefinition ( tokenSpell ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                                ( * _lex ) - > byteOffset , 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                                ( * _lex ) - > utf16charOffset , 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                                ( * _lex ) - > lineno ,  env ,  client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                ! =  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }  else  if  ( ( * _lex ) - > is ( T_LPAREN ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( ( * _lex ) - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    _value . set_long ( macroDefinition ( tokenSpell ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                                    ( * _lex ) - > byteOffset , 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                                    ( * _lex ) - > utf16charOffset , 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                                    ( * _lex ) - > lineno , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                    env ,  client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    ! =  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    + + ( * _lex ) ; 
							 
						 
					
						
							
								
									
										
										
											
												Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
  # skip ast (excluding paste, astpath, and canv'ast'imer)
  next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
  s = File.read(file)
  next if s.include?('qlalr')
  orig = s.dup
  s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
    res = $&
    if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
      res
    else
      res.gsub!('} else', 'else')
      res.gsub!(/\n +} *\n/m, "\n")
      res.gsub(/ *{$/, '')
    end
  }
  s.gsub!(/ *$/, '')
  File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
											 
										 
										
											2013-01-08 03:32:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    if  ( ( * _lex ) - > is ( T_RPAREN ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                        + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( ( * _lex ) - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _value . set_long ( 0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( ( * _lex ) - > is ( T_MINUS ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            process_primary ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _value . set_long ( -  _value . l ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( ( * _lex ) - > is ( T_PLUS ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            process_primary ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-04-27 09:55:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( ( * _lex ) - > is ( T_TILDE ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            process_primary ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _value . set_long ( ~  _value . l ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( ( * _lex ) - > is ( T_EXCLAIM ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            process_primary ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _value . set_long ( _value . is_zero ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( ( * _lex ) - > is ( T_LPAREN ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            process_expression ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ( * _lex ) - > is ( T_RPAREN ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Value  process_expression_with_operator_precedence ( const  Value  & lhs ,  int  minPrecedence ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Value  result  =  lhs ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        while  ( precedence ( ( * _lex ) - > kind ( ) )  > =  minPrecedence )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  int  oper  =  ( * _lex ) - > kind ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  int  operPrecedence  =  precedence ( oper ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            process_primary ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Value  rhs  =  _value ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            for  ( int  LA_token_kind  =  ( * _lex ) - > kind ( ) ,  LA_precedence  =  precedence ( LA_token_kind ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 17:05:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    LA_precedence  >  operPrecedence  & &  isBinaryOperator ( LA_token_kind ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    LA_token_kind  =  ( * _lex ) - > kind ( ) ,  LA_precedence  =  precedence ( LA_token_kind ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                rhs  =  process_expression_with_operator_precedence ( rhs ,  LA_precedence ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            result  =  evaluate_expression ( oper ,  result ,  rhs ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    void  process_constant_expression ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        process_primary ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        _value  =  process_expression_with_operator_precedence ( _value ,  precedence ( T_PIPE_PIPE ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ( * _lex ) - > is ( T_QUESTION ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  Value  cond  =  _value ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            + + ( * _lex ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            process_constant_expression ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Value  left  =  _value ,  right ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ( * _lex ) - > is ( T_COLON ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                + + ( * _lex ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                process_constant_expression ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                right  =  _value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _value  =  !  cond . is_zero ( )  ?  left  :  right ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								private :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    inline  int  precedence ( int  tokenKind )  const 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        switch  ( tokenKind )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PIPE_PIPE :        return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_AMPER_AMPER :      return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PIPE :             return  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_CARET :            return  3 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_AMPER :            return  4 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_EQUAL_EQUAL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_EXCLAIM_EQUAL :    return  5 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS_EQUAL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER_EQUAL :    return  6 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS_LESS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER_GREATER :  return  7 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PLUS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_MINUS :            return  8 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_STAR : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_SLASH : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PERCENT :          return  9 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    static  inline  bool  isBinaryOperator ( int  tokenKind ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        switch  ( tokenKind )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PIPE_PIPE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_AMPER_AMPER : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PIPE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_CARET : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_AMPER : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_EQUAL_EQUAL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_EXCLAIM_EQUAL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS_EQUAL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER_EQUAL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS_LESS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER_GREATER : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PLUS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_MINUS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_STAR : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_SLASH : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PERCENT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    static  inline  Value  evaluate_expression ( int  tokenKind ,  const  Value  & lhs ,  const  Value  & rhs ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-28 15:22:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        switch  ( tokenKind )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PIPE_PIPE :        return  lhs  | |  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_AMPER_AMPER :      return  lhs  & &  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PIPE :             return  lhs  |  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_CARET :            return  lhs  ^  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_AMPER :            return  lhs  &  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_EQUAL_EQUAL :      return  lhs  = =  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_EXCLAIM_EQUAL :    return  lhs  ! =  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER :          return  lhs  >  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS :             return  lhs  <  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS_EQUAL :       return  lhs  < =  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER_EQUAL :    return  lhs  > =  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_LESS_LESS :        return  lhs  < <  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_GREATER_GREATER :  return  lhs  > >  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PLUS :             return  lhs  +  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_MINUS :            return  lhs  -  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_STAR :             return  lhs  *  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_SLASH :            return  rhs . is_zero ( )  ?  Value ( )  :  lhs  /  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  T_PERCENT :          return  rhs . is_zero ( )  ?  Value ( )  :  lhs  %  rhs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  Value ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								private :  
						 
					
						
							
								
									
										
										
										
											2009-09-25 16:00:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Client  * client ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    Environment  * env ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    QByteArray  source ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    RangeLexer  * _lex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Value  _value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  // end of anonymous namespace
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Preprocessor : : State : : State ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    :  m_lexer ( 0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  m_skipping ( MAX_LEVEL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  m_trueTest ( MAX_LEVEL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  m_ifLevel ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_tokenBufferDepth ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-21 14:12:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_tokenBuffer ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_inPreprocessorDirective ( false ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_markExpandedTokens ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_noLines ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  m_inCondition ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_bytesOffsetRef ( 0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  m_utf16charsOffsetRef ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-21 14:12:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_result ( 0 ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_lineRef ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_currentExpansion ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_includeGuardState ( IncludeGuardState_BeforeIfndef ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_skipping [ m_ifLevel ]  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_trueTest [ m_ifLevel ]  =  false ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_expansionResult . reserve ( 256 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    setExpansionStatus ( NotExpanding ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# define COMPRESS_TOKEN_BUFFER 
  
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : State : : pushTokenBuffer ( const  PPToken  * start ,  const  PPToken  * end ,  const  Macro  * macro )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_tokenBufferDepth  < =  MAX_TOKEN_BUFFER_DEPTH )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef COMPRESS_TOKEN_BUFFER 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( macro  | |  ! m_tokenBuffer )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // If there is a new blocking macro (or no token buffer yet), create
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // one.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_tokenBuffer  =  new  TokenBuffer ( start ,  end ,  macro ,  m_tokenBuffer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + m_tokenBufferDepth ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // No new blocking macro is passed in, so tokens can be prepended to
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // the existing buffer.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_tokenBuffer - > tokens . insert ( m_tokenBuffer - > tokens . begin ( ) ,  start ,  end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# else 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_tokenBuffer  =  new  TokenBuffer ( start ,  end ,  macro ,  m_tokenBuffer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        + + m_tokenBufferDepth ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : State : : popTokenBuffer ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    TokenBuffer  * r  =  m_tokenBuffer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_tokenBuffer  =  m_tokenBuffer - > next ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    delete  r ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_tokenBufferDepth ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        - - m_tokenBufferDepth ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef DEBUG_INCLUDE_GUARD_TRACKING 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								QString  Preprocessor : : State : : guardStateToString ( int  guardState )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( guardState )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_NoGuard :  return  QLatin1String ( " NoGuard " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_BeforeIfndef :  return  QLatin1String ( " BeforeIfndef " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_AfterIfndef :  return  QLatin1String ( " AfterIfndef " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_AfterDefine :  return  QLatin1String ( " AfterDefine " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_AfterEndif :  return  QLatin1String ( " AfterEndif " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    default :  return  QLatin1String ( " UNKNOWN " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // DEBUG_INCLUDE_GUARD_TRACKING
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ brief  Update  the  include - guard  tracking  state . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Include  guards  are  the  # ifdef / # define / # endif  sequence  typically  found  in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  header  files  to  prevent  repeated  definition  of  the  contents  of  that  header 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  file .  So ,  for  a  file  to  have  an  include  guard ,  it  must  look  like  this : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  \ code 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  # ifndef  SOME_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  . . .  all  declarations / definitions / etc .  go  here  . . . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  # endif 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  \ endcode 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SOME_ID  is  an  identifier ,  and  is  also  the  include  guard .  The  only  tokens 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  allowed  before  the  # ifndef  and  after  the  # endif  are  comments  ( in  any  form ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  or  # line  directives .  The  only  other  requirement  is  that  a  # define  SOME_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  occurs  inside  the  # ifndef  block ,  but  not  nested  inside  other 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  # if / # ifdef / # ifndef  blocks . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-07 13:34:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  This  function  tracks  the  state ,  and  is  called  from  \ c  updateIncludeGuardState 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  which  handles  the  most  common  no - op  cases . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ param  hint  indicates  what  kind  of  token  is  encountered  in  the  input 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ param  idToken  the  identifier  token  that  ought  to  be  in  the  input 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *         after  a  # ifndef  or  a  # define  . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : State : : updateIncludeGuardState_helper ( IncludeGuardStateHint  hint ,  PPToken  * idToken )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef DEBUG_INCLUDE_GUARD_TRACKING 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    int  oldIncludeGuardState  =  m_includeGuardState ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    QByteArray  oldIncludeGuardMacroName  =  m_includeGuardMacroName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // DEBUG_INCLUDE_GUARD_TRACKING
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( m_includeGuardState )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_NoGuard : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_BeforeIfndef : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( hint  = =  IncludeGuardStateHint_Ifndef 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  idToken  & &  idToken - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_includeGuardMacroName  =  idToken - > asByteArrayRef ( ) . toByteArray ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_includeGuardState  =  IncludeGuardState_AfterIfndef ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_includeGuardState  =  IncludeGuardState_NoGuard ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_AfterIfndef : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( hint  = =  IncludeGuardStateHint_Define 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  idToken  & &  idToken - > is ( T_IDENTIFIER ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  idToken - > asByteArrayRef ( )  = =  m_includeGuardMacroName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_includeGuardState  =  IncludeGuardState_AfterDefine ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_AfterDefine : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( hint  = =  IncludeGuardStateHint_Endif ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_includeGuardState  =  IncludeGuardState_AfterEndif ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  IncludeGuardState_AfterEndif : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_includeGuardState  =  IncludeGuardState_NoGuard ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_includeGuardMacroName . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef DEBUG_INCLUDE_GUARD_TRACKING 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    qDebug ( )  < <  " *** "  < <  guardStateToString ( oldIncludeGuardState ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             < <  " -> "  < <  guardStateToString ( m_includeGuardState ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             < <  " hint: "  < <  hint 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             < <  " guard: "  < <  oldIncludeGuardMacroName  < <  " -> "  < <  m_includeGuardMacroName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // DEBUG_INCLUDE_GUARD_TRACKING
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-11-28 09:52:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  QString  Preprocessor : : configurationFileName  =  QLatin1String ( " <configuration> " ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Preprocessor : : Preprocessor ( Client  * client ,  Environment  * env )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    :  m_client ( client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ,  m_env ( env ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_expandFunctionlikeMacros ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ,  m_keepComments ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 10:35:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								QByteArray  Preprocessor : : run ( const  QString  & fileName ,  const  QString  & source )  
						 
					
						
							
								
									
										
										
										
											2009-06-15 15:38:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2013-12-12 21:36:01 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  run ( fileName ,  source . toUtf8 ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-06-15 15:38:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 10:35:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								QByteArray  Preprocessor : : run ( const  QString  & fileName ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                             const  QByteArray  & source , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                             bool  noLines , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                             bool  markGeneratedTokens ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 11:30:43 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_scratchBuffer . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  preprocessed ,  includeGuardMacroName ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-03-05 09:56:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    preprocessed . reserve ( source . size ( )  *  2 ) ;  // multiply by 2 because we insert #gen lines.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    preprocess ( fileName ,  source ,  & preprocessed ,  & includeGuardMacroName ,  noLines , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								               markGeneratedTokens ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! includeGuardMacroName . isEmpty ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_client - > markAsIncludeGuard ( includeGuardMacroName ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 11:30:43 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  preprocessed ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Preprocessor : : expandFunctionlikeMacros ( )  const  
						 
					
						
							
								
									
										
										
										
											2009-07-04 20:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  m_expandFunctionlikeMacros ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-04 20:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : setExpandFunctionlikeMacros ( bool  expandMacros )  
						 
					
						
							
								
									
										
										
										
											2009-07-04 20:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_expandFunctionlikeMacros  =  expandMacros ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-04 20:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-08-23 14:05:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Preprocessor : : keepComments ( )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  m_keepComments ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-23 14:05:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : setKeepComments ( bool  keepComments )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_keepComments  =  keepComments ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-23 14:05:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : generateOutputLineMarker ( unsigned  lineno )  
						 
					
						
							
								
									
										
										
										
											2012-03-30 13:01:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    maybeStartOutputLine ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  & marker  =  currentOutputBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    marker . append ( " #  " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    marker . append ( QByteArray : : number ( lineno ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    marker . append ( "   \" " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    marker . append ( m_env - > currentFileUtf8 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    marker . append ( " \" \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 13:01:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleDefined ( PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-04-19 17:30:03 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ScopedBoolSwap  s ( m_state . m_inPreprocessorDirective ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  lineno  =  tk - > lineno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "defined" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bool  lparenSeen  =  tk - > is ( T_LPAREN ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( lparenSeen ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( tk ) ;  // consume "(" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( tk - > isNot ( T_IDENTIFIER ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //### TODO: generate error message
 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  idToken  =  * tk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > isNot ( T_POUND_POUND ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > is ( T_IDENTIFIER ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            idToken  =  generateConcatenated ( idToken ,  * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  while  ( isContinuationToken ( * tk ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-24 18:50:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 14:33:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( lparenSeen  & &  tk - > is ( T_RPAREN ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    pushToken ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  result ( 1 ,  ' 0 ' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-22 21:34:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  ByteArrayRef  macroName  =  idToken . asByteArrayRef ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( macroDefinition ( macroName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        idToken . byteOffset  +  m_state . m_bytesOffsetRef , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        idToken . utf16charOffset  +  m_state . m_utf16charsOffsetRef , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-22 21:34:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        idToken . lineno ,  m_env ,  m_client ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        result [ 0 ]  =  ' 1 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-22 21:34:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 11:34:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    * tk  =  generateToken ( T_NUMERIC_LITERAL ,  result . constData ( ) ,  result . size ( ) ,  lineno ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : pushToken ( Preprocessor : : PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  PPToken  currentTokenBuffer [ ]  =  {  * tk  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . pushTokenBuffer ( currentTokenBuffer ,  currentTokenBuffer  +  1 ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : lex ( PPToken  * tk )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2014-08-28 14:56:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								again :  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_state . m_tokenBuffer )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // There is a token buffer, so read from there.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( m_state . m_tokenBuffer - > tokens . empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // The token buffer is empty, so pop it, and start over.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_state . popTokenBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-28 14:56:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            goto  again ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        * tk  =  m_state . m_tokenBuffer - > tokens . front ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_tokenBuffer - > tokens . pop_front ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // The token buffer might now be empty. We leave it in, because the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // token we just read might expand into new tokens, or might be a call
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // to the macro that generated this token. In either case, the macro
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // that generated the token still needs to be blocked (!), which is
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // recorded in the token buffer. Removing the blocked macro and the
 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-07 13:34:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // empty token buffer happens the next time that this function is called.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 10:35:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // No token buffer, so have the lexer scan the next token.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        tk - > setSource ( m_state . m_source ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_lexer - > scan ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Adjust token's line number in order to take into account the environment reference.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tk - > lineno  + =  m_state . m_lineRef  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-08-28 14:56:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								reclassify :  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( !  m_state . m_inPreprocessorDirective )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > newline ( )  & &  tk - > is ( T_POUND ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            handlePreprocessorDirective ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-28 14:56:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            goto  reclassify ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( tk - > newline ( )  & &  skipping ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ScopedBoolSwap  s ( m_state . m_inPreprocessorDirective ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  while  ( isContinuationToken ( * tk ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-28 14:56:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            goto  reclassify ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( tk - > is ( T_IDENTIFIER )  & &  ! isQtReservedWord ( tk - > tokenStart ( ) ,  tk - > bytes ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_state . updateIncludeGuardState ( State : : IncludeGuardStateHint_OtherToken ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 12:37:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( m_state . m_inCondition  & &  tk - > asByteArrayRef ( )  = =  " defined " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                handleDefined ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 12:37:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                synchronizeOutputLines ( * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( handleIdentifier ( tk ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-08-28 14:56:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    goto  again ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 12:37:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( tk - > isNot ( T_COMMENT )  & &  tk - > isNot ( T_EOF_SYMBOL ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . updateIncludeGuardState ( State : : IncludeGuardStateHint_OtherToken ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:27:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : skipPreprocesorDirective ( PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2012-03-16 15:16:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ScopedBoolSwap  s ( m_state . m_inPreprocessorDirective ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    while  ( isContinuationToken ( * tk ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        scanComment ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-16 15:16:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Preprocessor : : handleIdentifier ( PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2009-03-04 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2015-01-02 11:33:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ScopedBoolSwap  s ( m_state . m_inPreprocessorDirective ,  ! tk - > f . expanded ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 10:53:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    static  const  QByteArray  ppLine ( " __LINE__ " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppFile ( " __FILE__ " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppDate ( " __DATE__ " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppTime ( " __TIME__ " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ByteArrayRef  macroNameRef  =  tk - > asByteArrayRef ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( macroNameRef . size ( )  = =  8 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            & &  macroNameRef [ 0 ]  = =  ' _ ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            & &  macroNameRef [ 1 ]  = =  ' _ ' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        PPToken  newTk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( macroNameRef  = =  ppLine )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 15:47:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            QByteArray  txt  =  QByteArray : : number ( tk - > lineno ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 10:53:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            newTk  =  generateToken ( T_STRING_LITERAL ,  txt . constData ( ) ,  txt . size ( ) ,  tk - > lineno ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( macroNameRef  = =  ppFile )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 15:47:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            QByteArray  txt ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 10:53:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            txt . append ( ' " ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            txt . append ( m_env - > currentFileUtf8 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            txt . append ( ' " ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            newTk  =  generateToken ( T_STRING_LITERAL ,  txt . constData ( ) ,  txt . size ( ) ,  tk - > lineno ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( macroNameRef  = =  ppDate )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 15:47:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            QByteArray  txt ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 10:53:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            txt . append ( ' " ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            txt . append ( QDate : : currentDate ( ) . toString ( ) . toUtf8 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            txt . append ( ' " ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            newTk  =  generateToken ( T_STRING_LITERAL ,  txt . constData ( ) ,  txt . size ( ) ,  tk - > lineno ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( macroNameRef  = =  ppTime )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 15:47:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            QByteArray  txt ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 10:53:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            txt . append ( ' " ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            txt . append ( QTime : : currentTime ( ) . toString ( ) . toUtf8 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            txt . append ( ' " ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            newTk  =  generateToken ( T_STRING_LITERAL ,  txt . constData ( ) ,  txt . size ( ) ,  tk - > lineno ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( newTk . hasSource ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 15:47:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            newTk . f . newline  =  tk - > newline ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            newTk . f . whitespace  =  tk - > whitespace ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            * tk  =  newTk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 10:53:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Macro  * macro  =  m_env - > resolve ( macroNameRef ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! macro 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            | |  ( tk - > expanded ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                & &  m_state . m_tokenBuffer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  m_state . m_tokenBuffer - > isBlocked ( macro ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//    qDebug() << "expanding" << macro->name() << "on line" << tk->lineno;
  
						 
					
						
							
								
									
										
										
										
											2010-03-03 14:09:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Keep track the of the macro identifier token.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  idTk  =  * tk ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Expanded tokens which are not generated ones preserve the original line number from
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // their corresponding argument in macro substitution. For expanded tokens which are
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // generated, this information must be taken from somewhere else. What we do is to keep
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // a "reference" line initialize set to the line where expansion happens.
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-20 22:14:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  baseLine  =  idTk . lineno  -  m_state . m_lineRef  +  1 ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QVector < PPToken >  body  =  macro - > definitionTokens ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-03 14:09:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 00:12:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Within nested expansion we might reach a previously added marker token. In this case,
 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // we need to move it from its current possition to outside the nesting.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PPToken  oldMarkerTk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( macro - > isFunctionLike ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-09-11 14:18:24 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! expandFunctionlikeMacros ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // Still expand if this originally started with an object-like macro.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  m_state . m_expansionStatus  ! =  Expanding )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_client - > notifyMacroReference ( m_state . m_bytesOffsetRef  +  idTk . byteOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                           m_state . m_utf16charsOffsetRef  +  idTk . utf16charOffset , 
							 
						 
					
						
							
								
									
										
										
										
											2012-10-11 16:16:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                           idTk . lineno , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                           * macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-09-11 14:18:24 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-06 15:28:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Collect individual tokens that form the macro arguments.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        QVector < QVector < PPToken >  >  allArgTks ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 15:59:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        bool  hasArgs  =  collectActualArguments ( tk ,  & allArgTks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Check whether collecting arguments failed due to a previously added marker
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // that goot nested in a sequence of expansions. If so, store it and try again.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! hasArgs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  ! tk - > hasSource ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  m_state . m_markExpandedTokens 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  ( m_state . m_expansionStatus  = =  Expanding 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    | |  m_state . m_expansionStatus  = =  ReadyForExpansion ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            oldMarkerTk  =  * tk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            hasArgs  =  collectActualArguments ( tk ,  & allArgTks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 15:59:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Check for matching parameter/argument count.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        bool  hasMatchingArgs  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( hasArgs )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  int  expectedArgCount  =  macro - > formals ( ) . size ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-25 17:13:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( macro - > isVariadic ( )  & &  allArgTks . size ( )  = =  expectedArgCount  -  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                allArgTks . push_back ( QVector < PPToken > ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 15:59:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  int  actualArgCount  =  allArgTks . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( expectedArgCount  = =  actualArgCount 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    | |  ( macro - > isVariadic ( )  & &  actualArgCount  >  expectedArgCount  -  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    // Handle '#define foo()' when invoked as 'foo()'
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    | |  ( expectedArgCount  = =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        & &  actualArgCount  = =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        & &  allArgTks . at ( 0 ) . isEmpty ( ) ) )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                hasMatchingArgs  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 15:59:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! hasArgs  | |  ! hasMatchingArgs )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            //### TODO: error message
 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            pushToken ( tk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // If a previous marker was found, make sure to put it back.
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( oldMarkerTk . bytes ( ) ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                pushToken ( & oldMarkerTk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            * tk  =  idTk ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-02 08:46:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-03 14:09:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( m_client  & &  ! idTk . generated ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Bundle each token sequence into a macro argument "reference" for notification.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 14:51:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // Even empty ones, which are not necessarily important on its own, but for the matter
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // of couting their number - such as in foo(,)
 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            QVector < MacroArgumentReference >  argRefs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  ( int  i  =  0 ;  i  <  allArgTks . size ( ) ;  + + i )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const  QVector < PPToken >  & argTks  =  allArgTks . at ( i ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 14:51:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( argTks . isEmpty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    argRefs . push_back ( MacroArgumentReference ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    argRefs . push_back ( MacroArgumentReference ( 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-12 10:49:23 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                  m_state . m_bytesOffsetRef  +  argTks . first ( ) . bytesBegin ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                  argTks . last ( ) . bytesBegin ( )  +  argTks . last ( ) . bytes ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    -  argTks . first ( ) . bytesBegin ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                  m_state . m_utf16charsOffsetRef  +  argTks . first ( ) . utf16charsBegin ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                  argTks . last ( ) . utf16charsBegin ( )  +  argTks . last ( ) . utf16chars ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    -  argTks . first ( ) . utf16charsBegin ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-12 14:51:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_client - > startExpandingMacro ( m_state . m_bytesOffsetRef  +  idTk . byteOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                          m_state . m_utf16charsOffsetRef  +  idTk . utf16charOffset , 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                          idTk . lineno , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                          * macro , 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 12:37:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                          argRefs ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 15:12:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! handleFunctionLikeMacro ( macro ,  body ,  allArgTks ,  baseLine ) )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( m_client  & &  ! idTk . expanded ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_client - > stopExpandingMacro ( idTk . byteOffset ,  * macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  if  ( m_client  & &  ! idTk . generated ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        m_client - > startExpandingMacro ( m_state . m_bytesOffsetRef  +  idTk . byteOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                      m_state . m_utf16charsOffsetRef  +  idTk . utf16charOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                      idTk . lineno ,  * macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-30 14:29:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( body . isEmpty ( ) )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( m_state . m_markExpandedTokens 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  ( m_state . m_expansionStatus  = =  NotExpanding 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    | |  m_state . m_expansionStatus  = =  JustFinishedExpansion ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // This is not the most beautiful approach but it's quite reasonable. What we do here
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // is to create a fake identifier token which is only composed by whitespaces. It's
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // also not marked as expanded so it it can be treated as a regular token.
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  QByteArray  content ( int ( idTk . bytes ( )  +  computeDistance ( idTk ) ) ,  '   ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            PPToken  fakeIdentifier  =  generateToken ( T_IDENTIFIER , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                   content . constData ( ) ,  content . length ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                   idTk . lineno ,  false ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fakeIdentifier . f . whitespace  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fakeIdentifier . f . expanded  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fakeIdentifier . f . generated  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            body . push_back ( fakeIdentifier ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-30 14:29:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // The first body token replaces the macro invocation so its whitespace and
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // newline info is replicated.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        PPToken  & bodyTk  =  body [ 0 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 21:03:40 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        bodyTk . f . whitespace  =  idTk . whitespace ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        bodyTk . f . newline  =  idTk . newline ( ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Expansions are tracked from a "top-level" basis. This means that each expansion
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // section in the output corresponds to a direct use of a macro (either object-like
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // or function-like) in the source code and all its recurring expansions - they are
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // surrounded by two marker tokens, one at the begin and the other at the end.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // For instance, the following code will generate 3 expansions in total, but the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // output will aggregate the tokens in only 2 expansion sections.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //  - The first corresponds to BAR expanding to FOO and then FOO expanding to T o;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //  - The second corresponds to FOO expanding to T o;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // #define FOO(T, o) T o;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // #define BAR(T, o) FOO(T, o)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // BAR(Test, x) FOO(Test, y)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_markExpandedTokens )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( m_state . m_expansionStatus  = =  NotExpanding 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    | |  m_state . m_expansionStatus  = =  JustFinishedExpansion )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                PPToken  marker ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                marker . f . expanded  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                marker . f . bytes  =  idTk . bytes ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                marker . byteOffset  =  idTk . byteOffset ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                marker . lineno  =  idTk . lineno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                body . prepend ( marker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                body . append ( marker ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_state . setExpansionStatus ( ReadyForExpansion ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            }  else  if  ( oldMarkerTk . bytes ( ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                       & &  ( m_state . m_expansionStatus  = =  ReadyForExpansion 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                           | |  m_state . m_expansionStatus  = =  Expanding ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                body . append ( oldMarkerTk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-30 14:29:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 14:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . pushTokenBuffer ( body . begin ( ) ,  body . end ( ) ,  macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-30 14:29:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_client  & &  ! idTk . generated ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        m_client - > stopExpandingMacro ( idTk . byteOffset ,  * macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-30 14:29:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 15:12:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Preprocessor : : handleFunctionLikeMacro ( const  Macro  * macro ,  
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                           QVector < PPToken >  & body , 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                           const  QVector < QVector < PPToken >  >  & actuals , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                           unsigned  baseLine ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QVector < PPToken >  expanded ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 13:03:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    expanded . reserve ( MAX_TOKEN_EXPANSION_COUNT ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  size_t  bodySize  =  body . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( size_t  i  =  0 ;  i  <  bodySize  & &  expanded . size ( )  <  MAX_TOKEN_EXPANSION_COUNT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + i )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        int  expandedSize  =  expanded . size ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-12 09:54:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        PPToken  bodyTk  =  body . at ( int ( i ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( bodyTk . is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  ByteArrayRef  id  =  bodyTk . asByteArrayRef ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  QVector < QByteArray >  & formals  =  macro - > formals ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            int  j  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  ( ;  j  <  formals . size ( )  & &  expanded . size ( )  <  MAX_TOKEN_EXPANSION_COUNT ;  + + j )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( formals [ j ]  = =  id )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 13:03:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    QVector < PPToken >  actualsForThisParam  =  actuals . at ( j ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    unsigned  lineno  =  baseLine ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    // Collect variadic arguments
 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 11:54:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    if  ( id  = =  " __VA_ARGS__ "  | |  ( macro - > isVariadic ( )  & &  j  +  1  = =  formals . size ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        for  ( int  k  =  j  +  1 ;  k  <  actuals . size ( ) ;  + + k )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            actualsForThisParam . append ( generateToken ( T_COMMA ,  " , " ,  1 ,  lineno ,  true ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            actualsForThisParam  + =  actuals . at ( k ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-22 13:11:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 10:41:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    const  int  actualsSize  =  actualsForThisParam . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-12 09:54:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    if  ( i  >  0  & &  body [ int ( i )  -  1 ] . is ( T_POUND ) )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        QByteArray  enclosedString ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        enclosedString . reserve ( 256 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        for  ( int  i  =  0 ;  i  <  actualsSize ;  + + i )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            const  PPToken  & t  =  actualsForThisParam . at ( i ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  ( i  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                lineno  =  t . lineno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            else  if  ( t . whitespace ( ) ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                enclosedString . append ( '   ' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            enclosedString . append ( t . tokenStart ( ) ,  t . bytes ( ) ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        enclosedString . replace ( " \\ " ,  " \\ \\ " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        enclosedString . replace ( " \" " ,  " \\ \" " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        expanded . push_back ( generateToken ( T_STRING_LITERAL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                         enclosedString . constData ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                         enclosedString . size ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                         lineno ,  true ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        for  ( int  k  =  0 ;  k  <  actualsSize ;  + + k )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            // Mark the actual tokens (which are the replaced version of the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            // body's one) as expanded. For the first token we replicate the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            // body's whitespace info.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            PPToken  actual  =  actualsForThisParam . at ( k ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            actual . f . expanded  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  ( k  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                actual . f . whitespace  =  bodyTk . whitespace ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            expanded  + =  actual ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  ( k  = =  actualsSize  -  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                lineno  =  actual . lineno ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 17:06:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    // Get a better (more up-to-date) value for the base line.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    baseLine  =  lineno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    break ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 17:18:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( j  = =  formals . size ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // No formal macro parameter for this identifier in the body.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                bodyTk . f . generated  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                bodyTk . lineno  =  baseLine ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                expanded . push_back ( bodyTk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( bodyTk . isNot ( T_POUND )  & &  bodyTk . isNot ( T_POUND_POUND ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bodyTk . f . generated  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bodyTk . lineno  =  baseLine ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            expanded . push_back ( bodyTk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 09:58:43 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-12 09:54:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( i  >  1  & &  body [ int ( i )  -  1 ] . is ( T_POUND_POUND ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( expandedSize  <  1  | |  expanded . size ( )  = =  expandedSize )  //### TODO: [cpp.concat] placemarkers
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  PPToken  & leftTk  =  expanded [ expandedSize  -  1 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  PPToken  & rightTk  =  expanded [ expandedSize ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            expanded [ expandedSize  -  1 ]  =  generateConcatenated ( leftTk ,  rightTk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            expanded . remove ( expandedSize ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2009-12-09 16:01:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // The "new" body.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    body  =  expanded ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-18 13:03:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    body . squeeze ( ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : trackExpansionCycles ( PPToken  * tk )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_state . m_markExpandedTokens )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Identify a macro expansion section. The format is as follows:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // # expansion begin x,y ~g l:c
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // # expansion end
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // The x and y correspond, respectively, to the offset where the macro invocation happens
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // and the macro name's length. Following that there might be an unlimited number of
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // token marks which are directly mapped to each token that appears in the expansion.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Something like ~g indicates that the following g tokens are all generated. While
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // something like l:c indicates that the following token is expanded but not generated
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // and is positioned on line l and column c. Example:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // #define FOO(X) int f(X = 0)  // line 1
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // FOO(int
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //     a);
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Output would be:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // # expansion begin 8,3 ~3 2:4 3:4 ~3
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // int f(int a = 0)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // # expansion end
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // # 3 filename
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //       ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > expanded ( )  & &  ! tk - > hasSource ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( m_state . m_expansionStatus  = =  ReadyForExpansion )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_state . setExpansionStatus ( Expanding ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_state . m_expansionResult . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                m_state . m_expandedTokensInfo . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }  else  if  ( m_state . m_expansionStatus  = =  Expanding )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_state . setExpansionStatus ( JustFinishedExpansion ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                QByteArray  & buffer  =  currentOutputBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-20 15:44:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                maybeStartOutputLine ( ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // Offset and length of the macro invocation
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-20 15:44:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                char  chunk [ 40 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                qsnprintf ( chunk ,  sizeof ( chunk ) ,  " # expansion begin %d,%d " ,  tk - > byteOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                          tk - > bytes ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                buffer . append ( chunk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // Expanded tokens
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                unsigned  generatedCount  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  ( int  i  =  0 ;  i  <  m_state . m_expandedTokensInfo . size ( ) ;  + + i )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    const  QPair < unsigned ,  unsigned >  & p  =  m_state . m_expandedTokensInfo . at ( i ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ( p . first )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  ( generatedCount )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-20 15:44:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            qsnprintf ( chunk ,  sizeof ( chunk ) ,  "  ~%d " ,  generatedCount ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            buffer . append ( chunk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            generatedCount  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-20 15:44:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        qsnprintf ( chunk ,  sizeof ( chunk ) ,  "  %d:%d " ,  p . first ,  p . second ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        buffer . append ( chunk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        + + generatedCount ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( generatedCount )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-20 15:44:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    qsnprintf ( chunk ,  sizeof ( chunk ) ,  "  ~%d " ,  generatedCount ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    buffer . append ( chunk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                buffer . append ( ' \n ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                buffer . append ( m_state . m_expansionResult ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                maybeStartOutputLine ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                buffer . append ( " # expansion end \n " ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( tk - > expanded ( )  & &  ! tk - > hasSource ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                trackExpansionCycles ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-08-20 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  void  adjustForCommentOrStringNewlines ( unsigned  * currentLine ,  const  PPToken  & tk )  
						 
					
						
							
								
									
										
										
										
											2012-08-07 10:47:38 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2014-02-04 22:23:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( tk . isComment ( )  | |  tk . isStringLiteral ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-07 10:47:38 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ( * currentLine )  + =  tk . asByteArrayRef ( ) . count ( ' \n ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : synchronizeOutputLines ( const  PPToken  & tk ,  bool  forceLine )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_state . m_expansionStatus  ! =  NotExpanding 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            | |  ( ! forceLine  & &  m_env - > currentLine  = =  tk . lineno ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-20 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        adjustForCommentOrStringNewlines ( & m_env - > currentLine ,  tk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( forceLine  | |  m_env - > currentLine  >  tk . lineno  | |  tk . lineno  -  m_env - > currentLine  > =  9 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_noLines )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! m_state . m_markExpandedTokens ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                currentOutputBuffer ( ) . append ( '   ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            generateOutputLineMarker ( tk . lineno ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( unsigned  i  =  m_env - > currentLine ;  i  <  tk . lineno ;  + + i ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            currentOutputBuffer ( ) . append ( ' \n ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_env - > currentLine  =  tk . lineno ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-20 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    adjustForCommentOrStringNewlines ( & m_env - > currentLine ,  tk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								std : : size_t  Preprocessor : : computeDistance ( const  Preprocessor : : PPToken  & tk ,  bool  forceTillLine )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Find previous non-space character or line begin.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * buffer  =  tk . bufferStart ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * tokenBegin  =  tk . tokenStart ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * it  =  tokenBegin  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( ;  it  > =  buffer ;  - - it )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( * it  = =  ' \n ' | |  ( ! pp_isspace ( * it )  & &  ! forceTillLine ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    + + it ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  tokenBegin  -  it ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : enforceSpacing ( const  Preprocessor : : PPToken  & tk ,  bool  forceSpacing )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( tk . whitespace ( )  | |  forceSpacing )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        QByteArray  & buffer  =  currentOutputBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // For expanded tokens we simply add a whitespace, if necessary - the exact amount of
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // whitespaces is irrelevant within an expansion section. For real tokens we must be
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // more specific and get the information from the original source.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk . expanded ( )  & &  ! atStartOfOutputLine ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            buffer . append ( '   ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  std : : size_t  spacing  =  computeDistance ( tk ,  forceSpacing ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  char  * tokenBegin  =  tk . tokenStart ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  char  * it  =  tokenBegin  -  spacing ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Reproduce the content as in the original line.
 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            for  ( ;  it  ! =  tokenBegin ;  + + it ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                buffer . append ( pp_isspace ( * it )  ?  * it  :  '   ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/// invalid pp-tokens are used as markers to force whitespace checks.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : preprocess ( const  QString  & fileName ,  const  QByteArray  & source ,  
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                              QByteArray  * result ,  QByteArray  * includeGuardMacroName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                              bool  noLines , 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                              bool  markGeneratedTokens ,  bool  inCondition , 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                              unsigned  bytesOffsetRef ,  unsigned  utf16charOffsetRef , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                              unsigned  lineRef ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:59:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( source . isEmpty ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-04 11:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 17:06:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ScopedSwap < State >  savedState ( m_state ,  State ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 11:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_currentFileName  =  fileName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_source  =  source ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_lexer  =  new  Lexer ( source . constBegin ( ) ,  source . constEnd ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_lexer - > setScanKeywords ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_lexer - > setScanAngleStringLiteralTokens ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-07 15:24:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_lexer - > setPreprocessorMode ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 11:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_keepComments ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_lexer - > setScanCommentTokens ( true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_result  =  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . setExpansionStatus ( m_state . m_expansionStatus ) ;  // Re-set m_currentExpansion
 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 11:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_noLines  =  noLines ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_markExpandedTokens  =  markGeneratedTokens ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 11:54:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_inCondition  =  inCondition ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_bytesOffsetRef  =  bytesOffsetRef ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_utf16charsOffsetRef  =  utf16charOffsetRef ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_state . m_lineRef  =  lineRef ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:59:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ScopedSwap < QString >  savedFileName ( m_env - > currentFile ,  fileName ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ScopedSwap < QByteArray >  savedUtf8FileName ( m_env - > currentFileUtf8 ,  fileName . toUtf8 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ScopedSwap < unsigned >  savedCurrentLine ( m_env - > currentLine ,  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:59:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 13:01:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! m_state . m_noLines ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        generateOutputLineMarker ( 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-04 11:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  tk ( m_state . m_source ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( & tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-04 11:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Track the start and end of macro expansion cycles.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        trackExpansionCycles ( & tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        bool  macroExpanded  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_expansionStatus  = =  Expanding )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Collect the line and column from the tokens undergoing expansion. Those will
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // be available in the expansion section for further referencing about their real
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // location.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            unsigned  trackedLine  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            unsigned  trackedColumn  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( tk . expanded ( )  & &  ! tk . generated ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                trackedLine  =  tk . lineno ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-12 09:54:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                trackedColumn  =  unsigned ( computeDistance ( tk ,  true ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-04 11:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_state . m_expandedTokensInfo . append ( qMakePair ( trackedLine ,  trackedColumn ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( m_state . m_expansionStatus  = =  JustFinishedExpansion )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_state . setExpansionStatus ( NotExpanding ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            macroExpanded  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-04 11:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:59:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Update environment line information.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        synchronizeOutputLines ( tk ,  macroExpanded ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:56:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Make sure spacing between tokens is handled properly.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        enforceSpacing ( tk ,  macroExpanded ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Finally output the token.
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        currentOutputBuffer ( ) . append ( tk . tokenStart ( ) ,  tk . bytes ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  while  ( tk . isNot ( T_EOF_SYMBOL ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:56:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( includeGuardMacroName )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_includeGuardState  = =  State : : IncludeGuardState_AfterDefine 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                | |  m_state . m_includeGuardState  = =  State : : IncludeGuardState_AfterEndif ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            * includeGuardMacroName  =  m_state . m_includeGuardMacroName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-19 10:25:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    delete  m_state . m_lexer ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-09-17 14:46:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    while  ( m_state . m_tokenBuffer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . popTokenBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:56:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Preprocessor : : scanComment ( Preprocessor : : PPToken  * tk )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! tk - > isComment ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    synchronizeOutputLines ( * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    enforceSpacing ( * tk ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    currentOutputBuffer ( ) . append ( tk - > tokenStart ( ) ,  tk - > bytes ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  Preprocessor : : consumeComments ( PPToken  * tk )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    while  ( scanComment ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  tk - > isNot ( T_EOF_SYMBOL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Preprocessor : : collectActualArguments ( PPToken  * tk ,  QVector < QVector < PPToken >  >  * actuals )  
						 
					
						
							
								
									
										
										
										
											2009-03-03 17:18:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Q_ASSERT ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Q_ASSERT ( actuals ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 17:18:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume the identifier
 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:46:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    bool  lastCommentIsCpp  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    while  ( scanComment ( tk ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /* After C++ comments we need to add a new line
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           e . g . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             # define foo(a, b) int a = b 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             foo  // comment
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             ( x ,  3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           can  result  in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                 // commentint
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             x  =  3 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lastCommentIsCpp  =  tk - > is ( T_CPP_COMMENT )  | |  tk - > is ( T_CPP_DOXY_COMMENT ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-17 17:26:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( lastCommentIsCpp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        maybeStartOutputLine ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-17 17:26:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( tk - > isNot ( T_LPAREN ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //### TODO: error message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:46:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QVector < PPToken >  tokens ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    scanActualArgument ( tk ,  & tokens ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:46:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    actuals - > append ( tokens ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:19:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    while  ( tk - > is ( T_COMMA ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:19:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        QVector < PPToken >  tokens ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        scanActualArgument ( tk ,  & tokens ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        actuals - > append ( tokens ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 16:19:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 15:12:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! tk - > is ( T_RPAREN ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //###TODO: else error message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : scanActualArgument ( PPToken  * tk ,  QVector < PPToken >  * tokens )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Q_ASSERT ( tokens ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    int  count  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    while  ( tk - > isNot ( T_EOF_SYMBOL ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > is ( T_LPAREN ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + count ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( tk - > is ( T_RPAREN ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( !  count ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            - - count ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( !  count  & &  tk - > is ( T_COMMA ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-08-15 16:06:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( m_keepComments 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                & &  ( tk - > is ( T_CPP_COMMENT )  | |  tk - > is ( T_CPP_DOXY_COMMENT ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Even in keep comments mode, we cannot preserve C++ style comments inside the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // expansion. We stick with GCC's approach which is to replace them by C style
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // comments (currently clang just gets rid of them) and transform internals */
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // into *|.
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            QByteArray  text  =  m_state . m_source . mid ( tk - > bytesBegin ( )  +  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                   tk - > bytesEnd ( )  -  tk - > bytesBegin ( )  -  2 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-15 16:06:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  QByteArray  & comment  =  " /* "  +  text . replace ( " */ " ,  " *| " )  +  " */ " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tokens - > append ( generateToken ( T_COMMENT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                         comment . constData ( ) ,  comment . size ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                         tk - > lineno ,  false ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tokens - > append ( * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handlePreprocessorDirective ( PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ScopedBoolSwap  s ( m_state . m_inPreprocessorDirective ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 09:52:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  poundToken  =  * tk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lex ( tk ) ;  // scan the directive
 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-03 09:52:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( tk - > newline ( )  & &  !  tk - > joined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ;  // nothing to do.
 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    static  const  QByteArray  ppDefine ( " define " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppIf ( " if " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppIfDef ( " ifdef " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppIfNDef ( " ifndef " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppEndIf ( " endif " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppElse ( " else " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppUndef ( " undef " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppElif ( " elif " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppInclude ( " include " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppIncludeNext ( " include_next " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    static  const  QByteArray  ppImport ( " import " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //### TODO:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // line
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // error
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // pragma
 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( tk - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  ByteArrayRef  directive  =  tk - > asByteArrayRef ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! skipping ( )  & &  directive  = =  ppDefine )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            handleDefineDirective ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( directive  = =  ppIfNDef )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            handleIfDefDirective ( true ,  tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( directive  = =  ppEndIf )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            handleEndIfDirective ( tk ,  poundToken ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . updateIncludeGuardState ( State : : IncludeGuardStateHint_OtherToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! skipping ( )  & &  directive  = =  ppUndef ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleUndefDirective ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( ! skipping ( )  & &  ( directive  = =  ppInclude 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    | |  directive  = =  ppImport ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleIncludeDirective ( tk ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( ! skipping ( )  & &  directive  = =  ppIncludeNext ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleIncludeDirective ( tk ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( directive  = =  ppIf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleIfDirective ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( directive  = =  ppIfDef ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleIfDefDirective ( false ,  tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( directive  = =  ppElse ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleElseDirective ( tk ,  poundToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( directive  = =  ppElif ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                handleElifDirective ( tk ,  poundToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-08-29 13:21:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    skipPreprocesorDirective ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2009-03-03 09:52:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-03 17:22:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleIncludeDirective ( PPToken  * tk ,  bool  includeNext )  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_lexer - > setScanAngleStringLiteralTokens ( true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "include" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_lexer - > setScanAngleStringLiteralTokens ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-29 17:14:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  unsigned  line  =  tk - > lineno ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  included ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( tk - > is ( T_STRING_LITERAL )  | |  tk - > is ( T_ANGLE_STRING_LITERAL ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        included  =  tk - > asByteArrayRef ( ) . toByteArray ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-29 17:14:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ;  // consume string token
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        included  =  expand ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    included  =  included . trimmed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-30 13:34:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( included . isEmpty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //### TODO: error message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-04 20:12:32 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//    qDebug("include [[%s]]", included.constData());
  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Client : : IncludeType  mode ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-03 17:22:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( includeNext ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        mode  =  Client : : IncludeNext ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  if  ( included . at ( 0 )  = =  ' " ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        mode  =  Client : : IncludeLocal ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  if  ( included . at ( 0 )  = =  ' < ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        mode  =  Client : : IncludeGlobal ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ;  //### TODO: add error message?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-17 13:21:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_client )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        QString  inc  =  QString : : fromUtf8 ( included . constData ( )  +  1 ,  included . size ( )  -  2 ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        m_client - > sourceNeeded ( line ,  inc ,  mode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-17 13:21:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleDefineDirective ( PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  unsigned  defineOffset  =  tk - > byteOffset ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "define" token
 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! consumeComments ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( tk - > isNot ( T_IDENTIFIER ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    Macro  macro ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    macro . setFileName ( m_env - > currentFile ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-02 14:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    macro . setLine ( tk - > lineno ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  macroName  =  tk - > asByteArrayRef ( ) . toByteArray ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    macro . setName ( macroName ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    macro . setBytesOffset ( tk - > byteOffset ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    macro . setUtf16charOffset ( tk - > utf16charOffset ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  idToken ( * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( isContinuationToken ( * tk )  & &  tk - > is ( T_LPAREN )  & &  !  tk - > whitespace ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-22 13:55:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        macro . setFunctionLike ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ;  // skip `('
 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! consumeComments ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        bool  hasIdentifier  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( isContinuationToken ( * tk )  & &  tk - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-16 14:06:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            hasIdentifier  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            macro . addFormal ( tk - > asByteArrayRef ( ) . toByteArray ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! consumeComments ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            while  ( isContinuationToken ( * tk )  & &  tk - > is ( T_COMMA ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( ! consumeComments ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( isContinuationToken ( * tk )  & &  tk - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    macro . addFormal ( tk - > asByteArrayRef ( ) . toByteArray ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    if  ( ! consumeComments ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-16 14:06:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    hasIdentifier  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > is ( T_DOT_DOT_DOT ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-22 13:55:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            macro . setVariadic ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-16 14:06:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! hasIdentifier ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                macro . addFormal ( " __VA_ARGS__ " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            lex ( tk ) ;  // consume elipsis token
 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! consumeComments ( tk ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( isContinuationToken ( * tk )  & &  tk - > is ( T_RPAREN ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            lex ( tk ) ;  // consume ")" token
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_ifLevel  = =  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . updateIncludeGuardState ( State : : IncludeGuardStateHint_Define ,  & idToken ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QVector < PPToken >  bodyTokens ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  previousBytesOffset  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unsigned  previousUtf16charsOffset  =  0 ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  previousLine  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Macro  * macroReference  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    while  ( isContinuationToken ( * tk ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Macro tokens are always marked as expanded. However, only for object-like macros
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // we mark them as generated too. For function-like macros we postpone it until the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // formals are identified in the bodies.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tk - > f . expanded  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! macro . isFunctionLike ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tk - > f . generated  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Identifiers must not be eagerly expanded inside defines, but we should still notify
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // in the case they are macros.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( tk - > is ( T_IDENTIFIER )  & &  m_client )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            macroReference  =  m_env - > resolve ( tk - > asByteArrayRef ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( macroReference )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( ! macroReference - > isFunctionLike ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    m_client - > notifyMacroReference ( tk - > byteOffset ,  tk - > utf16charOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                   tk - > lineno ,  * macroReference ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    macroReference  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 15:27:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 12:37:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( macroReference )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( tk - > is ( T_LPAREN ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                m_client - > notifyMacroReference ( previousBytesOffset ,  previousUtf16charsOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                               previousLine ,  * macroReference ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            macroReference  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 15:27:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        previousBytesOffset  =  tk - > byteOffset ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        previousUtf16charsOffset  =  tk - > utf16charOffset ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        previousLine  =  tk - > lineno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-13 10:37:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! scanComment ( tk ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-09-05 15:16:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            bodyTokens . push_back ( * tk ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-29 15:27:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 18:10:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( isQtReservedWord ( macroName . data ( ) ,  macroName . size ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-22 13:55:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        QByteArray  macroId  =  macro . name ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( macro . isFunctionLike ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            macroId  + =  ' ( ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bool  fst  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-19 15:42:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            foreach  ( const  QByteArray  & formal ,  macro . formals ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-22 13:55:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( !  fst ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    macroId  + =  " ,  " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                fst  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                macroId  + =  formal ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            macroId  + =  ' ) ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        bodyTokens . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        macro . setDefinition ( macroId ,  bodyTokens ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  if  ( ! bodyTokens . isEmpty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        PPToken  & firstBodyToken  =  bodyTokens [ 0 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        int  start  =  firstBodyToken . byteOffset ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        int  len  =  tk - > byteOffset  -  start ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        QByteArray  bodyText  =  firstBodyToken . source ( ) . mid ( start ,  len ) . trimmed ( ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  int  bodySize  =  bodyTokens . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( int  i  =  0 ;  i  <  bodySize ;  + + i )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            PPToken  & t  =  bodyTokens [ i ] ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( t . hasSource ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                t . squeezeSource ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-06 11:50:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        macro . setDefinition ( bodyText ,  bodyTokens ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    macro . setLength ( tk - > byteOffset  -  defineOffset ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_env - > bind ( macro ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//    qDebug() << "adding macro" << macro.name() << "defined at" << macro.fileName() << ":"<<macro.line();
  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_client - > macroAdded ( macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								QByteArray  Preprocessor : : expand ( PPToken  * tk ,  PPToken  * lastConditionToken )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  line  =  tk - > lineno ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  bytesBegin  =  tk - > bytesBegin ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-02 16:06:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  utf16charsBegin  =  tk - > utf16charsBegin ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  lastTk ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    while  ( isContinuationToken ( * tk ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lastTk  =  * tk ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Gather the exact spelling of the content in the source.
 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  condition ( m_state . m_source . mid ( bytesBegin ,  lastTk . bytesBegin ( )  +  lastTk . bytes ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                              -  bytesBegin ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//    qDebug("*** Condition before: [%s]", condition.constData());
  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    result . reserve ( 256 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    preprocess ( m_state . m_currentFileName ,  condition ,  & result ,  0 ,  true ,  false ,  true , 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-02 16:06:26 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								               bytesBegin ,  utf16charsBegin ,  line ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    result . squeeze ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//    qDebug("*** Condition after: [%s]", result.constData());
  
						 
					
						
							
								
									
										
										
										
											2012-05-22 12:27:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( lastConditionToken ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        * lastConditionToken  =  lastTk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  PPToken  Preprocessor : : evalExpression ( PPToken  * tk ,  Value  & result )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    PPToken  lastConditionToken ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  QByteArray  expanded  =  expand ( tk ,  & lastConditionToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Lexer  lexer ( expanded . constData ( ) ,  expanded . constData ( )  +  expanded . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-07 15:24:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lexer . setPreprocessorMode ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    std : : vector < Token >  buf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Token  t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        lexer . scan ( & t ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        buf . push_back ( t ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  while  ( t . isNot ( T_EOF_SYMBOL ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ExpressionEvaluator  eval ( m_client ,  m_env ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    result  =  eval ( & buf [ 0 ] ,  & buf [ buf . size ( )  -  1 ] ,  expanded ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  lastConditionToken ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleIfDirective ( PPToken  * tk )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "if" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Value  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  PPToken  lastExpressionToken  =  evalExpression ( tk ,  result ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-03 09:10:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_state . m_ifLevel  > =  MAX_LEVEL  -  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        nestingTooDeep ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  bool  value  =  ! result . is_zero ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  bool  wasSkipping  =  m_state . m_skipping [ m_state . m_ifLevel ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    + + m_state . m_ifLevel ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_state . m_trueTest [ m_state . m_ifLevel ]  =  value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( wasSkipping )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_skipping [ m_state . m_ifLevel ]  =  wasSkipping ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        bool  startSkipping  =  ! value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_skipping [ m_state . m_ifLevel ]  =  startSkipping ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( startSkipping  & &  m_client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            startSkippingBlocks ( lastExpressionToken ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleElifDirective ( PPToken  * tk ,  const  PPToken  & poundToken )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_state . m_ifLevel  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//        std::cerr << "*** WARNING #elif without #if" << std::endl;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        handleIfDirective ( tk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ;  // consume "elif" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_skipping [ m_state . m_ifLevel  -  1 ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // we keep on skipping because we are nested in a skipped block
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_skipping [ m_state . m_ifLevel ]  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( m_state . m_trueTest [ m_state . m_ifLevel ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! m_state . m_skipping [ m_state . m_ifLevel ] )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 00:12:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                // start skipping because the preceding then-part was not skipped
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_state . m_skipping [ m_state . m_ifLevel ]  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( m_client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    startSkippingBlocks ( poundToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 00:12:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // preceding then-part was skipped, so calculate if we should start
 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // skipping, depending on the condition
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Value  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            evalExpression ( tk ,  result ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bool  startSkipping  =  result . is_zero ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_trueTest [ m_state . m_ifLevel ]  =  ! startSkipping ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_skipping [ m_state . m_ifLevel ]  =  startSkipping ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( m_client  & &  ! startSkipping ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_client - > stopSkippingBlocks ( poundToken . utf16charOffset  -  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleElseDirective ( PPToken  * tk ,  const  PPToken  & poundToken )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "else" token
 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-19 20:06:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_state . m_ifLevel  ! =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_skipping [ m_state . m_ifLevel  -  1 ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // we keep on skipping because we are nested in a skipped block
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_skipping [ m_state . m_ifLevel ]  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bool  wasSkipping  =  m_state . m_skipping [ m_state . m_ifLevel ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bool  startSkipping  =  m_state . m_trueTest [ m_state . m_ifLevel ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_skipping [ m_state . m_ifLevel ]  =  startSkipping ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( m_client  & &  wasSkipping  & &  ! startSkipping ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                m_client - > stopSkippingBlocks ( poundToken . utf16charOffset  -  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            else  if  ( m_client  & &  ! wasSkipping  & &  startSkipping ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                startSkippingBlocks ( poundToken ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef NO_DEBUG 
  
						 
					
						
							
								
									
										
										
										
											2013-07-17 00:01:45 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        std : : cerr  < <  " *** WARNING #else without #if "  < <  std : : endl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // NO_DEBUG
  
						 
					
						
							
								
									
										
										
										
											2013-07-17 00:01:45 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleEndIfDirective ( PPToken  * tk ,  const  PPToken  & poundToken )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( m_state . m_ifLevel  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef NO_DEBUG 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        std : : cerr  < <  " *** WARNING #endif without #if " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! tk - > generated ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            std : : cerr  < <  "  on line  "  < <  tk - > lineno  < <  "  of file  "  < <  m_state . m_currentFileName . toUtf8 ( ) . constData ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        std : : cerr  < <  std : : endl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // NO_DEBUG
  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        bool  wasSkipping  =  m_state . m_skipping [ m_state . m_ifLevel ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_skipping [ m_state . m_ifLevel ]  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_state . m_trueTest [ m_state . m_ifLevel ]  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        - - m_state . m_ifLevel ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_client  & &  wasSkipping  & &  ! m_state . m_skipping [ m_state . m_ifLevel ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_client - > stopSkippingBlocks ( poundToken . utf16charOffset  -  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_state . m_ifLevel  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . updateIncludeGuardState ( State : : IncludeGuardStateHint_Endif ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "endif" token
 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleIfDefDirective ( bool  checkUndefined ,  PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "ifdef" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( tk - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-21 17:08:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( checkUndefined  & &  m_state . m_ifLevel  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . updateIncludeGuardState ( State : : IncludeGuardStateHint_Ifndef ,  tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        bool  value  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  ByteArrayRef  macroName  =  tk - > asByteArrayRef ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( Macro  * macro  =  macroDefinition ( macroName ,  tk - > byteOffset ,  tk - > utf16charOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                           tk - > lineno ,  m_env ,  m_client ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            value  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-12 15:24:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // the macro is a feature constraint(e.g. QT_NO_XXX)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( checkUndefined  & &  macroName . startsWith ( " QT_NO_ " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-11-28 09:52:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( macro - > fileName ( )  = =  configurationFileName )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    // and it' defined in a pro file (e.g. DEFINES += QT_NO_QOBJECT)
 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-12 15:24:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    value  =  false ;  // take the branch
 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-12 15:24:45 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( m_env - > isBuiltinMacro ( macroName ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            value  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( checkUndefined ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            value  =  ! value ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  bool  wasSkipping  =  m_state . m_skipping [ m_state . m_ifLevel ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-02-03 09:10:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( m_state . m_ifLevel  <  MAX_LEVEL  -  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            + + m_state . m_ifLevel ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_trueTest [ m_state . m_ifLevel ]  =  value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_state . m_skipping [ m_state . m_ifLevel ]  =  wasSkipping  ?  wasSkipping  :  ! value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( m_client  & &  ! wasSkipping  & &  ! value ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                startSkippingBlocks ( * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            nestingTooDeep ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ;  // consume the identifier
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef NO_DEBUG 
  
						 
					
						
							
								
									
										
										
										
											2013-07-17 00:01:45 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        std : : cerr  < <  " *** WARNING #ifdef without identifier "  < <  std : : endl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // NO_DEBUG
  
						 
					
						
							
								
									
										
										
										
											2013-07-17 00:01:45 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Preprocessor : : handleUndefDirective ( PPToken  * tk )  
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lex ( tk ) ;  // consume "undef" token
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( tk - > is ( T_IDENTIFIER ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  ByteArrayRef  macroName  =  tk - > asByteArrayRef ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  unsigned  bytesOffset  =  tk - > byteOffset  +  m_state . m_bytesOffsetRef ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  unsigned  utf16charsOffset  =  tk - > utf16charOffset  +  m_state . m_utf16charsOffsetRef ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 23:18:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Track macro use if previously defined
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( m_client )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( const  Macro  * existingMacro  =  m_env - > resolve ( macroName ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                m_client - > notifyMacroReference ( bytesOffset ,  utf16charsOffset , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                               tk - > lineno ,  * existingMacro ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 23:18:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        synchronizeOutputLines ( * tk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Macro  * macro  =  m_env - > remove ( macroName ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 23:18:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( m_client  & &  macro )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            macro - > setBytesOffset ( bytesOffset ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            macro - > setUtf16charOffset ( utf16charsOffset ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            m_client - > macroAdded ( * macro ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 23:18:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        lex ( tk ) ;  // consume macro name
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef NO_DEBUG 
  
						 
					
						
							
								
									
										
										
										
											2013-07-17 00:01:45 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        std : : cerr  < <  " *** WARNING #undef without identifier "  < <  std : : endl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // NO_DEBUG
  
						 
					
						
							
								
									
										
										
										
											2013-07-17 00:01:45 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-02 12:01:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								PPToken  Preprocessor : : generateToken ( enum  Kind  kind ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    const  char  * content ,  int  length , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    unsigned  lineno , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    bool  addQuotes , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    bool  addToControl ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2012-04-22 12:04:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // When the token is a generated token, the column position cannot be
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // reconstructed, but we also have to prevent it from searching the whole
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // scratch buffer. So inserting a newline before the new token will give
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // an indent width of 0 (zero).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_scratchBuffer . append ( ' \n ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  size_t  pos  =  m_scratchBuffer . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( kind  = =  T_STRING_LITERAL  & &  addQuotes ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_scratchBuffer . append ( ' " ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    m_scratchBuffer . append ( content ,  length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( kind  = =  T_STRING_LITERAL  & &  addQuotes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_scratchBuffer . append ( ' " ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        length  + =  2 ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  tk ( m_scratchBuffer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tk . f . kind  =  kind ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_state . m_lexer - > control ( )  & &  addToControl )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( kind  = =  T_STRING_LITERAL ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            tk . string  =  m_state . m_lexer - > control ( ) - > stringLiteral ( m_scratchBuffer . constData ( )  +  pos ,  length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        else  if  ( kind  = =  T_IDENTIFIER ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            tk . identifier  =  m_state . m_lexer - > control ( ) - > identifier ( m_scratchBuffer . constData ( )  +  pos ,  length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        else  if  ( kind  = =  T_NUMERIC_LITERAL ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            tk . number  =  m_state . m_lexer - > control ( ) - > numericLiteral ( m_scratchBuffer . constData ( )  +  pos ,  length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    tk . byteOffset  =  unsigned ( pos ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tk . f . bytes  =  length ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    tk . f . generated  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tk . f . expanded  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tk . lineno  =  lineno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  tk ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								PPToken  Preprocessor : : generateConcatenated ( const  PPToken  & leftTk ,  const  PPToken  & rightTk )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    QByteArray  newText ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 18:41:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    newText . reserve ( leftTk . bytes ( )  +  rightTk . bytes ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    newText . append ( leftTk . tokenStart ( ) ,  leftTk . bytes ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    newText . append ( rightTk . tokenStart ( ) ,  rightTk . bytes ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-27 17:11:16 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    PPToken  result  =  generateToken ( T_IDENTIFIER ,  newText . constData ( ) ,  newText . size ( ) ,  leftTk . lineno ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-13 21:03:40 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    result . f . whitespace  =  leftTk . whitespace ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-27 17:11:16 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : startSkippingBlocks ( const  Preprocessor : : PPToken  & tk )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! m_client ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    unsigned  utf16charIter  =  tk . utf16charsEnd ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * source  =  tk . source ( ) . constData ( )  +  tk . bytesEnd ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * sourceEnd  =  tk . source ( ) . constEnd ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unsigned  char  yychar  =  * source ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( yychar  = =  ' \n ' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            m_client - > startSkippingBlocks ( utf16charIter  +  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-26 15:18:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-09 10:04:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Lexer : : yyinp_utf8 ( source ,  yychar ,  utf16charIter ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  while  ( source  <  sourceEnd ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-06-15 15:38:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  Preprocessor : : atStartOfOutputLine ( )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  QByteArray  * buffer  =  m_state . m_currentExpansion ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  buffer - > isEmpty ( )  | |  buffer - > endsWith ( ' \n ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Preprocessor : : maybeStartOutputLine ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2013-04-16 10:40:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    QByteArray  & buffer  =  currentOutputBuffer ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-05 08:37:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( buffer . isEmpty ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! buffer . endsWith ( ' \n ' ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        buffer . append ( ' \n ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // If previous line ends with \ (possibly followed by whitespace), add another \n
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * start  =  buffer . constData ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  char  * ch  =  start  +  buffer . length ( )  -  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    while  ( ch  >  start  & &  ( * ch  ! =  ' \n ' )  & &  std : : isspace ( * ch ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        - - ch ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( * ch  = =  ' \\ ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-16 11:23:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        buffer . append ( ' \n ' ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												C++: Core changes in preprocessing
Summary of most relevant items:
- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.
- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.
- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.
- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.
- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.
- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.
- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.
- Other small stuff.
This is all in one patch because the fixes are a consequence
of the change in preprocessing control.
Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
											 
										 
										
											2012-06-20 15:22:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}