ASBeautifier.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 ASBEAUTIFIER_H
00025 #define ASBEAUTIFIER_H
00026 
00027 #include "ASResource.h"
00028 #include "compiler_defines.h"
00029 #include "ASSourceIterator.h"
00030 
00031 #include <string>
00032 #include <vector>
00033 
00034 
00035 using namespace std;
00036 
00037 namespace astyle
00038   {
00039 
00040   enum BracketMode   { NONE_MODE, ATTACH_MODE, BREAK_MODE, BDAC_MODE };
00041   enum BracketType   { NULL_TYPE = 0,
00042                        DEFINITION_TYPE = 1,
00043                        COMMAND_TYPE = 2,
00044                        ARRAY_TYPE  = 4,
00045                        SINGLE_LINE_TYPE = 8};
00046 
00047 
00048   class ASBeautifier : protected ASResource
00049     {
00050     public:
00051       ASBeautifier();
00052       virtual ~ASBeautifier();
00053       virtual void init(ASSourceIterator* iter); // pointer to dynamically created iterator.
00054       virtual void init();
00055       virtual bool hasMoreLines() const;
00056       virtual string nextLine();
00057       virtual string beautify(const string &line);
00058       void setTabIndentation(int length = 4, bool forceTabs = false);
00059       void setSpaceIndentation(int length = 4);
00060       void setMaxInStatementIndentLength(int max);
00061       void setMinConditionalIndentLength(int min);
00062       void setClassIndent(bool state);
00063       void setSwitchIndent(bool state);
00064       void setCaseIndent(bool state);
00065       void setBracketIndent(bool state);
00066       void setBlockIndent(bool state);
00067       void setNamespaceIndent(bool state);
00068       void setLabelIndent(bool state);
00069       void setCStyle();
00070       void setJavaStyle();
00071       void setEmptyLineFill(bool state);
00072       void setPreprocessorIndent(bool state);
00073 
00074 
00075     protected:
00076       int getNextProgramCharDistance(const string &line, int i);
00077       bool isLegalNameChar(char ch) const;
00078       bool isWhiteSpace(char ch) const;
00079       const string *findHeader(const string &line, int i,
00080                                const vector<const string*> &possibleHeaders,
00081                                bool checkBoundry = true);
00082       string trim(const string &str);
00083       int indexOf(vector<const string*> &container, const string *element);
00084 
00085     private:
00086       ASBeautifier(const ASBeautifier &copy);
00087       void operator=(ASBeautifier&); // not to be implemented
00088 
00089       void initStatic();
00090       void registerInStatementIndent(const string &line, int i, int spaceTabCount,
00091                                      int minIndent, bool updateParenStack);
00092       string preLineWS(int spaceTabCount, int tabCount);
00093 
00094       static vector<const string*> headers;
00095       static vector<const string*> nonParenHeaders;
00096       static vector<const string*> preprocessorHeaders;
00097       static vector<const string*> preBlockStatements;
00098       static vector<const string*> assignmentOperators;
00099       static vector<const string*> nonAssignmentOperators;
00100 
00101       static bool calledInitStatic;
00102 
00103       ASSourceIterator *sourceIterator;
00104       vector<ASBeautifier*> *waitingBeautifierStack;
00105       vector<ASBeautifier*> *activeBeautifierStack;
00106       vector<int> *waitingBeautifierStackLengthStack;
00107       vector<int> *activeBeautifierStackLengthStack;
00108       vector<const string*> *headerStack;
00109       vector< vector<const string*>* > *tempStacks;
00110       vector<int> *blockParenDepthStack;
00111       vector<bool> *blockStatementStack;
00112       vector<bool> *parenStatementStack;
00113       vector<int> *inStatementIndentStack;
00114       vector<int> *inStatementIndentStackSizeStack;
00115       vector<int> *parenIndentStack;
00116       vector<bool> *bracketBlockStateStack;
00117       string indentString;
00118       const string *currentHeader;
00119       const string *previousLastLineHeader;
00120       const string *immediatelyPreviousAssignmentOp;
00121       const string *probationHeader;
00122       bool isInQuote;
00123       bool isInComment;
00124       bool isInCase;
00125       bool isInQuestion;
00126       bool isInStatement;
00127       bool isInHeader;
00128       bool isCStyle;
00129       bool isInOperator;
00130       bool isInTemplate;
00131       bool isInConst;
00132       bool isInDefine;
00133       bool isInDefineDefinition;
00134       bool classIndent;
00135       bool isInClassHeader;
00136       bool isInClassHeaderTab;
00137       bool switchIndent;
00138       bool caseIndent;
00139       bool namespaceIndent;
00140       bool bracketIndent;
00141       bool blockIndent;
00142       bool labelIndent;
00143       bool preprocessorIndent;
00144       bool isInConditional;
00145       bool isMinimalConditinalIndentSet;
00146       bool shouldForceTabIndentation;
00147       int minConditionalIndent;
00148       int parenDepth;
00149       int indentLength;
00150       int blockTabCount;
00151       unsigned int leadingWhiteSpaces;
00152       int maxInStatementIndent;
00153       int templateDepth;
00154       char quoteChar;
00155       char prevNonSpaceCh;
00156       char currentNonSpaceCh;
00157       char currentNonLegalCh;
00158       char prevNonLegalCh;
00159       int prevFinalLineSpaceTabCount;
00160       int prevFinalLineTabCount;
00161       bool emptyLineFill;
00162       bool backslashEndsPrevLine;
00163       int defineTabCount;
00164     };
00165 }
00166 
00167 #endif

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