CNDEditingAndFormatting
Editing and formatting
Status
- Implemented formatter on new lexer.
- 290 unit formatter/indent tests.
- Supported formatting styles.
- Supported formatting of active and not active code.
Not solved problems:
- Formatter does not take into account macro expansion. If expansion contains key word or not balanced braces or parenthesis the formatting can be wrong.
- Sometimes algorithm of formating #if-#else-#endif blocks is wrong. Need more clever algorithm. At least algorithm should detect dead branches and does not take it into account.
- No reliable algorithm to differ unary/binary operators and binary/separators (+,-,*,&,<,>). Need code model support.
Plans for future improvement
- Persist user defined styles. User view.
- Detect and preserve style of repeated statement. Users like to wrap equality sign and end line comments.
- Use code model abstract syntax tree for more accurate formatting.
Examples
Formatting active and not active code
#ifdef A for (int i = 0; i < 2; i++) { boo(); #else { #endif foo(); }
Dead code (technical comments for editor)
#if 0 ) #endif
Binary or part of type?
a * b;
Repeated statements
int A = 10; // This is an A int A20 = 200; // This is an A20 int A100 = A + A20; // This is an A100
Unbalanced brace in macro
#define FOR(n) for (int i = 0; i < n; i++) { FOR(2); foo(); }
Issuezilla
Status Whiteboard keyword: formatting
(click on the keyword above to get issues list)