1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Breaking precedence for binary expressions.

This commit is contained in:
Sergey Prigogin 2011-03-04 17:57:24 +00:00
parent 6ad4ad176a
commit 5bfffca532
3 changed files with 37 additions and 7 deletions

View file

@ -2539,9 +2539,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (isAssignment(node)) { if (isAssignment(node)) {
return formatAssignment(node); return formatAssignment(node);
} }
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
Alignment.BINARY_EXPRESSION, Alignment.BINARY_EXPRESSION,
preferences.alignment_for_binary_expression, preferences.alignment_for_binary_expression,
Alignment.R_OUTERMOST,
2, 2,
scribe.scanner.getCurrentPosition()); scribe.scanner.getCurrentPosition());
@ -2549,12 +2551,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
boolean ok = false; boolean ok = false;
do { do {
try { try {
scribe.alignFragment(expressionAlignment, 0);
final IASTExpression op1= node.getOperand1(); final IASTExpression op1= node.getOperand1();
// operand 1 // Left operand
op1.accept(this); op1.accept(this);
scribe.printTrailingComment(); scribe.printTrailingComment();
scribe.alignFragment(expressionAlignment, 1); scribe.alignFragment(expressionAlignment, 1);
// In case of macros we may have already passed the operator position. // In case of macros we may have already passed the operator position.
@ -2577,7 +2578,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
} }
// operand 2 // Right operand
final IASTExpression op2= node.getOperand2(); final IASTExpression op2= node.getOperand2();
op2.accept(this); op2.accept(this);

View file

@ -46,9 +46,9 @@ void bug183220() {
if (((rtc_hdw_cr_sync_next != rtc_hdw_cr_sync) || rtc_hdw_cr_resync_enable) if (((rtc_hdw_cr_sync_next != rtc_hdw_cr_sync) || rtc_hdw_cr_resync_enable)
&& !rtc_s2000_src_pending && !rtc_s2000_cr_sync_pending) { && !rtc_s2000_src_pending && !rtc_s2000_cr_sync_pending) {
if (!identify_hdw_fvr_master() || !rtc_hdw_current_clock->external if (!identify_hdw_fvr_master() || !rtc_hdw_current_clock->external
|| !rtc_hdw_cr_sync_next || ((rtc_hdw_current_clock->external || !rtc_hdw_cr_sync_next
&& rtc_hdw_cr_sync_next && rtc_s2000_clock_source_state || ((rtc_hdw_current_clock->external && rtc_hdw_cr_sync_next
!= RTC_CLOCK_PLL))) { && rtc_s2000_clock_source_state != RTC_CLOCK_PLL))) {
} }
} }
} }

View file

@ -1870,6 +1870,35 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult(); assertFormatterResult();
} }
//class Stream {
//Stream& operator <<(const char*);
//Stream& operator <<(int);
//};
//
//Stream stream;
//
//void test() {
// // Breaking at << is preferred to breaking at +.
//stream << "text text text text text text text text text" << 1000000 + 2000000;
//}
//class Stream {
// Stream& operator <<(const char*);
// Stream& operator <<(int);
//};
//
//Stream stream;
//
//void test() {
// // Breaking at << is preferred to breaking at +.
// stream << "text text text text text text text text text"
// << 1000000 + 2000000;
//}
public void testBreakingPrecedence() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
assertFormatterResult();
}
//#define m() f() //#define m() f()
//void f() { //void f() {
//if (1) f(); //if (1) f();