00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef ASFORMATTER_H
00025 #define ASFORMATTER_H
00026
00027 #include "ASBeautifier.h"
00028
00029 #include "compiler_defines.h"
00030
00031 namespace astyle {
00032
00033 class ASFormatter : public ASBeautifier
00034 {
00035 public:
00036 ASFormatter();
00037 virtual ~ASFormatter();
00038 virtual void init(ASSourceIterator* iter);
00039 virtual bool hasMoreLines() const;
00040 virtual string nextLine();
00041 void setBracketFormatMode(BracketMode mode);
00042 void setBreakClosingHeaderBracketsMode(bool state);
00043 void setOperatorPaddingMode(bool mode);
00044 void setParenthesisPaddingMode(bool mode);
00045 void setBreakOneLineBlocksMode(bool state);
00046 void setSingleStatementsMode(bool state);
00047 void setTabSpaceConversionMode(bool state);
00048 void setBreakBlocksMode(bool state);
00049 void setBreakClosingHeaderBlocksMode(bool state);
00050 void setBreakElseIfsMode(bool state);
00051
00052 private:
00053 void ASformatter(ASFormatter ©);
00054 void operator=(ASFormatter&);
00055 void staticInit();
00056 bool isFormattingEnabled() const;
00057 void goForward(int i);
00058 bool getNextChar();
00059 char peekNextChar() const;
00060 bool isBeforeComment() const;
00061 void trimNewLine();
00062 BracketType getBracketType() const;
00063 bool isPointerOrReference() const;
00064 bool isUrinaryMinus() const;
00065 bool isInExponent() const;
00066 bool isOneLineBlockReached() const;
00067 void appendChar(char ch, bool canBreakLine = true);
00068 void appendCurrentChar(bool canBreakLine = true);
00069 void appendSequence(const string &sequence, bool canBreakLine = true);
00070 void appendSpacePad();
00071 void breakLine();
00072 inline bool isSequenceReached(const string &sequence) const;
00073 const string *findHeader(const vector<const string*> &headers, bool checkBoundry = true);
00074
00075 static vector<const string*> headers;
00076 static vector<const string*> nonParenHeaders;
00077 static vector<const string*> preprocessorHeaders;
00078 static vector<const string*> preDefinitionHeaders;
00079 static vector<const string*> preCommandHeaders;
00080 static vector<const string*> operators;
00081 static vector<const string*> assignmentOperators;
00082 static bool calledInitStatic;
00083
00084 ASSourceIterator *sourceIterator;
00085 vector<const string*> *preBracketHeaderStack;
00086 vector<BracketType> *bracketTypeStack;
00087 vector<int> *parenStack;
00088 string readyFormattedLine;
00089 string currentLine;
00090 string formattedLine;
00091 const string *currentHeader;
00092 const string *previousOperator;
00093 char currentChar;
00094 char previousChar;
00095 char previousNonWSChar;
00096 char previousCommandChar;
00097 char quoteChar;
00098 unsigned int charNum;
00099 BracketMode bracketFormatMode;
00100 bool isVirgin;
00101 bool shouldPadOperators;
00102 bool shouldPadParenthesies;
00103 bool shouldConvertTabs;
00104 bool isInLineComment;
00105 bool isInComment;
00106 bool isInPreprocessor;
00107 bool isInTemplate;
00108 bool doesLineStartComment;
00109 bool isInQuote;
00110 bool isSpecialChar;
00111 bool isNonParenHeader;
00112 bool foundQuestionMark;
00113 bool foundPreDefinitionHeader;
00114 bool foundPreCommandHeader;
00115 bool isInLineBreak;
00116 bool isInClosingBracketLineBreak;
00117 bool endOfCodeReached;
00118 bool isLineReady;
00119 bool isPreviousBracketBlockRelated;
00120 bool isInPotentialCalculation;
00121
00122 bool shouldBreakOneLineBlocks;
00123 bool shouldReparseCurrentChar;
00124 bool shouldBreakOneLineStatements;
00125 bool shouldBreakLineAfterComments;
00126 bool shouldBreakClosingHeaderBrackets;
00127 bool shouldBreakElseIfs;
00128 bool passedSemicolon;
00129 bool passedColon;
00130 bool isImmediatelyPostComment;
00131 bool isImmediatelyPostLineComment;
00132 bool isImmediatelyPostEmptyBlock;
00133
00134 bool shouldBreakBlocks;
00135 bool shouldBreakClosingHeaderBlocks;
00136 bool isPrependPostBlockEmptyLineRequested;
00137 bool isAppendPostBlockEmptyLineRequested;
00138
00139 bool prependEmptyLine;
00140 bool foundClosingHeader;
00141 int previousReadyFormattedLineLength;
00142
00143 bool isInHeader;
00144 bool isImmediatelyPostHeader;
00145
00146 };
00147
00148 }
00149
00150 #endif