ASFormatter.h

00001 /*
00002  * Copyright (c) 1998,1999,2000,2001,2002 Tal Davidson. All rights reserved.
00003  *
00004  * compiler_defines.h   (1 January 1999)
00005  * by Tal Davidson (davidsont@bigfoot.com)
00006  * This file is a part of "Artistic Style" - an indentater and reformatter
00007  * of C, C++, C# and Java source files.
00008  *
00009  * The "Artistic Style" project, including all files needed to compile it,
00010  * is free software; you can redistribute it and/or use it and/or modify it
00011  * under the terms of the GNU General Public License as published 
00012  * by the Free Software Foundation; either version 2 of the License, 
00013  * or (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018  *
00019  * You should have received a copy of the GNU General Public
00020  * License along with this program.
00021  */
00022 
00023 
00024 #ifndef ASFORMATTER_H
00025 #define ASFORMATTER_H
00026 
00027 #include "ASBeautifier.h"
00028 //#include "enums.h"
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 &copy); // not to be imlpemented
00054       void operator=(ASFormatter&); // not to be implemented
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;                        // true both in template definitions (e.g. template<class A>) and template usage (e.g. F<int>).
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       //bool foundOneLineBlock;
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

Generated on Fri Apr 27 13:12:35 2007 for Highlight Code Converter by  doxygen 1.5.2