00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ASTYLE_H
00028 #define ASTYLE_H
00029
00030 #ifdef __VMS
00031 #define __USE_STD_IOSTREAM 1
00032 #include <assert>
00033 #else
00034 #include <cassert>
00035 #endif
00036
00037 #include <string.h>
00038 #include <string>
00039 #include <vector>
00040 #include <cctype>
00041
00042 #ifdef _WIN32
00043 #define STDCALL __stdcall
00044 #define EXPORT __declspec(dllexport)
00045 #else
00046 #define STDCALL
00047 #define EXPORT
00048 #endif
00049
00050 #ifdef _MSC_VER
00051 #pragma warning(disable: 4996) // secure version deprecation warnings
00052 #pragma warning(disable: 4267) // 64 bit signed/unsigned loss of data
00053 #endif
00054
00055 #ifdef __BORLANDC__
00056 #pragma warn -aus // variable is assigned a value that is never used in function.
00057 #endif
00058
00059 #ifdef __INTEL_COMPILER
00060 #pragma warning(disable: 383) // value copied to temporary, reference to temporary used
00061 #pragma warning(disable: 444) // destructor for base class is not virtual
00062 #pragma warning(disable: 981) // operands are evaluated in unspecified order
00063 #endif
00064
00065 using namespace std;
00066
00067 namespace astyle
00068 {
00069
00070 enum FileType { C_TYPE=0, JAVA_TYPE=1, SHARP_TYPE=2 };
00071
00072
00073
00074
00075 enum FormatStyle { STYLE_NONE,
00076 STYLE_ALLMAN,
00077 STYLE_JAVA,
00078 STYLE_KandR,
00079 STYLE_STROUSTRUP,
00080 STYLE_WHITESMITH,
00081 STYLE_BANNER,
00082 STYLE_GNU,
00083 STYLE_LINUX,
00084 STYLE_HORSTMANN,
00085 STYLE_1TBS
00086 };
00087
00088 enum BracketMode { NONE_MODE,
00089 ATTACH_MODE,
00090 BREAK_MODE,
00091 LINUX_MODE,
00092 STROUSTRUP_MODE,
00093 HORSTMANN_MODE,
00094 BDAC_MODE = LINUX_MODE
00095 };
00096
00097 enum BracketType { NULL_TYPE = 0,
00098 NAMESPACE_TYPE = 1,
00099 CLASS_TYPE = 2,
00100 STRUCT_TYPE = 4,
00101 INTERFACE_TYPE = 8,
00102 DEFINITION_TYPE = 16,
00103 COMMAND_TYPE = 32,
00104 ARRAY_NIS_TYPE = 64,
00105 ARRAY_TYPE = 128,
00106 EXTERN_TYPE = 256,
00107 SINGLE_LINE_TYPE = 512
00108 };
00109
00110 enum PointerAlign { ALIGN_NONE,
00111 ALIGN_TYPE,
00112 ALIGN_MIDDLE,
00113 ALIGN_NAME
00114 };
00115
00116 enum FileEncoding { ENCODING_OK,
00117 UTF_16BE,
00118 UTF_16LE,
00119 UTF_32BE,
00120 UTF_32LE
00121 };
00122
00123 enum LineEndFormat { LINEEND_DEFAULT,
00124 LINEEND_WINDOWS,
00125 LINEEND_LINUX,
00126 LINEEND_MACOLD,
00127 LINEEND_CRLF = LINEEND_WINDOWS,
00128 LINEEND_LF = LINEEND_LINUX,
00129 LINEEND_CR = LINEEND_MACOLD
00130 };
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 class ASSourceIterator
00142 {
00143 public:
00144 ASSourceIterator() {}
00145 virtual ~ASSourceIterator() {}
00146 virtual bool hasMoreLines() const = 0;
00147 virtual string nextLine(bool emptyLineWasDeleted = false) = 0;
00148 virtual string peekNextLine() = 0;
00149 virtual void peekReset() = 0;
00150 };
00151
00152
00153
00154
00155
00156 class ASResource
00157 {
00158 public:
00159 void buildAssignmentOperators(vector<const string*>* assignmentOperators);
00160 void buildCastOperators(vector<const string*>* castOperators);
00161 void buildHeaders(vector<const string*>* headers, int fileType, bool beautifier=false);
00162 void buildIndentableHeaders(vector<const string*>* indentableHeaders);
00163 void buildNonAssignmentOperators(vector<const string*>* nonAssignmentOperators);
00164 void buildNonParenHeaders(vector<const string*>* nonParenHeaders, int fileType, bool beautifier=false);
00165 void buildOperators(vector<const string*>* operators);
00166 void buildPreBlockStatements(vector<const string*>* preBlockStatements, int fileType);
00167 void buildPreCommandHeaders(vector<const string*>* preCommandHeaders, int fileType);
00168 void buildPreDefinitionHeaders(vector<const string*>* preDefinitionHeaders, int fileType);
00169
00170 public:
00171 static const string AS_IF, AS_ELSE;
00172 static const string AS_DO, AS_WHILE;
00173 static const string AS_FOR;
00174 static const string AS_SWITCH, AS_CASE, AS_DEFAULT;
00175 static const string AS_TRY, AS_CATCH, AS_THROWS, AS_FINALLY;
00176 static const string AS_PUBLIC, AS_PROTECTED, AS_PRIVATE;
00177 static const string AS_CLASS, AS_STRUCT, AS_UNION, AS_INTERFACE, AS_NAMESPACE;
00178 static const string AS_EXTERN, AS_ENUM;
00179 static const string AS_STATIC, AS_CONST, AS_WHERE, AS_NEW;
00180 static const string AS_SYNCHRONIZED;
00181 static const string AS_OPERATOR, AS_TEMPLATE;
00182 static const string AS_OPEN_BRACKET, AS_CLOSE_BRACKET;
00183 static const string AS_OPEN_LINE_COMMENT, AS_OPEN_COMMENT, AS_CLOSE_COMMENT;
00184 static const string AS_BAR_DEFINE, AS_BAR_INCLUDE, AS_BAR_IF, AS_BAR_EL, AS_BAR_ENDIF;
00185 static const string AS_RETURN;
00186 static const string AS_CIN, AS_COUT, AS_CERR;
00187 static const string AS_ASSIGN, AS_PLUS_ASSIGN, AS_MINUS_ASSIGN, AS_MULT_ASSIGN;
00188 static const string AS_DIV_ASSIGN, AS_MOD_ASSIGN, AS_XOR_ASSIGN, AS_OR_ASSIGN, AS_AND_ASSIGN;
00189 static const string AS_GR_GR_ASSIGN, AS_LS_LS_ASSIGN, AS_GR_GR_GR_ASSIGN, AS_LS_LS_LS_ASSIGN;
00190 static const string AS_GCC_MIN_ASSIGN, AS_GCC_MAX_ASSIGN;
00191 static const string AS_EQUAL, AS_PLUS_PLUS, AS_MINUS_MINUS, AS_NOT_EQUAL, AS_GR_EQUAL, AS_GR_GR_GR, AS_GR_GR;
00192 static const string AS_LS_EQUAL, AS_LS_LS_LS, AS_LS_LS;
00193 static const string AS_QUESTION_QUESTION, AS_EQUAL_GR;
00194 static const string AS_ARROW, AS_AND, AS_OR;
00195 static const string AS_COLON_COLON, AS_PAREN_PAREN, AS_BLPAREN_BLPAREN;
00196 static const string AS_PLUS, AS_MINUS, AS_MULT, AS_DIV, AS_MOD, AS_GR, AS_LS;
00197 static const string AS_NOT, AS_BIT_XOR, AS_BIT_OR, AS_BIT_AND, AS_BIT_NOT;
00198 static const string AS_QUESTION, AS_COLON, AS_SEMICOLON, AS_COMMA;
00199 static const string AS_ASM, AS__ASM__, AS_MS_ASM, AS_MS__ASM;
00200 static const string AS_FOREACH, AS_LOCK, AS_UNSAFE, AS_FIXED;
00201 static const string AS_GET, AS_SET, AS_ADD, AS_REMOVE;
00202 static const string AS_DELEGATE, AS_UNCHECKED;
00203 static const string AS_CONST_CAST, AS_DYNAMIC_CAST, AS_REINTERPRET_CAST, AS_STATIC_CAST;
00204 };
00205
00206
00207
00208
00209
00210 class ASBase
00211 {
00212 private:
00213
00214 int baseFileType;
00215
00216 protected:
00217 ASBase() { baseFileType = C_TYPE; }
00218 ~ASBase() {}
00219
00220
00221 bool findKeyword(const string &line, int i, const string &keyword) const;
00222 string getCurrentWord(const string& line, size_t index) const;
00223
00224 protected:
00225
00226 void init(int fileTypeArg) { baseFileType = fileTypeArg; }
00227 bool isCStyle() const { return (baseFileType == C_TYPE); }
00228 bool isJavaStyle() const { return (baseFileType == JAVA_TYPE); }
00229 bool isSharpStyle() const { return (baseFileType == SHARP_TYPE); }
00230
00231
00232 bool isLegalNameChar(char ch) const {
00233 if (isWhiteSpace(ch)) return false;
00234 if ((unsigned) ch > 127) return false;
00235 return (isalnum(ch)
00236 || ch == '.' || ch == '_'
00237 || (isJavaStyle() && ch == '$')
00238 || (isSharpStyle() && ch == '@'));
00239 }
00240
00241
00242 bool isCharPotentialHeader(const string &line, size_t i) const {
00243 assert(!isWhiteSpace(line[i]));
00244 char prevCh = ' ';
00245 if (i > 0) prevCh = line[i-1];
00246 if (!isLegalNameChar(prevCh) && isLegalNameChar(line[i]))
00247 return true;
00248 return false;
00249 }
00250
00251
00252 bool isCharPotentialOperator(char ch) const {
00253 assert(!isWhiteSpace(ch));
00254 if ((unsigned) ch > 127) return false;
00255 return (ispunct(ch)
00256 && ch != '{' && ch != '}'
00257 && ch != '(' && ch != ')'
00258 && ch != '[' && ch != ']'
00259 && ch != ';' && ch != ','
00260 && ch != '#' && ch != '\\'
00261 && ch != '\'' && ch != '\"');
00262 }
00263
00264
00265 bool isWhiteSpace(char ch) const { return (ch == ' ' || ch == '\t'); }
00266
00267
00268 char peekNextChar(const string &line, int i) const {
00269 char ch = ' ';
00270 size_t peekNum = line.find_first_not_of(" \t", i + 1);
00271 if (peekNum == string::npos)
00272 return ch;
00273 ch = line[peekNum];
00274 return ch;
00275 }
00276 };
00277
00278
00279
00280
00281
00282 class ASBeautifier : protected ASResource, protected ASBase
00283 {
00284 public:
00285 ASBeautifier();
00286 virtual ~ASBeautifier();
00287 virtual void init(ASSourceIterator* iter);
00288 void init();
00289 virtual bool hasMoreLines() const;
00290 virtual string nextLine();
00291 virtual string beautify(const string &line);
00292 void deleteVector(vector<const string*>*& container);
00293 void initVector(vector<const string*>*& container);
00294 void setTabIndentation(int length = 4, bool forceTabs = false);
00295 void setSpaceIndentation(int length = 4);
00296 void setMaxInStatementIndentLength(int max);
00297 void setMinConditionalIndentLength(int min);
00298 void setIndentManuallySet(bool state);
00299 void setMinConditionalManuallySet(bool state);
00300 void setModeManuallySet(bool state);
00301 void setClassIndent(bool state);
00302 void setSwitchIndent(bool state);
00303 void setCaseIndent(bool state);
00304 void setBracketIndent(bool state);
00305 void setBlockIndent(bool state);
00306 void setNamespaceIndent(bool state);
00307 void setLabelIndent(bool state);
00308 void setCStyle();
00309 void setJavaStyle();
00310 void setSharpStyle();
00311 void setEmptyLineFill(bool state);
00312 void setPreprocessorIndent(bool state);
00313 int getFileType();
00314 int getIndentLength(void);
00315 string getIndentString(void);
00316 bool getBracketIndent(void);
00317 bool getBlockIndent(void);
00318 bool getCaseIndent(void);
00319 bool getClassIndent(void);
00320 bool getEmptyLineFill(void);
00321 bool getForceTabIndentation(void);
00322 bool getIndentManuallySet(void);
00323 bool getMinConditionalManuallySet(void);
00324 bool getModeManuallySet(void);
00325 bool getSwitchIndent(void);
00326
00327 protected:
00328 void deleteStaticVectors();
00329 const string* findHeader(const string &line, int i,
00330 const vector<const string*>* possibleHeaders) const;
00331 const string* findOperator(const string &line, int i,
00332 const vector<const string*>* possibleOperators) const;
00333 int getNextProgramCharDistance(const string &line, int i) const;
00334 int indexOf(vector<const string*> &container, const string *element);
00335 string trim(const string &str);
00336
00337
00338 int inLineNumber;
00339 int horstmannIndentInStatement;
00340 int nonInStatementBracket;
00341 bool lineCommentNoBeautify;
00342 bool isNonInStatementArray;
00343 bool isSharpAccessor;
00344 bool isSharpDelegate;
00345 bool isInExtern;
00346 bool isInBeautifySQL;
00347 bool isInIndentableStruct;
00348
00349 private:
00350 ASBeautifier(const ASBeautifier ©);
00351 ASBeautifier& operator=(ASBeautifier&);
00352
00353 void initStatic();
00354 void registerInStatementIndent(const string &line, int i, int spaceTabCount,
00355 int tabIncrementIn, int minIndent, bool updateParenStack);
00356 string preLineWS(int spaceTabCount, int tabCount);
00357
00358 static int beautifierFileType;
00359 static vector<const string*>* headers;
00360 static vector<const string*>* nonParenHeaders;
00361 static vector<const string*>* preBlockStatements;
00362 static vector<const string*>* assignmentOperators;
00363 static vector<const string*>* nonAssignmentOperators;
00364 static vector<const string*>* indentableHeaders;
00365
00366 ASSourceIterator *sourceIterator;
00367 vector<ASBeautifier*> *waitingBeautifierStack;
00368 vector<ASBeautifier*> *activeBeautifierStack;
00369 vector<int> *waitingBeautifierStackLengthStack;
00370 vector<int> *activeBeautifierStackLengthStack;
00371 vector<const string*> *headerStack;
00372 vector< vector<const string*>* > *tempStacks;
00373 vector<int> *blockParenDepthStack;
00374 vector<bool> *blockStatementStack;
00375 vector<bool> *parenStatementStack;
00376 vector<bool> *bracketBlockStateStack;
00377 vector<int> *inStatementIndentStack;
00378 vector<int> *inStatementIndentStackSizeStack;
00379 vector<int> *parenIndentStack;
00380 int convertTabToSpaces(int i, int tabIncrementIn) const;
00381 int getInStatementIndentAssign(const string& line, size_t currPos) const;
00382 int getInStatementIndentComma(const string& line, size_t currPos) const;
00383 bool isClassAccessModifier(string& line) const;
00384 bool isLineEndComment(string& line, int startPos) const;
00385 bool statementEndsWithComma(string &line, int index);
00386 vector<vector<const string*>*>* copyTempStacks(const ASBeautifier &other) const;
00387 template<typename T> void deleteContainer(T &container);
00388 void deleteContainer(vector<vector<const string*>*>* &container);
00389 template<typename T> void initContainer(T &container, T value);
00390
00391 private:
00392 string indentString;
00393 const string *currentHeader;
00394 const string *previousLastLineHeader;
00395 const string *probationHeader;
00396 bool isInQuote;
00397 bool isInVerbatimQuote;
00398 bool haveLineContinuationChar;
00399 bool isInAsm;
00400 bool isInAsmOneLine;
00401 bool isInAsmBlock;
00402 bool isInComment;
00403 bool isInHorstmannComment;
00404 bool isInCase;
00405 bool isInQuestion;
00406 bool isInStatement;
00407 bool isInHeader;
00408 bool isInTemplate;
00409 bool isInDefine;
00410 bool isInDefineDefinition;
00411 bool classIndent;
00412 bool isInClassInitializer;
00413 bool isInClassHeaderTab;
00414 bool isInEnum;
00415 bool switchIndent;
00416 bool caseIndent;
00417 bool namespaceIndent;
00418 bool bracketIndent;
00419 bool blockIndent;
00420 bool labelIndent;
00421 bool preprocessorIndent;
00422 bool isInConditional;
00423 bool isIndentManuallySet;
00424 bool isMinConditionalManuallySet;
00425 bool isModeManuallySet;
00426 bool shouldForceTabIndentation;
00427 bool emptyLineFill;
00428 bool backslashEndsPrevLine;
00429 bool lineOpensComment;
00430 bool blockCommentNoIndent;
00431 bool blockCommentNoBeautify;
00432 bool previousLineProbationTab;
00433 int fileType;
00434 int minConditionalIndent;
00435 int parenDepth;
00436 int indentLength;
00437 int blockTabCount;
00438 int maxInStatementIndent;
00439 int classInitializerTabs;
00440 int templateDepth;
00441 int prevFinalLineSpaceTabCount;
00442 int prevFinalLineTabCount;
00443 int defineTabCount;
00444 char quoteChar;
00445 char prevNonSpaceCh;
00446 char currentNonSpaceCh;
00447 char currentNonLegalCh;
00448 char prevNonLegalCh;
00449 };
00450
00451
00452
00453
00454
00455 class ASEnhancer : protected ASBase
00456 {
00457 public:
00458 ASEnhancer();
00459 ~ASEnhancer();
00460 void init(int, int, string, bool, bool);
00461 void enhance(string &line, bool isInSQL);
00462
00463 private:
00464
00465 int indentLength;
00466 bool useTabs;
00467 bool caseIndent;
00468 bool emptyLineFill;
00469
00470
00471 int lineNumber;
00472 bool isInQuote;
00473 bool isInComment;
00474 char quoteChar;
00475
00476
00477 int bracketCount;
00478 int switchDepth;
00479 bool lookingForCaseBracket;
00480 bool unindentNextLine;
00481
00482
00483
00484 struct switchVariables {
00485 int switchBracketCount;
00486 int unindentDepth;
00487 bool unindentCase;
00488 };
00489
00490 switchVariables sw;
00491 vector<switchVariables> swVector;
00492
00493
00494 bool nextLineIsEventIndent;
00495 bool isInEventTable;
00496
00497
00498 bool nextLineIsDeclareIndent;
00499 bool isInDeclareSection;
00500
00501
00502 private:
00503 size_t findCaseColon(string &line, size_t caseIndex) const;
00504 int indentLine(string &line, int indent) const;
00505 bool isBeginDeclareSectionSQL(string &line, size_t index) const;
00506 bool isEndDeclareSectionSQL(string &line, size_t index) const;
00507 size_t processSwitchBlock(string &line, size_t index);
00508 int unindentLine(string &line, int unindent) const;
00509 };
00510
00511
00512
00513
00514
00515 class ASFormatter : public ASBeautifier
00516 {
00517 public:
00518 ASFormatter();
00519 virtual ~ASFormatter();
00520 virtual void init(ASSourceIterator* iter);
00521 virtual bool hasMoreLines() const;
00522 virtual string nextLine();
00523 LineEndFormat getLineEndFormat() const;
00524 void setFormattingStyle(FormatStyle style);
00525 void setAddBracketsMode(bool state);
00526 void setAddOneLineBracketsMode(bool state);
00527 void setBracketFormatMode(BracketMode mode);
00528 void setBreakClosingHeaderBracketsMode(bool state);
00529 void setBreakBlocksMode(bool state);
00530 void setBreakClosingHeaderBlocksMode(bool state);
00531 void setBreakElseIfsMode(bool state);
00532 void setBreakOneLineBlocksMode(bool state);
00533 void setDeleteEmptyLinesMode(bool state);
00534 void setIndentCol1CommentsMode(bool state);
00535 void setLineEndFormat(LineEndFormat fmt);
00536 void setOperatorPaddingMode(bool mode);
00537 void setParensOutsidePaddingMode(bool mode);
00538 void setParensInsidePaddingMode(bool mode);
00539 void setParensHeaderPaddingMode(bool mode);
00540 void setParensUnPaddingMode(bool state);
00541 void setPointerAlignment(PointerAlign alignment);
00542 void setSingleStatementsMode(bool state);
00543 void setTabSpaceConversionMode(bool state);
00544
00545 private:
00546 void ASformatter(ASFormatter ©);
00547 ASFormatter& operator=(ASFormatter&);
00548 template<typename T> void deleteContainer(T &container);
00549 template<typename T> void initContainer(T &container, T value);
00550 char peekNextChar() const;
00551 BracketType getBracketType();
00552 bool addBracketsToStatement();
00553 bool commentAndHeaderFollows() const;
00554 bool getNextChar();
00555 bool getNextLine(bool emptyLineWasDeleted = false);
00556 bool isBeforeComment() const;
00557 bool isBeforeAnyComment() const;
00558 bool isBeforeAnyLineEndComment(int startPos) const;
00559 bool isBeforeMultipleLineEndComments(int startPos) const;
00560 bool isBracketType(BracketType a, BracketType b) const;
00561 bool isCurrentBracketBroken() const;
00562 bool isDereferenceOrAddressOf() const;
00563 bool isExecSQL(string &line, size_t index) const;
00564 bool isEmptyLine(const string &line) const;
00565 bool isNextWordSharpNonParenHeader(int startChar) const;
00566 bool isNonInStatementArrayBracket() const;
00567 bool isPointerOrReference() const;
00568 bool isPointerOrReferenceCentered() const;
00569 bool isSharpStyleWithParen(const string* header) const;
00570 bool isStructAccessModified(string &firstLine, size_t index) const;
00571 bool isUnaryOperator() const;
00572 bool isInExponent() const;
00573 bool isOneLineBlockReached(string& line, int startChar) const;
00574 bool isNextCharOpeningBracket(int startChar) const;
00575 bool isOkToBreakBlock(BracketType bracketType) const;
00576 int getCurrentLineCommentAdjustment();
00577 int getNextLineCommentAdjustment();
00578 void appendCharInsideComments();
00579 void appendSequence(const string &sequence, bool canBreakLine = true);
00580 void appendSpacePad();
00581 void appendSpaceAfter();
00582 void breakLine();
00583 void buildLanguageVectors();
00584 void checkForFollowingHeader(const string& firstLine);
00585 void convertTabToSpaces();
00586 void deleteContainer(vector<BracketType>* &container);
00587 void formatArrayRunIn();
00588 void formatRunIn();
00589 void goForward(int i);
00590 void initContainer(vector<BracketType>* &container, vector<BracketType>* value);
00591 void initNewLine();
00592 void padOperators(const string *newOperator);
00593 void padParens();
00594 void formatArrayBrackets(BracketType bracketType, bool isOpeningArrayBracket);
00595 void formatClosingBracket(BracketType bracketType);
00596 void formatCommentBody();
00597 void formatCommentOpener();
00598 void formatLineCommentBody();
00599 void formatLineCommentOpener();
00600 void formatOpeningBracket(BracketType bracketType);
00601 void formatQuoteBody();
00602 void formatQuoteOpener();
00603 void formatPointerOrReference();
00604 void formatPointerOrReferenceCast();
00605 void adjustComments();
00606 void isLineBreakBeforeClosingHeader();
00607 void setBreakBlocksVariables();
00608 void fixOptionVariableConflicts();
00609 void processPreprocessor();
00610 void trimContinuationLine();
00611 size_t findNextChar(string& line, char searchChar, int searchStart = 0);
00612 string getPreviousWord(const string& line, int currPos) const;
00613 string peekNextText(const string& firstLine, bool endOnEmptyLine=false) const;
00614
00615 private:
00616 static int formatterFileType;
00617 static vector<const string*>* headers;
00618 static vector<const string*>* nonParenHeaders;
00619 static vector<const string*>* preDefinitionHeaders;
00620 static vector<const string*>* preCommandHeaders;
00621 static vector<const string*>* operators;
00622 static vector<const string*>* assignmentOperators;
00623 static vector<const string*>* castOperators;
00624
00625 ASSourceIterator *sourceIterator;
00626 ASEnhancer *enhancer;
00627
00628 vector<const string*> *preBracketHeaderStack;
00629 vector<BracketType> *bracketTypeStack;
00630 vector<int> *parenStack;
00631 vector<bool> *structStack;
00632 string readyFormattedLine;
00633 string currentLine;
00634 string formattedLine;
00635 const string *currentHeader;
00636 const string *previousOperator;
00637 char currentChar;
00638 char previousChar;
00639 char previousNonWSChar;
00640 char previousCommandChar;
00641 char quoteChar;
00642 int charNum;
00643 int preprocBracketTypeStackSize;
00644 int tabIncrementIn;
00645 int spacePadNum;
00646 int nextLineSpacePadNum;
00647 int templateDepth;
00648 int traceLineNumber;
00649 int horstmannIndentChars;
00650 size_t leadingSpaces;
00651 size_t formattedLineCommentNum;
00652 size_t currentLineFirstBracketNum;
00653 size_t previousReadyFormattedLineLength;
00654 FormatStyle formattingStyle;
00655 BracketMode bracketFormatMode;
00656 BracketType previousBracketType;
00657 PointerAlign pointerAlignment;
00658 LineEndFormat lineEnd;
00659 bool isVirgin;
00660 bool shouldPadOperators;
00661 bool shouldPadParensOutside;
00662 bool shouldPadParensInside;
00663 bool shouldPadHeader;
00664 bool shouldUnPadParens;
00665 bool shouldConvertTabs;
00666 bool shouldIndentCol1Comments;
00667 bool isInLineComment;
00668 bool isInComment;
00669 bool noTrimCommentContinuation;
00670 bool isInPreprocessor;
00671 bool isInTemplate;
00672 bool doesLineStartComment;
00673 bool lineEndsInCommentOnly;
00674 bool lineIsLineCommentOnly;
00675 bool lineIsEmpty;
00676 bool isImmediatelyPostCommentOnly;
00677 bool isImmediatelyPostEmptyLine;
00678 bool isInQuote;
00679 bool isInVerbatimQuote;
00680 bool haveLineContinuationChar;
00681 bool isInQuoteContinuation;
00682 bool isInBlParen;
00683 bool isSpecialChar;
00684 bool isNonParenHeader;
00685 bool foundQuestionMark;
00686 bool foundPreDefinitionHeader;
00687 bool foundNamespaceHeader;
00688 bool foundClassHeader;
00689 bool foundStructHeader;
00690 bool foundInterfaceHeader;
00691 bool foundPreCommandHeader;
00692 bool foundCastOperator;
00693 bool isInLineBreak;
00694 bool endOfCodeReached;
00695 bool lineCommentNoIndent;
00696 bool isInExecSQL;
00697 bool isInAsm;
00698 bool isInAsmOneLine;
00699 bool isInAsmBlock;
00700 bool isLineReady;
00701 bool isPreviousBracketBlockRelated;
00702 bool isInPotentialCalculation;
00703 bool isCharImmediatelyPostComment;
00704 bool isPreviousCharPostComment;
00705 bool isCharImmediatelyPostLineComment;
00706 bool isCharImmediatelyPostOpenBlock;
00707 bool isCharImmediatelyPostCloseBlock;
00708 bool isCharImmediatelyPostTemplate;
00709 bool isCharImmediatelyPostReturn;
00710 bool isCharImmediatelyPostOperator;
00711 bool breakCurrentOneLineBlock;
00712 bool isInHorstmannRunIn;
00713 bool currentLineBeginsWithBracket;
00714 bool shouldBreakOneLineBlocks;
00715 bool shouldReparseCurrentChar;
00716 bool shouldBreakOneLineStatements;
00717 bool shouldBreakClosingHeaderBrackets;
00718 bool shouldBreakElseIfs;
00719 bool shouldAddBrackets;
00720 bool shouldAddOneLineBrackets;
00721 bool shouldDeleteEmptyLines;
00722 bool needHeaderOpeningBracket;
00723 bool shouldBreakLineAtNextChar;
00724 bool passedSemicolon;
00725 bool passedColon;
00726 bool clearNonInStatement;
00727 bool isImmediatelyPostComment;
00728 bool isImmediatelyPostLineComment;
00729 bool isImmediatelyPostEmptyBlock;
00730 bool isImmediatelyPostPreprocessor;
00731 bool isImmediatelyPostReturn;
00732 bool isImmediatelyPostOperator;
00733
00734 bool shouldBreakBlocks;
00735 bool shouldBreakClosingHeaderBlocks;
00736 bool isPrependPostBlockEmptyLineRequested;
00737 bool isAppendPostBlockEmptyLineRequested;
00738
00739 bool prependEmptyLine;
00740 bool appendOpeningBracket;
00741 bool foundClosingHeader;
00742
00743 bool isInHeader;
00744 bool isImmediatelyPostHeader;
00745 bool isInCase;
00746 bool isJavaStaticConstructor;
00747
00748 private:
00749
00750 void appendChar(char ch, bool canBreakLine) {
00751 if (canBreakLine && isInLineBreak)
00752 breakLine();
00753 formattedLine.append(1, ch);
00754 isImmediatelyPostCommentOnly = false;
00755 }
00756
00757
00758 void appendCurrentChar(bool canBreakLine = true) {
00759 appendChar(currentChar, canBreakLine);
00760 }
00761
00762
00763 bool isSequenceReached(const char *sequence) const {
00764 return currentLine.compare(charNum, strlen(sequence), sequence) == 0;
00765 }
00766
00767
00768 const string *findHeader(const vector<const string*>* headers) {
00769 return ASBeautifier::findHeader(currentLine, charNum, headers);
00770 }
00771
00772
00773 const string *findOperator(const vector<const string*>* headers) {
00774 return ASBeautifier::findOperator(currentLine, charNum, headers);
00775 }
00776 };
00777
00778
00779
00780
00781
00782
00783 bool sortOnLength(const string *a, const string *b);
00784 bool sortOnName(const string *a, const string *b);
00785
00786 }
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 typedef void (STDCALL *fpError)(int, char*);
00797 typedef char* (STDCALL *fpAlloc)(unsigned long);
00798 extern "C" EXPORT char* STDCALL AStyleMain(const char*, const char*, fpError, fpAlloc);
00799 extern "C" EXPORT const char* STDCALL AStyleGetVersion (void);
00800
00801
00802 #endif // closes ASTYLE_H