File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -589,6 +589,7 @@ void simplecpp::TokenList::constFold()
589589 constFoldUnaryNotPosNeg (tok);
590590 constFoldMulDivRem (tok);
591591 constFoldAddSub (tok);
592+ constFoldShift (tok);
592593 constFoldComparison (tok);
593594 constFoldBitwise (tok);
594595 constFoldLogicalOp (tok);
@@ -769,6 +770,29 @@ void simplecpp::TokenList::constFoldAddSub(Token *tok)
769770 }
770771}
771772
773+ void simplecpp::TokenList::constFoldShift (Token *tok)
774+ {
775+ for (; tok && tok->op != ' )' ; tok = tok->next ) {
776+ if (!tok->previous || !tok->previous ->number )
777+ continue ;
778+ if (!tok->next || !tok->next ->number )
779+ continue ;
780+
781+ long long result;
782+ if (tok->str == " <<" )
783+ result = stringToLL (tok->previous ->str ) << stringToLL (tok->next ->str );
784+ else if (tok->str == " >>" )
785+ result = stringToLL (tok->previous ->str ) >> stringToLL (tok->next ->str );
786+ else
787+ continue ;
788+
789+ tok = tok->previous ;
790+ tok->setstr (toString (result));
791+ deleteToken (tok->next );
792+ deleteToken (tok->next );
793+ }
794+ }
795+
772796static const std::string NOTEQ (" not_eq" );
773797void simplecpp::TokenList::constFoldComparison (Token *tok)
774798{
Original file line number Diff line number Diff line change @@ -249,6 +249,7 @@ namespace simplecpp {
249249 void constFoldUnaryNotPosNeg (Token *tok);
250250 void constFoldMulDivRem (Token *tok);
251251 void constFoldAddSub (Token *tok);
252+ void constFoldShift (Token *tok);
252253 void constFoldComparison (Token *tok);
253254 void constFoldBitwise (Token *tok);
254255 void constFoldLogicalOp (Token *tok);
You can’t perform that action at this time.
0 commit comments