From: Baptiste L. <gai...@fr...> - 2002-12-27 20:15:08
|
----- Original Message ----- From: "Andre Baresel" <and...@gm...> To: "Baptiste Lepilleur" <gai...@fr...> Sent: Friday, December 27, 2002 8:57 PM Subject: Re: [Cpptool-develop] Progress on InlineTemp > Baptiste Lepilleur wrote: > > >----- Original Message ----- > >From: "Andre Baresel" <and...@gm...> > >To: "CppTool Mailing List" <Cpp...@li...> > >Sent: Friday, December 27, 2002 11:38 AM > >Subject: [Cpptool-develop] Progress on InlineTemp > > > > > > > > > >>There're just two things that are left to be done for the InlineTemp > >>refactoring. > >>Both of them need an improvement in expression parsing I'm currently > >>thinking > >>about. The two things are: > >>- detect assignments to a temporary variable > >> > >> > > > >Yes, we need that. Sven started something like that for the SplitTemp > >refactoring. I'm not sure what the status of the code is though. Give a look > >to SplitTempRefactoring class. > > > Yep, I did this afternoon and found that it does only check the > character the follows the occurence of a > temporary variable. This is for the first ok, but it does not really > work for the future. > imagine the code : "if (temp == 0)" .. in this case we have no > assignment ... > > > > > > > > >>- find out if the initializer expression consists of one or more > >>elements (in case > >> of more elements I need to add braces when inlining the expression) > >> > >> > > > >I don't get what you mean. Do you mean if the variable is initialized by a > >constructor ? > > > nope this will be detected as not allowed at the moment since it > contains an identifier. > However just two examples: > > int tmpTobeInlined = 3; > expr = tmpTobeInlined * 5; > ==> Here we have no problem just replacing the tmpToBeInlined by its > initializer resulting in: > expr = 3 * 5; > > But what about: > int tmpTobeInlined = 3 + 3; > expr = tmpTobeInlined * 5; > ==> Here we have to add braces for the expression "3 + 3" resulting in: > expr = (3 + 3) * 5; > > For that reason I'm currently adding allways braces which doesn't look > very nice for most usecases I believe: > expr = ( 3 ) * 5; > With some Code-Rewriter that knowns about minimal placement of braces > that would be no problem. > > I was just thinking about an heuristic for the decision of placing > braces: > Just check if any c++ operator occures in the blanked text of the > initializer. If it does, I will place braces, if not > I leave it as it is. Ok, I understand the issue better know. What would be need is: 1) Is the initializer expression 'atomic' (it is not a composite of expression) ? 2) Does the expression need to be surrounded by braces when inlined in a given expression? ( x = tmpTobeInlined; does not need braces, but x = tmpTobeInlined * 2 need braces). For now, I suggest letting the user decide if braces should be added. This would be a parameter passed to the apply() method. May be add a simple heuristic for a default value (should add braces if '-' or '+' is found in the expression). Baptiste. > > -- Andre |