/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ASFormatter.cpp
*
* Copyright (C) 2006-2011 by Jim Pattee <jimp03@email.com>
* Copyright (C) 1998-2002 by Tal Davidson
* <http://www.gnu.org/licenses/lgpl-3.0.html>
*
* This file is a part of Artistic Style - an indentation and
* reformatting tool for C, C++, C# and Java source files.
* <http://astyle.sourceforge.net>
*
* Artistic Style is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Artistic Style is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Artistic Style. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
#include "astyle.h"
#include <algorithm>
#include <fstream>
#include <iostream>
namespace astyle
{
/**
* Constructor of ASFormatter
*/
ASFormatter::ASFormatter()
{
sourceIterator = NULL;
enhancer = new ASEnhancer;
preBracketHeaderStack = NULL;
bracketTypeStack = NULL;
parenStack = NULL;
structStack = NULL;
lineCommentNoIndent = false;
formattingStyle = STYLE_NONE;
bracketFormatMode = NONE_MODE;
pointerAlignment = PTR_ALIGN_NONE;
referenceAlignment = REF_SAME_AS_PTR;
lineEnd = LINEEND_DEFAULT;
shouldPadOperators = false;
shouldPadParensOutside = false;
shouldPadParensInside = false;
shouldPadHeader = false;
shouldUnPadParens = false;
shouldAttachClosingBracket = false;
shouldBreakOneLineBlocks = true;
shouldBreakOneLineStatements = true;
shouldConvertTabs = false;
shouldIndentCol1Comments = false;
shouldBreakBlocks = false;
shouldBreakClosingHeaderBlocks = false;
shouldBreakClosingHeaderBrackets = false;
shouldDeleteEmptyLines = false;
shouldBreakElseIfs = false;
shouldAddBrackets = false;
shouldAddOneLineBrackets = false;
// initialize ASFormatter member vectors
formatterFileType = 9; // reset to an invalid type
headers = new vector<const string*>;
nonParenHeaders = new vector<const string*>;
preDefinitionHeaders = new vector<const string*>;
preCommandHeaders = new vector<const string*>;
operators = new vector<const string*>;
assignmentOperators = new vector<const string*>;
castOperators = new vector<const string*>;
// the following prevents warning messages with cppcheck
// it will NOT compile if activated
// init();
}
/**
* Destructor of ASFormatter
*/
ASFormatter::~ASFormatter()
{
// delete ASFormatter stack vectors
deleteContainer(preBracketHeaderStack);
deleteContainer(bracketTypeStack);
deleteContainer(parenStack);
deleteContainer(structStack);
// delete ASFormatter member vectors
formatterFileType = 9; // reset to an invalid type
delete headers;
delete nonParenHeaders;
delete preDefinitionHeaders;
delete preCommandHeaders;
delete operators;
delete assignmentOperators;
delete castOperators;
// delete ASBeautifier member vectors
// must be done when the ASFormatter object is deleted (not ASBeautifier)
ASBeautifier::deleteBeautifierVectors();
delete enhancer;
}
/**
* initialize the ASFormatter.
*
* init() should be called every time a ASFormatter object is to start
* formatting a NEW source file.
* init() recieves a pointer to a ASSourceIterator object that will be
* used to iterate through the source code.
*
* @param sourceIterator a pointer to the ASSourceIterator or ASStreamIterator object.
*/
void ASFormatter::init(ASSourceIterator* si)
{
buildLanguageVectors();
fixOptionVariableConflicts();
ASBeautifier::init(si);
enhancer->init(getFileType(),
getIndentLength(),
getIndentString(),
getCaseIndent(),
getPreprocessorIndent(),
getEmptyLineFill());
sourceIterator = si;
initContainer(preBracketHeaderStack, new vector<const string*>);
initContainer(parenStack, new vector<int>);
initContainer(structStack, new vector<bool>);
parenStack->push_back(0); // parenStack must contain this default entry
initContainer(bracketTypeStack, new vector<BracketType>);
bracketTypeStack->push_back(NULL_TYPE); // bracketTypeStack must contain this default entry
currentHeader = NULL;
currentLine = "";
readyFormattedLine = "";
formattedLine = "";
currentChar = ' ';
previousChar = ' ';
previousCommandChar = ' ';
previousNonWSChar = ' ';
quoteChar = '"';
charNum = 0;
checksumIn = 0;
checksumOut = 0;
leadingSpaces = 0;
formattedLineCommentNum = 0;
preprocBracketTypeStackSize = 0;
spacePadNum = 0;
nextLineSpacePadNum = 0;
currentLineFirstBracketNum = string::npos;
previousReadyFormattedLineLength = string::npos;
templateDepth = 0;
traceLineNumber = 0;
horstmannIndentChars = 0;
tabIncrementIn = 0;
previousBracketType = NULL_TYPE;
previousOperator = NULL;
isVirgin = true;
isInLineComment = false;
isInComment = false;
noTrimCommentContinuation = false;
isInPreprocessor = false;
isInPreprocessorBeautify = false;
doesLineStartComment = false;
lineEndsInCommentOnly = false;
lineIsLineCommentOnly = false;
lineIsEmpty = false;
isImmediatelyPostCommentOnly = false;
isImmediatelyPostEmptyLine = false;
isInQuote = false;
isInVerbatimQuote = false;
haveLineContinuationChar = false;
isInQuoteContinuation = false;
isSpecialChar = false;
isNonParenHeader = false;
foundNamespaceHeader = false;
foundClassHeader = false;
foundStructHeader = false;
foundInterfaceHeader = false;
foundPreDefinitionHeader = false;
foundPreCommandHeader = false;
foundCastOperator = false;
foundQuestionMark = false;
isInLineBreak = false;
endOfCodeReached = false;
isInExecSQL = false;
isInAsm = false;
isInAsmOneLine = false;
isInAsmBlock = false;
isLineReady = false;
isPreviousBracketBlockRelated = false;
isInPotentialCalculation = false;
shouldReparseCurrentChar = false;
needHeaderOpeningBracket = false;
shouldBreakLineAtNextChar = false;
passedSemicolon = false;
passedColon = false;
isImmediatelyPostNonInStmt = false;
isCharImmediatelyPostNonInStmt = false;
isInTemplate = false;
isImmediatelyPostComment = false;
isImmediatelyPostLineComment = false;
isImmediatelyPostEmptyBlock = false;
isImmediatelyPostPreprocessor = false;
isImmediatelyPostReturn = false;
isImmediatelyPostOperator = false;
isImmediatelyPostTemplate = false;
isImmediatelyPostPointerOrReference = false;
isCharImmediatelyPostReturn = false;
isCharImmediatelyPostOperator = false;
isCharImmediatelyPostComment = false;
isPreviousCharPostComment = false;
isCharImmediatelyPostLineComment = false;
isCharImmediatelyPostOpenBlock = false;
isCharImmediatelyPostCloseBlock = false;
isCharImmediatelyPostTemplate = false;
isCharImmediatelyPostPointerOrReference = false;
breakCurrentOneLineBlock = false;
isInHorstmannRunIn = false;
currentLineBeginsWithBracket = false;
isPrependPostBlockEmptyLineRequested = false;
isAppendPostBlockEmptyLineRequested = false;
prependEmptyLine = false;
appendOpeningBracket = false;
foundClosingHeader = false;
isImmediatelyPostHeader = false;
isInHeader = false;
isInCase = false;
isJavaStaticConstructor = false;
}
/**
* build vectors for each programing language
* depending on the file extension.
*/
void ASFormatter::buildLanguageVectors()
{
if (getFileType() == formatterFileType) // don't build unless necessary
没有合适的资源?快使用搜索试试~ 我知道了~
AStyle(vs2010代码格式化工具)
共52个文件
sln:15个
html:10个
vcproj:8个
5星 · 超过95%的资源 需积分: 20 47 下载量 111 浏览量
2012-02-21
12:05:21
上传
评论
收藏 358KB ZIP 举报
温馨提示
使用教程http://www.cppblog.com/jokes000/articles/158838.html
资源推荐
资源详情
资源评论
收起资源包目录
AStyle_2.02.1_windows.zip (52个子文件)
AStyle
src
astyle_main.h 13KB
astyle.h 31KB
astyle_main.cpp 92KB
ASFormatter.cpp 143KB
ASEnhancer.cpp 16KB
ASBeautifier.cpp 77KB
ASLocalizer.h 4KB
ASResource.cpp 20KB
ASLocalizer.cpp 21KB
doc
links.html 8KB
index.html 11KB
styles.css 2KB
notes.html 81KB
subversion.html 5KB
scripts.html 6KB
license.html 12KB
astyle.html 68KB
news.html 61KB
install.html 16KB
vsinstall.html 5KB
build
vs2008
AStyleDll.sln 1KB
AStyleJava.sln 1KB
AStyleJava
AStyleJava.vcproj 9KB
AStyleLib
AStyleLib.vcproj 7KB
AStyleDll
AStyleDll.vcproj 8KB
AStyle
AStyle.vcproj 12KB
AStyle.sln 2KB
AStyleLib.sln 1KB
All AStyle.sln 4KB
vs2010
AStyleDll.sln 1KB
AStyleJava.sln 1KB
AStyleJava
AStyleJava.vcxproj 11KB
AStyleJava.vcxproj.filters 1KB
AStyleLib
AStyleLib.vcxproj.filters 1KB
AStyleLib.vcxproj 8KB
AStyleDll
AStyleDll.vcxproj 10KB
AStyleDll.vcxproj.filters 1KB
AStyle
AStyle.vcxproj.filters 1KB
AStyle.vcxproj 14KB
AStyle.sln 2KB
AStyleLib.sln 1KB
All AStyle.sln 4KB
vs2005
AStyleDll.sln 1KB
AStyleJava.sln 1KB
AStyleJava
AStyleJava.vcproj 9KB
AStyleLib
AStyleLib.vcproj 7KB
AStyleDll
AStyleDll.vcproj 8KB
AStyle
AStyle.vcproj 11KB
AStyle.sln 2KB
AStyleLib.sln 1KB
All AStyle.sln 4KB
bin
AStyle.exe 353KB
共 52 条
- 1
资源评论
- 包达叔2013-08-02不怎么好用 还是老实用vs吧
- ly819662012-09-08挺好的,就是引导安装不好!
- jianwangwuwo52012-11-22不好用呀。 使用过程不够详细... 命令,初始目录怎么配都没有说...
- fanzhiyu74102013-11-02代码非常的全 ,不过自己安装的话还是用vs联机搜索安装,比较方便,代码也是只能学习用
anbylau2130
- 粉丝: 0
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功