git-svn-id: svn://ultimatepp.org/upp/trunk@330 f0d560ea-af0d-0410-9eb7-867de7ffcac7

This commit is contained in:
cxl 2008-08-15 09:33:15 +00:00
parent 605a77315f
commit f49ae74c89
90 changed files with 10807 additions and 9917 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,489 +1,489 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* ASEnhancer.cpp
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
// can trace only if NDEBUG is not defined
#ifndef NDEBUG
// #define TRACEswitch
// #define TRACEcase
// #define TRACEmisc
#endif
#include "astyle.h"
#include <iostream>
#include <fstream>
#include <sstream>
#ifdef TRACEswitch
#define TRswitch(a,b) *traceOut << lineNumber << a << b << endl;
#else
#define TRswitch(a,b) ((void)0)
#endif // TRACEswitch
#ifdef TRACEcase
#define TRcase(a,b) *traceOut << lineNumber << a << b << endl;
#else
#define TRcase(a,b) ((void)0)
#endif // TRACEcase
#ifdef TRACEmisc
#define TRmisc(a) *traceOut << lineNumber << a << endl;
#else
#define TRmisc(a) ((void)0)
#endif // TRACEmisc
namespace astyle
{
// ---------------------------- functions for ASEnhancer Class -------------------------------------
/**
* ASEnhancer constructor
*/
ASEnhancer::ASEnhancer()
{
// variables are initialized by init()
traceOut = new StringStream;
}
/**
* Destructor of ASEnhancer
* Display the TRACE entries.
*/
ASEnhancer::~ASEnhancer()
{
#if defined(TRACEswitch) || defined(TRACEcase) || defined(TRACEmisc)
WString line;
WString msg = "TRACE Entries\n\n";
char countLine[50];
int count = 0;
while (getline(*traceOut, line))
{
msg += line + '\n';
count++;
}
sprintf(countLine, "\n%d Entries", count);
msg += countLine;
// write a text file to "My Documents" (Windows)
char filename [_MAX_PATH + _MAX_FNAME + _MAX_EXT + 1]; // full path and filename
strcpy(filename, getenv("USERPROFILE"));
strcat(filename, "\\My Documents\\tracee.txt");
ofstream outfile(filename);
outfile << msg;
outfile.close();
#endif
delete traceOut;
}
/**
* initialize the ASEnhancer.
*
* init() is called each time an ASFormatter object is initialized.
*/
void ASEnhancer::init(int _indentLength,
WString _indentString,
bool _isCStyle,
bool _isJavaStyle,
bool _isSharpStyle,
bool _caseIndent,
bool _emptyLineFill)
{
// formatting variables from ASFormatter and ASBeautifier
indentLength = _indentLength;
if (_indentString[0] == '\t')
useTabs = true;
else
useTabs = false;
isCStyle = _isCStyle;
isJavaStyle = _isJavaStyle;
isSharpStyle = _isSharpStyle;
caseIndent = _caseIndent;
emptyLineFill = _emptyLineFill;
// unindent variables
lineNumber = 0;
bracketCount = 0;
isInComment = false;
isInQuote = false;
switchDepth = 0;
lookingForCaseBracket = false;
unindentNextLine = false;
#if defined(TRACEswitch) || defined(TRACEcase) || defined(TRACEmisc)
*traceOut << "New file -------------" << endl;
#endif
}
/**
* additional formatting for line of source code.
* every line of source code in a source code file should be sent
* one after the other to this function.
* indents event tables
* unindents the case blocks
*
* @param line the original formatted line will be updated if necessary.
*/
void ASEnhancer::enhance(WString &line)
{
static Array<switchVariables> swVector; // stack Vector of switch variables
static switchVariables sw; // switch variables struct
static bool nextLineIsEventTable; // begin event table is reached
static bool isInEventTable; // need to indent an event table
bool isSpecialChar = false;
int lineLength; // length of the line being parsed
lineNumber++;
lineLength = line.GetCount();
// check for beginning of event table
if (nextLineIsEventTable)
{
isInEventTable = true;
nextLineIsEventTable = false;
}
if (lineLength == 0
&& ! isInEventTable
&& ! emptyLineFill)
return;
// test for unindent on attached brackets
if (unindentNextLine)
{
sw.unindentDepth++;
sw.unindentCase = true;
unindentNextLine = false;
TRcase(" unindent case ", sw.unindentDepth);
}
// parse characters in the current line.
for (int i = 0; i < lineLength; i++)
{
char ch = line[i];
// bypass whitespace
if (isWhiteSpaceX(ch))
continue;
// handle special characters (i.e. backslash+character such as \n, \t, ...)
if (isSpecialChar)
{
isSpecialChar = false;
continue;
}
if (!(isInComment) && line.Mid(i, 2) == WString("\\\\"))
{
i++;
continue;
}
if (!(isInComment) && ch == '\\')
{
isSpecialChar = true;
continue;
}
// handle quotes (such as 'x' and "Hello Dolly")
if (!(isInComment) && (ch == '"' || ch == '\''))
if (!isInQuote)
{
quoteChar = ch;
isInQuote = true;
}
else if (quoteChar == ch)
{
isInQuote = false;
continue;
}
if (isInQuote)
continue;
// handle comments
if (!(isInComment) && line.Mid(i, 2) == WString("//"))
{
// check for windows line markers
//@@ CHECK !!!! if (line.Mid(i + 2, 1) > WString("\xf0"))
if (line.Mid(i + 2, 1) > WString("\xf0") && line.Mid(i + 2, 1) > WString("\xff"))
lineNumber--;
break; // finished with the line
}
else if (!(isInComment) && line.Mid(i, 2) == WString("/*"))
{
isInComment = true;
i++;
continue;
}
else if ((isInComment) && line.Mid(i, 2) == WString("*/"))
{
isInComment = false;
i++;
continue;
}
if (isInComment)
continue;
// if we have reached this far then we are NOT in a comment or String of special characters
if (line[i] == '{') // if open bracket
bracketCount++;
if (line[i] == '}') // if close bracket
bracketCount--;
// ---------------- process event tables --------------------------------------
// check for event table begin
if (findKeyword(line, i, "BEGIN_EVENT_TABLE")
|| findKeyword(line, i, "BEGIN_MESSAGE_MAP"))
nextLineIsEventTable = true;
// check for event table end
if (findKeyword(line, i, "END_EVENT_TABLE")
|| findKeyword(line, i, "END_MESSAGE_MAP"))
isInEventTable = false;
// ---------------- process switch statements ---------------------------------
if (findKeyword(line, i, "switch")) // if switch statement
{
switchDepth++; // bump switch depth
TRswitch(" switch ", switchDepth);
swVector.push_back(sw); // save current variables
sw.switchBracketCount = 0;
sw.unindentCase = false; // don't clear case until end of switch
i += 5; // bypass switch statement
continue;
}
// just want switch statements from this point
if (caseIndent || switchDepth == 0) // from here just want switch statements
continue; // get next char
if (line[i] == '{') // if open bracket
{
sw.switchBracketCount++;
if (lookingForCaseBracket) // if 1st after case statement
{
sw.unindentCase = true; // unindenting this case
sw.unindentDepth++; // bump depth
lookingForCaseBracket = false; // not looking now
TRcase(" unindent case ", sw.unindentDepth);
}
continue;
}
lookingForCaseBracket = false; // no opening bracket, don't indent
if (line[i] == '}') // if close bracket
{
sw.switchBracketCount--;
if (sw.switchBracketCount == 0) // if end of switch statement
{
TRswitch(" endsw ", switchDepth);
switchDepth--; // one less switch
sw = swVector.back(); // restore sw struct
swVector.pop_back(); // remove last entry from stack
}
continue;
}
// look for case or default header
if (findKeyword(line, i, "case") || findKeyword(line, i, "default"))
{
if (sw.unindentCase) // if unindented last case
{
sw.unindentCase = false; // stop unindenting previous case
sw.unindentDepth--; // reduce depth
}
for (; i < lineLength; i++) // bypass colon
{
if (line[i] == ':')
if ((i + 1 < lineLength) && (line[i + 1] == ':'))
i++; // bypass scope resolution operator
else
break;
}
i++;
for (; i < lineLength; i++) // bypass whitespace
{
if (!(isWhiteSpaceX(line[i])))
break;
}
if (i < lineLength) // check for bracket
{
if (line[i] == '{') // if bracket found
{
sw.switchBracketCount++;
unindentNextLine = true; // start unindenting on next line
continue;
}
}
lookingForCaseBracket = true; // bracket must be on next line
i--; // need to check for comments
continue;
}
} // end of for loop
if (isInEventTable) // if need to indent
indentLine(line, 1); // do it
if (sw.unindentDepth > 0) // if need to unindent
unindentLine(line, sw.unindentDepth); // do it
}
/**
* indent a line by a given number of tabsets
* by inserting leading whitespace to the line argument.
*
* @param line a pointer to the line to indent.
* @param unindent the number of tabsets to insert.
* @return the number of characters inserted.
*/
int ASEnhancer::indentLine(WString &line, const int indent) const
{
if (line.GetCount() == 0
&& ! emptyLineFill)
return 0;
int charsToInsert; // number of chars to insert
if (useTabs) // if formatted with tabs
{
charsToInsert = indent; // tabs to insert
line.Insert(0, WString('\t', charsToInsert)); // insert the tabs
}
else
{
charsToInsert = indent * indentLength; // compute chars to insert
line.Insert(0, WString('\t', charsToInsert)); // insert the tabs
}
return charsToInsert;
}
/**
* unindent a line by a given number of tabsets
* by erasing the leading whitespace from the line argument.
*
* @param line a pointer to the line to unindent.
* @param unindent the number of tabsets to erase.
* @return the number of characters erased.
*/
int ASEnhancer::unindentLine(WString &line, const int unindent) const
{
int whitespace = ASString_Find_First_Not_Of(line, " \t");
if (whitespace == -1) // if line is blank
whitespace = line.GetCount(); // must remove padding, if any
if (whitespace == 0)
return 0;
int charsToErase; // number of chars to erase
if (useTabs) // if formatted with tabs
{
charsToErase = unindent; // tabs to erase
if (charsToErase <= whitespace) // if there is enough whitespace
line.Remove(0, charsToErase); // erase the tabs
else
charsToErase = 0;
}
else
{
charsToErase = unindent * indentLength; // compute chars to erase
if (charsToErase <= whitespace) // if there is enough whitespace
line.Remove(0, charsToErase); // erase the spaces
else
charsToErase = 0;
}
return charsToErase;
}
/**
* check if a specific line position contains a keyword.
*
* @return true if the word was found. false if the word was not found.
*/
bool ASEnhancer::findKeyword(const WString &line, int i, const char *keyword) const
{
if (line.Mid(i, strlen(keyword)) == WString(keyword))
{
// check that this is a header and not a part of a longer word
// (e.g. not at its begining, not at its middle...)
int lineLength = line.GetCount();
int wordEnd = i + strlen(keyword);
char startCh = keyword[0]; // first char of header
char endCh = 0; // char just after header
char prevCh = 0; // char just before header
if (wordEnd < lineLength)
{
endCh = line[wordEnd];
}
if (i > 0)
{
prevCh = line[i-1];
}
if (prevCh != 0
&& isLegalNameCharX(startCh)
&& isLegalNameCharX(prevCh))
{
return false;
}
else if (wordEnd >= lineLength
|| !isLegalNameCharX(startCh)
|| !isLegalNameCharX(endCh))
{
return true;
}
else
{
return false;
}
}
return false;
}
} // end namespace astyle
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* ASEnhancer.cpp
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
// can trace only if NDEBUG is not defined
#ifndef NDEBUG
// #define TRACEswitch
// #define TRACEcase
// #define TRACEmisc
#endif
#include "astyle.h"
#include <iostream>
#include <fstream>
#include <sstream>
#ifdef TRACEswitch
#define TRswitch(a,b) *traceOut << lineNumber << a << b << endl;
#else
#define TRswitch(a,b) ((void)0)
#endif // TRACEswitch
#ifdef TRACEcase
#define TRcase(a,b) *traceOut << lineNumber << a << b << endl;
#else
#define TRcase(a,b) ((void)0)
#endif // TRACEcase
#ifdef TRACEmisc
#define TRmisc(a) *traceOut << lineNumber << a << endl;
#else
#define TRmisc(a) ((void)0)
#endif // TRACEmisc
namespace astyle
{
// ---------------------------- functions for ASEnhancer Class -------------------------------------
/**
* ASEnhancer constructor
*/
ASEnhancer::ASEnhancer()
{
// variables are initialized by init()
traceOut = new StringStream;
}
/**
* Destructor of ASEnhancer
* Display the TRACE entries.
*/
ASEnhancer::~ASEnhancer()
{
#if defined(TRACEswitch) || defined(TRACEcase) || defined(TRACEmisc)
WString line;
WString msg = "TRACE Entries\n\n";
char countLine[50];
int count = 0;
while (getline(*traceOut, line))
{
msg += line + '\n';
count++;
}
sprintf(countLine, "\n%d Entries", count);
msg += countLine;
// write a text file to "My Documents" (Windows)
char filename [_MAX_PATH + _MAX_FNAME + _MAX_EXT + 1]; // full path and filename
strcpy(filename, getenv("USERPROFILE"));
strcat(filename, "\\My Documents\\tracee.txt");
ofstream outfile(filename);
outfile << msg;
outfile.close();
#endif
delete traceOut;
}
/**
* initialize the ASEnhancer.
*
* init() is called each time an ASFormatter object is initialized.
*/
void ASEnhancer::init(int _indentLength,
WString _indentString,
bool _isCStyle,
bool _isJavaStyle,
bool _isSharpStyle,
bool _caseIndent,
bool _emptyLineFill)
{
// formatting variables from ASFormatter and ASBeautifier
indentLength = _indentLength;
if (_indentString[0] == '\t')
useTabs = true;
else
useTabs = false;
isCStyle = _isCStyle;
isJavaStyle = _isJavaStyle;
isSharpStyle = _isSharpStyle;
caseIndent = _caseIndent;
emptyLineFill = _emptyLineFill;
// unindent variables
lineNumber = 0;
bracketCount = 0;
isInComment = false;
isInQuote = false;
switchDepth = 0;
lookingForCaseBracket = false;
unindentNextLine = false;
#if defined(TRACEswitch) || defined(TRACEcase) || defined(TRACEmisc)
*traceOut << "New file -------------" << endl;
#endif
}
/**
* additional formatting for line of source code.
* every line of source code in a source code file should be sent
* one after the other to this function.
* indents event tables
* unindents the case blocks
*
* @param line the original formatted line will be updated if necessary.
*/
void ASEnhancer::enhance(WString &line)
{
static Array<switchVariables> swVector; // stack Vector of switch variables
static switchVariables sw; // switch variables struct
static bool nextLineIsEventTable; // begin event table is reached
static bool isInEventTable; // need to indent an event table
bool isSpecialChar = false;
int lineLength; // length of the line being parsed
lineNumber++;
lineLength = line.GetCount();
// check for beginning of event table
if (nextLineIsEventTable)
{
isInEventTable = true;
nextLineIsEventTable = false;
}
if (lineLength == 0
&& ! isInEventTable
&& ! emptyLineFill)
return;
// test for unindent on attached brackets
if (unindentNextLine)
{
sw.unindentDepth++;
sw.unindentCase = true;
unindentNextLine = false;
TRcase(" unindent case ", sw.unindentDepth);
}
// parse characters in the current line.
for (int i = 0; i < lineLength; i++)
{
char ch = line[i];
// bypass whitespace
if (isWhiteSpaceX(ch))
continue;
// handle special characters (i.e. backslash+character such as \n, \t, ...)
if (isSpecialChar)
{
isSpecialChar = false;
continue;
}
if (!(isInComment) && line.Mid(i, 2) == WString("\\\\"))
{
i++;
continue;
}
if (!(isInComment) && ch == '\\')
{
isSpecialChar = true;
continue;
}
// handle quotes (such as 'x' and "Hello Dolly")
if (!(isInComment) && (ch == '"' || ch == '\''))
if (!isInQuote)
{
quoteChar = ch;
isInQuote = true;
}
else if (quoteChar == ch)
{
isInQuote = false;
continue;
}
if (isInQuote)
continue;
// handle comments
if (!(isInComment) && line.Mid(i, 2) == WString("//"))
{
// check for windows line markers
//@@ CHECK !!!! if (line.Mid(i + 2, 1) > WString("\xf0"))
if (line.Mid(i + 2, 1) > WString("\xf0") && line.Mid(i + 2, 1) > WString("\xff"))
lineNumber--;
break; // finished with the line
}
else if (!(isInComment) && line.Mid(i, 2) == WString("/*"))
{
isInComment = true;
i++;
continue;
}
else if ((isInComment) && line.Mid(i, 2) == WString("*/"))
{
isInComment = false;
i++;
continue;
}
if (isInComment)
continue;
// if we have reached this far then we are NOT in a comment or String of special characters
if (line[i] == '{') // if open bracket
bracketCount++;
if (line[i] == '}') // if close bracket
bracketCount--;
// ---------------- process event tables --------------------------------------
// check for event table begin
if (findKeyword(line, i, "BEGIN_EVENT_TABLE")
|| findKeyword(line, i, "BEGIN_MESSAGE_MAP"))
nextLineIsEventTable = true;
// check for event table end
if (findKeyword(line, i, "END_EVENT_TABLE")
|| findKeyword(line, i, "END_MESSAGE_MAP"))
isInEventTable = false;
// ---------------- process switch statements ---------------------------------
if (findKeyword(line, i, "switch")) // if switch statement
{
switchDepth++; // bump switch depth
TRswitch(" switch ", switchDepth);
swVector.push_back(sw); // save current variables
sw.switchBracketCount = 0;
sw.unindentCase = false; // don't clear case until end of switch
i += 5; // bypass switch statement
continue;
}
// just want switch statements from this point
if (caseIndent || switchDepth == 0) // from here just want switch statements
continue; // get next char
if (line[i] == '{') // if open bracket
{
sw.switchBracketCount++;
if (lookingForCaseBracket) // if 1st after case statement
{
sw.unindentCase = true; // unindenting this case
sw.unindentDepth++; // bump depth
lookingForCaseBracket = false; // not looking now
TRcase(" unindent case ", sw.unindentDepth);
}
continue;
}
lookingForCaseBracket = false; // no opening bracket, don't indent
if (line[i] == '}') // if close bracket
{
sw.switchBracketCount--;
if (sw.switchBracketCount == 0) // if end of switch statement
{
TRswitch(" endsw ", switchDepth);
switchDepth--; // one less switch
sw = swVector.back(); // restore sw struct
swVector.pop_back(); // remove last entry from stack
}
continue;
}
// look for case or default header
if (findKeyword(line, i, "case") || findKeyword(line, i, "default"))
{
if (sw.unindentCase) // if unindented last case
{
sw.unindentCase = false; // stop unindenting previous case
sw.unindentDepth--; // reduce depth
}
for (; i < lineLength; i++) // bypass colon
{
if (line[i] == ':')
if ((i + 1 < lineLength) && (line[i + 1] == ':'))
i++; // bypass scope resolution operator
else
break;
}
i++;
for (; i < lineLength; i++) // bypass whitespace
{
if (!(isWhiteSpaceX(line[i])))
break;
}
if (i < lineLength) // check for bracket
{
if (line[i] == '{') // if bracket found
{
sw.switchBracketCount++;
unindentNextLine = true; // start unindenting on next line
continue;
}
}
lookingForCaseBracket = true; // bracket must be on next line
i--; // need to check for comments
continue;
}
} // end of for loop
if (isInEventTable) // if need to indent
indentLine(line, 1); // do it
if (sw.unindentDepth > 0) // if need to unindent
unindentLine(line, sw.unindentDepth); // do it
}
/**
* indent a line by a given number of tabsets
* by inserting leading whitespace to the line argument.
*
* @param line a pointer to the line to indent.
* @param unindent the number of tabsets to insert.
* @return the number of characters inserted.
*/
int ASEnhancer::indentLine(WString &line, const int indent) const
{
if (line.GetCount() == 0
&& ! emptyLineFill)
return 0;
int charsToInsert; // number of chars to insert
if (useTabs) // if formatted with tabs
{
charsToInsert = indent; // tabs to insert
line.Insert(0, WString('\t', charsToInsert)); // insert the tabs
}
else
{
charsToInsert = indent * indentLength; // compute chars to insert
line.Insert(0, WString('\t', charsToInsert)); // insert the tabs
}
return charsToInsert;
}
/**
* unindent a line by a given number of tabsets
* by erasing the leading whitespace from the line argument.
*
* @param line a pointer to the line to unindent.
* @param unindent the number of tabsets to erase.
* @return the number of characters erased.
*/
int ASEnhancer::unindentLine(WString &line, const int unindent) const
{
int whitespace = ASString_Find_First_Not_Of(line, " \t");
if (whitespace == -1) // if line is blank
whitespace = line.GetCount(); // must remove padding, if any
if (whitespace == 0)
return 0;
int charsToErase; // number of chars to erase
if (useTabs) // if formatted with tabs
{
charsToErase = unindent; // tabs to erase
if (charsToErase <= whitespace) // if there is enough whitespace
line.Remove(0, charsToErase); // erase the tabs
else
charsToErase = 0;
}
else
{
charsToErase = unindent * indentLength; // compute chars to erase
if (charsToErase <= whitespace) // if there is enough whitespace
line.Remove(0, charsToErase); // erase the spaces
else
charsToErase = 0;
}
return charsToErase;
}
/**
* check if a specific line position contains a keyword.
*
* @return true if the word was found. false if the word was not found.
*/
bool ASEnhancer::findKeyword(const WString &line, int i, const char *keyword) const
{
if (line.Mid(i, strlen(keyword)) == WString(keyword))
{
// check that this is a header and not a part of a longer word
// (e.g. not at its begining, not at its middle...)
int lineLength = line.GetCount();
int wordEnd = i + strlen(keyword);
char startCh = keyword[0]; // first char of header
char endCh = 0; // char just after header
char prevCh = 0; // char just before header
if (wordEnd < lineLength)
{
endCh = line[wordEnd];
}
if (i > 0)
{
prevCh = line[i-1];
}
if (prevCh != 0
&& isLegalNameCharX(startCh)
&& isLegalNameCharX(prevCh))
{
return false;
}
else if (wordEnd >= lineLength
|| !isLegalNameCharX(startCh)
|| !isLegalNameCharX(endCh))
{
return true;
}
else
{
return false;
}
}
return false;
}
} // end namespace astyle

File diff suppressed because it is too large Load diff

View file

@ -1,395 +1,395 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* ASResource.cpp
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
#include "astyle.h"
namespace astyle
{
const WString ASResource::AS_IF = WString("if");
const WString ASResource::AS_ELSE = WString("else");
const WString ASResource::AS_FOR = WString("for");
const WString ASResource::AS_DO = WString("do");
const WString ASResource::AS_WHILE = WString("while");
const WString ASResource::AS_SWITCH = WString("switch");
const WString ASResource::AS_CASE = WString("case");
const WString ASResource::AS_DEFAULT = WString("default");
const WString ASResource::AS_CLASS = WString("class");
const WString ASResource::AS_STRUCT = WString("struct");
const WString ASResource::AS_UNION = WString("union");
const WString ASResource::AS_INTERFACE = WString("interface");
const WString ASResource::AS_NAMESPACE = WString("namespace");
const WString ASResource::AS_EXTERN = WString("extern");
const WString ASResource::AS_PUBLIC = WString("public");
const WString ASResource::AS_PROTECTED = WString("protected");
const WString ASResource::AS_PRIVATE = WString("private");
const WString ASResource::AS_STATIC = WString("static");
const WString ASResource::AS_SYNCHRONIZED = WString("synchronized");
const WString ASResource::AS_OPERATOR = WString("operator");
const WString ASResource::AS_TEMPLATE = WString("template");
const WString ASResource::AS_TRY = WString("try");
const WString ASResource::AS_CATCH = WString("catch");
const WString ASResource::AS_FINALLY = WString("finally");
const WString ASResource::AS_THROWS = WString("throws");
const WString ASResource::AS_CONST = WString("const");
const WString ASResource::AS_ASM = WString("asm");
const WString ASResource::AS_BAR_DEFINE = WString("#define");
const WString ASResource::AS_BAR_INCLUDE = WString("#include");
const WString ASResource::AS_BAR_IF = WString("#if");
const WString ASResource::AS_BAR_EL = WString("#el");
const WString ASResource::AS_BAR_ENDIF = WString("#endif");
const WString ASResource::AS_OPEN_BRACKET = WString("{");
const WString ASResource::AS_CLOSE_BRACKET = WString("}");
const WString ASResource::AS_OPEN_LINE_COMMENT = WString("//");
const WString ASResource::AS_OPEN_COMMENT = WString("/*");
const WString ASResource::AS_CLOSE_COMMENT = WString("*/");
const WString ASResource::AS_ASSIGN = WString("=");
const WString ASResource::AS_PLUS_ASSIGN = WString("+=");
const WString ASResource::AS_MINUS_ASSIGN = WString("-=");
const WString ASResource::AS_MULT_ASSIGN = WString("*=");
const WString ASResource::AS_DIV_ASSIGN = WString("/=");
const WString ASResource::AS_MOD_ASSIGN = WString("%=");
const WString ASResource::AS_OR_ASSIGN = WString("|=");
const WString ASResource::AS_AND_ASSIGN = WString("&=");
const WString ASResource::AS_XOR_ASSIGN = WString("^=");
const WString ASResource::AS_GR_GR_ASSIGN = WString(">>=");
const WString ASResource::AS_LS_LS_ASSIGN = WString("<<=");
const WString ASResource::AS_GR_GR_GR_ASSIGN = WString(">>>=");
const WString ASResource::AS_LS_LS_LS_ASSIGN = WString("<<<=");
const WString ASResource::AS_RETURN = WString("return");
const WString ASResource::AS_EQUAL = WString("==");
const WString ASResource::AS_PLUS_PLUS = WString("++");
const WString ASResource::AS_MINUS_MINUS = WString("--");
const WString ASResource::AS_NOT_EQUAL = WString("!=");
const WString ASResource::AS_GR_EQUAL = WString(">=");
const WString ASResource::AS_GR_GR = WString(">>");
const WString ASResource::AS_GR_GR_GR = WString(">>>");
const WString ASResource::AS_LS_EQUAL = WString("<=");
const WString ASResource::AS_LS_LS = WString("<<");
const WString ASResource::AS_LS_LS_LS = WString("<<<");
const WString ASResource::AS_ARROW = WString("->");
const WString ASResource::AS_AND = WString("&&");
const WString ASResource::AS_OR = WString("||");
const WString ASResource::AS_COLON_COLON = WString("::");
const WString ASResource::AS_PAREN_PAREN = WString("()");
const WString ASResource::AS_BLPAREN_BLPAREN = WString("[]");
const WString ASResource::AS_PLUS = WString("+");
const WString ASResource::AS_MINUS = WString("-");
const WString ASResource::AS_MULT = WString("*");
const WString ASResource::AS_DIV = WString("/");
const WString ASResource::AS_MOD = WString("%");
const WString ASResource::AS_GR = WString(">");
const WString ASResource::AS_LS = WString("<");
const WString ASResource::AS_NOT = WString("!");
const WString ASResource::AS_BIT_OR = WString("|");
const WString ASResource::AS_BIT_AND = WString("&");
const WString ASResource::AS_BIT_NOT = WString("~");
const WString ASResource::AS_BIT_XOR = WString("^");
const WString ASResource::AS_QUESTION = WString("?");
const WString ASResource::AS_COLON = WString(":");
const WString ASResource::AS_COMMA = WString(",");
const WString ASResource::AS_SEMICOLON = WString(";");
const WString ASResource::AS_FOREACH = WString("foreach");
const WString ASResource::AS_LOCK = WString("lock");
const WString ASResource::AS_UNSAFE = WString("unsafe");
const WString ASResource::AS_FIXED = WString("fixed");
const WString ASResource::AS_GET = WString("get");
const WString ASResource::AS_SET = WString("set");
const WString ASResource::AS_ADD = WString("add");
const WString ASResource::AS_REMOVE = WString("remove");
const WString ASResource::AS_CONST_CAST = WString("const_cast");
const WString ASResource::AS_DYNAMIC_CAST = WString("dynamic_cast");
const WString ASResource::AS_REINTERPRET_CAST = WString("reinterpret_cast");
const WString ASResource::AS_STATIC_CAST = WString("static_cast");
/**
* Build the vector of assignment operators.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param assignmentOperators a reference to the vector to be built.
*/
void ASResource::buildAssignmentOperators(Vector<const WString*> &assignmentOperators)
{
assignmentOperators.push_back(&AS_ASSIGN);
assignmentOperators.push_back(&AS_PLUS_ASSIGN);
assignmentOperators.push_back(&AS_MINUS_ASSIGN);
assignmentOperators.push_back(&AS_MULT_ASSIGN);
assignmentOperators.push_back(&AS_DIV_ASSIGN);
assignmentOperators.push_back(&AS_MOD_ASSIGN);
assignmentOperators.push_back(&AS_OR_ASSIGN);
assignmentOperators.push_back(&AS_AND_ASSIGN);
assignmentOperators.push_back(&AS_XOR_ASSIGN);
// Java
assignmentOperators.push_back(&AS_GR_GR_GR_ASSIGN);
assignmentOperators.push_back(&AS_GR_GR_ASSIGN);
assignmentOperators.push_back(&AS_LS_LS_ASSIGN);
// Unknown
assignmentOperators.push_back(&AS_LS_LS_LS_ASSIGN);
assignmentOperators.push_back(&AS_RETURN);
}
/**
* Build the vector of C++ cast operators.
* Used by ONLY ASFormatter.cpp
*
* @param castOperators a reference to the vector to be built.
*/
void ASResource::buildCastOperators(Vector<const WString*> &castOperators)
{
castOperators.push_back(&AS_CONST_CAST);
castOperators.push_back(&AS_DYNAMIC_CAST);
castOperators.push_back(&AS_REINTERPRET_CAST);
castOperators.push_back(&AS_STATIC_CAST);
}
/**
* Build the vector of header words.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param headers a reference to the vector to be built.
*/
void ASResource::buildHeaders(Vector<const WString*> &headers, int fileType, bool beautifier)
{
headers.push_back(&AS_IF);
headers.push_back(&AS_ELSE);
headers.push_back(&AS_FOR);
headers.push_back(&AS_WHILE);
headers.push_back(&AS_DO);
headers.push_back(&AS_SWITCH);
headers.push_back(&AS_TRY);
headers.push_back(&AS_CATCH);
if (beautifier)
{
headers.push_back(&AS_CASE);
headers.push_back(&AS_DEFAULT);
headers.push_back(&AS_CONST);
headers.push_back(&AS_STATIC);
headers.push_back(&AS_EXTERN);
headers.push_back(&AS_TEMPLATE);
}
if (fileType == JAVA_TYPE)
{
headers.push_back(&AS_FINALLY);
headers.push_back(&AS_SYNCHRONIZED);
}
if (fileType == SHARP_TYPE)
{
headers.push_back(&AS_FINALLY);
headers.push_back(&AS_FOREACH);
headers.push_back(&AS_LOCK);
headers.push_back(&AS_UNSAFE);
headers.push_back(&AS_FIXED);
headers.push_back(&AS_GET);
headers.push_back(&AS_SET);
headers.push_back(&AS_ADD);
headers.push_back(&AS_REMOVE);
}
}
/**
* Build the vector of non-assignment operators.
* Used by ONLY ASBeautifier.cpp
*
* @param nonParenHeaders a reference to the vector to be built.
*/
void ASResource::buildNonAssignmentOperators(Vector<const WString*> &nonAssignmentOperators)
{
nonAssignmentOperators.push_back(&AS_EQUAL);
nonAssignmentOperators.push_back(&AS_PLUS_PLUS);
nonAssignmentOperators.push_back(&AS_MINUS_MINUS);
nonAssignmentOperators.push_back(&AS_NOT_EQUAL);
nonAssignmentOperators.push_back(&AS_GR_EQUAL);
nonAssignmentOperators.push_back(&AS_GR_GR_GR);
nonAssignmentOperators.push_back(&AS_GR_GR);
nonAssignmentOperators.push_back(&AS_LS_EQUAL);
nonAssignmentOperators.push_back(&AS_LS_LS_LS);
nonAssignmentOperators.push_back(&AS_LS_LS);
nonAssignmentOperators.push_back(&AS_ARROW);
nonAssignmentOperators.push_back(&AS_AND);
nonAssignmentOperators.push_back(&AS_OR);
}
/**
* Build the vector of header non-paren headers.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param nonParenHeaders a reference to the vector to be built.
*/
void ASResource::buildNonParenHeaders(Vector<const WString*> &nonParenHeaders, int fileType, bool beautifier)
{
nonParenHeaders.push_back(&AS_ELSE);
nonParenHeaders.push_back(&AS_DO);
nonParenHeaders.push_back(&AS_TRY);
if (beautifier)
{
nonParenHeaders.push_back(&AS_CASE);
nonParenHeaders.push_back(&AS_DEFAULT);
nonParenHeaders.push_back(&AS_CONST);
nonParenHeaders.push_back(&AS_STATIC);
nonParenHeaders.push_back(&AS_EXTERN);
nonParenHeaders.push_back(&AS_TEMPLATE);
}
if (fileType == JAVA_TYPE)
{
nonParenHeaders.push_back(&AS_FINALLY);
}
if (fileType == SHARP_TYPE)
{
nonParenHeaders.push_back(&AS_FINALLY);
nonParenHeaders.push_back(&AS_UNSAFE);
nonParenHeaders.push_back(&AS_GET);
nonParenHeaders.push_back(&AS_SET);
nonParenHeaders.push_back(&AS_ADD);
nonParenHeaders.push_back(&AS_REMOVE);
}
}
/**
* Build the vector of operators.
* Used by ONLY ASFormatter.cpp
*
* @param operators a reference to the vector to be built.
*/
void ASResource::buildOperators(Vector<const WString*> &operators)
{
operators.push_back(&AS_PLUS_ASSIGN);
operators.push_back(&AS_MINUS_ASSIGN);
operators.push_back(&AS_MULT_ASSIGN);
operators.push_back(&AS_DIV_ASSIGN);
operators.push_back(&AS_MOD_ASSIGN);
operators.push_back(&AS_OR_ASSIGN);
operators.push_back(&AS_AND_ASSIGN);
operators.push_back(&AS_XOR_ASSIGN);
operators.push_back(&AS_EQUAL);
operators.push_back(&AS_PLUS_PLUS);
operators.push_back(&AS_MINUS_MINUS);
operators.push_back(&AS_NOT_EQUAL);
operators.push_back(&AS_GR_EQUAL);
operators.push_back(&AS_GR_GR_GR_ASSIGN);
operators.push_back(&AS_GR_GR_ASSIGN);
operators.push_back(&AS_GR_GR_GR);
operators.push_back(&AS_GR_GR);
operators.push_back(&AS_LS_EQUAL);
operators.push_back(&AS_LS_LS_LS_ASSIGN);
operators.push_back(&AS_LS_LS_ASSIGN);
operators.push_back(&AS_LS_LS_LS);
operators.push_back(&AS_LS_LS);
operators.push_back(&AS_ARROW);
operators.push_back(&AS_AND);
operators.push_back(&AS_OR);
operators.push_back(&AS_COLON_COLON);
operators.push_back(&AS_PLUS);
operators.push_back(&AS_MINUS);
operators.push_back(&AS_MULT);
operators.push_back(&AS_DIV);
operators.push_back(&AS_MOD);
operators.push_back(&AS_QUESTION);
operators.push_back(&AS_COLON);
operators.push_back(&AS_ASSIGN);
operators.push_back(&AS_LS);
operators.push_back(&AS_GR);
operators.push_back(&AS_NOT);
operators.push_back(&AS_BIT_OR);
operators.push_back(&AS_BIT_AND);
operators.push_back(&AS_BIT_NOT);
operators.push_back(&AS_BIT_XOR);
operators.push_back(&AS_OPERATOR);
operators.push_back(&AS_COMMA);
operators.push_back(&AS_RETURN);
}
/**
* Build the vector of pre-block statements.
* Used by ONLY ASBeautifier.cpp
*
* @param preBlockStatements a reference to the vector to be built.
*/
void ASResource::buildPreBlockStatements(Vector<const WString*> &preBlockStatements)
{
preBlockStatements.push_back(&AS_CLASS);
preBlockStatements.push_back(&AS_STRUCT);
preBlockStatements.push_back(&AS_UNION);
preBlockStatements.push_back(&AS_INTERFACE);
preBlockStatements.push_back(&AS_NAMESPACE);
preBlockStatements.push_back(&AS_THROWS);
preBlockStatements.push_back(&AS_EXTERN);
}
/**
* Build the vector of pre-command headers.
* Used by ONLY ASFormatter.cpp
*
* @param preCommandHeaders a reference to the vector to be built.
*/
void ASResource::buildPreCommandHeaders(Vector<const WString*> &preCommandHeaders)
{
preCommandHeaders.push_back(&AS_EXTERN);
preCommandHeaders.push_back(&AS_THROWS);
preCommandHeaders.push_back(&AS_CONST);
}
/**
* Build the vector of pre-definition headers.
* Used by ONLY ASFormatter.cpp
*
* @param preDefinitionHeaders a reference to the vector to be built.
*/
void ASResource::buildPreDefinitionHeaders(Vector<const WString*> &preDefinitionHeaders)
{
preDefinitionHeaders.push_back(&AS_CLASS);
preDefinitionHeaders.push_back(&AS_INTERFACE);
preDefinitionHeaders.push_back(&AS_NAMESPACE);
preDefinitionHeaders.push_back(&AS_STRUCT);
}
} // end namespace astyle
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* ASResource.cpp
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
#include "astyle.h"
namespace astyle
{
const WString ASResource::AS_IF = WString("if");
const WString ASResource::AS_ELSE = WString("else");
const WString ASResource::AS_FOR = WString("for");
const WString ASResource::AS_DO = WString("do");
const WString ASResource::AS_WHILE = WString("while");
const WString ASResource::AS_SWITCH = WString("switch");
const WString ASResource::AS_CASE = WString("case");
const WString ASResource::AS_DEFAULT = WString("default");
const WString ASResource::AS_CLASS = WString("class");
const WString ASResource::AS_STRUCT = WString("struct");
const WString ASResource::AS_UNION = WString("union");
const WString ASResource::AS_INTERFACE = WString("interface");
const WString ASResource::AS_NAMESPACE = WString("namespace");
const WString ASResource::AS_EXTERN = WString("extern");
const WString ASResource::AS_PUBLIC = WString("public");
const WString ASResource::AS_PROTECTED = WString("protected");
const WString ASResource::AS_PRIVATE = WString("private");
const WString ASResource::AS_STATIC = WString("static");
const WString ASResource::AS_SYNCHRONIZED = WString("synchronized");
const WString ASResource::AS_OPERATOR = WString("operator");
const WString ASResource::AS_TEMPLATE = WString("template");
const WString ASResource::AS_TRY = WString("try");
const WString ASResource::AS_CATCH = WString("catch");
const WString ASResource::AS_FINALLY = WString("finally");
const WString ASResource::AS_THROWS = WString("throws");
const WString ASResource::AS_CONST = WString("const");
const WString ASResource::AS_ASM = WString("asm");
const WString ASResource::AS_BAR_DEFINE = WString("#define");
const WString ASResource::AS_BAR_INCLUDE = WString("#include");
const WString ASResource::AS_BAR_IF = WString("#if");
const WString ASResource::AS_BAR_EL = WString("#el");
const WString ASResource::AS_BAR_ENDIF = WString("#endif");
const WString ASResource::AS_OPEN_BRACKET = WString("{");
const WString ASResource::AS_CLOSE_BRACKET = WString("}");
const WString ASResource::AS_OPEN_LINE_COMMENT = WString("//");
const WString ASResource::AS_OPEN_COMMENT = WString("/*");
const WString ASResource::AS_CLOSE_COMMENT = WString("*/");
const WString ASResource::AS_ASSIGN = WString("=");
const WString ASResource::AS_PLUS_ASSIGN = WString("+=");
const WString ASResource::AS_MINUS_ASSIGN = WString("-=");
const WString ASResource::AS_MULT_ASSIGN = WString("*=");
const WString ASResource::AS_DIV_ASSIGN = WString("/=");
const WString ASResource::AS_MOD_ASSIGN = WString("%=");
const WString ASResource::AS_OR_ASSIGN = WString("|=");
const WString ASResource::AS_AND_ASSIGN = WString("&=");
const WString ASResource::AS_XOR_ASSIGN = WString("^=");
const WString ASResource::AS_GR_GR_ASSIGN = WString(">>=");
const WString ASResource::AS_LS_LS_ASSIGN = WString("<<=");
const WString ASResource::AS_GR_GR_GR_ASSIGN = WString(">>>=");
const WString ASResource::AS_LS_LS_LS_ASSIGN = WString("<<<=");
const WString ASResource::AS_RETURN = WString("return");
const WString ASResource::AS_EQUAL = WString("==");
const WString ASResource::AS_PLUS_PLUS = WString("++");
const WString ASResource::AS_MINUS_MINUS = WString("--");
const WString ASResource::AS_NOT_EQUAL = WString("!=");
const WString ASResource::AS_GR_EQUAL = WString(">=");
const WString ASResource::AS_GR_GR = WString(">>");
const WString ASResource::AS_GR_GR_GR = WString(">>>");
const WString ASResource::AS_LS_EQUAL = WString("<=");
const WString ASResource::AS_LS_LS = WString("<<");
const WString ASResource::AS_LS_LS_LS = WString("<<<");
const WString ASResource::AS_ARROW = WString("->");
const WString ASResource::AS_AND = WString("&&");
const WString ASResource::AS_OR = WString("||");
const WString ASResource::AS_COLON_COLON = WString("::");
const WString ASResource::AS_PAREN_PAREN = WString("()");
const WString ASResource::AS_BLPAREN_BLPAREN = WString("[]");
const WString ASResource::AS_PLUS = WString("+");
const WString ASResource::AS_MINUS = WString("-");
const WString ASResource::AS_MULT = WString("*");
const WString ASResource::AS_DIV = WString("/");
const WString ASResource::AS_MOD = WString("%");
const WString ASResource::AS_GR = WString(">");
const WString ASResource::AS_LS = WString("<");
const WString ASResource::AS_NOT = WString("!");
const WString ASResource::AS_BIT_OR = WString("|");
const WString ASResource::AS_BIT_AND = WString("&");
const WString ASResource::AS_BIT_NOT = WString("~");
const WString ASResource::AS_BIT_XOR = WString("^");
const WString ASResource::AS_QUESTION = WString("?");
const WString ASResource::AS_COLON = WString(":");
const WString ASResource::AS_COMMA = WString(",");
const WString ASResource::AS_SEMICOLON = WString(";");
const WString ASResource::AS_FOREACH = WString("foreach");
const WString ASResource::AS_LOCK = WString("lock");
const WString ASResource::AS_UNSAFE = WString("unsafe");
const WString ASResource::AS_FIXED = WString("fixed");
const WString ASResource::AS_GET = WString("get");
const WString ASResource::AS_SET = WString("set");
const WString ASResource::AS_ADD = WString("add");
const WString ASResource::AS_REMOVE = WString("remove");
const WString ASResource::AS_CONST_CAST = WString("const_cast");
const WString ASResource::AS_DYNAMIC_CAST = WString("dynamic_cast");
const WString ASResource::AS_REINTERPRET_CAST = WString("reinterpret_cast");
const WString ASResource::AS_STATIC_CAST = WString("static_cast");
/**
* Build the vector of assignment operators.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param assignmentOperators a reference to the vector to be built.
*/
void ASResource::buildAssignmentOperators(Vector<const WString*> &assignmentOperators)
{
assignmentOperators.push_back(&AS_ASSIGN);
assignmentOperators.push_back(&AS_PLUS_ASSIGN);
assignmentOperators.push_back(&AS_MINUS_ASSIGN);
assignmentOperators.push_back(&AS_MULT_ASSIGN);
assignmentOperators.push_back(&AS_DIV_ASSIGN);
assignmentOperators.push_back(&AS_MOD_ASSIGN);
assignmentOperators.push_back(&AS_OR_ASSIGN);
assignmentOperators.push_back(&AS_AND_ASSIGN);
assignmentOperators.push_back(&AS_XOR_ASSIGN);
// Java
assignmentOperators.push_back(&AS_GR_GR_GR_ASSIGN);
assignmentOperators.push_back(&AS_GR_GR_ASSIGN);
assignmentOperators.push_back(&AS_LS_LS_ASSIGN);
// Unknown
assignmentOperators.push_back(&AS_LS_LS_LS_ASSIGN);
assignmentOperators.push_back(&AS_RETURN);
}
/**
* Build the vector of C++ cast operators.
* Used by ONLY ASFormatter.cpp
*
* @param castOperators a reference to the vector to be built.
*/
void ASResource::buildCastOperators(Vector<const WString*> &castOperators)
{
castOperators.push_back(&AS_CONST_CAST);
castOperators.push_back(&AS_DYNAMIC_CAST);
castOperators.push_back(&AS_REINTERPRET_CAST);
castOperators.push_back(&AS_STATIC_CAST);
}
/**
* Build the vector of header words.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param headers a reference to the vector to be built.
*/
void ASResource::buildHeaders(Vector<const WString*> &headers, int fileType, bool beautifier)
{
headers.push_back(&AS_IF);
headers.push_back(&AS_ELSE);
headers.push_back(&AS_FOR);
headers.push_back(&AS_WHILE);
headers.push_back(&AS_DO);
headers.push_back(&AS_SWITCH);
headers.push_back(&AS_TRY);
headers.push_back(&AS_CATCH);
if (beautifier)
{
headers.push_back(&AS_CASE);
headers.push_back(&AS_DEFAULT);
headers.push_back(&AS_CONST);
headers.push_back(&AS_STATIC);
headers.push_back(&AS_EXTERN);
headers.push_back(&AS_TEMPLATE);
}
if (fileType == JAVA_TYPE)
{
headers.push_back(&AS_FINALLY);
headers.push_back(&AS_SYNCHRONIZED);
}
if (fileType == SHARP_TYPE)
{
headers.push_back(&AS_FINALLY);
headers.push_back(&AS_FOREACH);
headers.push_back(&AS_LOCK);
headers.push_back(&AS_UNSAFE);
headers.push_back(&AS_FIXED);
headers.push_back(&AS_GET);
headers.push_back(&AS_SET);
headers.push_back(&AS_ADD);
headers.push_back(&AS_REMOVE);
}
}
/**
* Build the vector of non-assignment operators.
* Used by ONLY ASBeautifier.cpp
*
* @param nonParenHeaders a reference to the vector to be built.
*/
void ASResource::buildNonAssignmentOperators(Vector<const WString*> &nonAssignmentOperators)
{
nonAssignmentOperators.push_back(&AS_EQUAL);
nonAssignmentOperators.push_back(&AS_PLUS_PLUS);
nonAssignmentOperators.push_back(&AS_MINUS_MINUS);
nonAssignmentOperators.push_back(&AS_NOT_EQUAL);
nonAssignmentOperators.push_back(&AS_GR_EQUAL);
nonAssignmentOperators.push_back(&AS_GR_GR_GR);
nonAssignmentOperators.push_back(&AS_GR_GR);
nonAssignmentOperators.push_back(&AS_LS_EQUAL);
nonAssignmentOperators.push_back(&AS_LS_LS_LS);
nonAssignmentOperators.push_back(&AS_LS_LS);
nonAssignmentOperators.push_back(&AS_ARROW);
nonAssignmentOperators.push_back(&AS_AND);
nonAssignmentOperators.push_back(&AS_OR);
}
/**
* Build the vector of header non-paren headers.
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
*
* @param nonParenHeaders a reference to the vector to be built.
*/
void ASResource::buildNonParenHeaders(Vector<const WString*> &nonParenHeaders, int fileType, bool beautifier)
{
nonParenHeaders.push_back(&AS_ELSE);
nonParenHeaders.push_back(&AS_DO);
nonParenHeaders.push_back(&AS_TRY);
if (beautifier)
{
nonParenHeaders.push_back(&AS_CASE);
nonParenHeaders.push_back(&AS_DEFAULT);
nonParenHeaders.push_back(&AS_CONST);
nonParenHeaders.push_back(&AS_STATIC);
nonParenHeaders.push_back(&AS_EXTERN);
nonParenHeaders.push_back(&AS_TEMPLATE);
}
if (fileType == JAVA_TYPE)
{
nonParenHeaders.push_back(&AS_FINALLY);
}
if (fileType == SHARP_TYPE)
{
nonParenHeaders.push_back(&AS_FINALLY);
nonParenHeaders.push_back(&AS_UNSAFE);
nonParenHeaders.push_back(&AS_GET);
nonParenHeaders.push_back(&AS_SET);
nonParenHeaders.push_back(&AS_ADD);
nonParenHeaders.push_back(&AS_REMOVE);
}
}
/**
* Build the vector of operators.
* Used by ONLY ASFormatter.cpp
*
* @param operators a reference to the vector to be built.
*/
void ASResource::buildOperators(Vector<const WString*> &operators)
{
operators.push_back(&AS_PLUS_ASSIGN);
operators.push_back(&AS_MINUS_ASSIGN);
operators.push_back(&AS_MULT_ASSIGN);
operators.push_back(&AS_DIV_ASSIGN);
operators.push_back(&AS_MOD_ASSIGN);
operators.push_back(&AS_OR_ASSIGN);
operators.push_back(&AS_AND_ASSIGN);
operators.push_back(&AS_XOR_ASSIGN);
operators.push_back(&AS_EQUAL);
operators.push_back(&AS_PLUS_PLUS);
operators.push_back(&AS_MINUS_MINUS);
operators.push_back(&AS_NOT_EQUAL);
operators.push_back(&AS_GR_EQUAL);
operators.push_back(&AS_GR_GR_GR_ASSIGN);
operators.push_back(&AS_GR_GR_ASSIGN);
operators.push_back(&AS_GR_GR_GR);
operators.push_back(&AS_GR_GR);
operators.push_back(&AS_LS_EQUAL);
operators.push_back(&AS_LS_LS_LS_ASSIGN);
operators.push_back(&AS_LS_LS_ASSIGN);
operators.push_back(&AS_LS_LS_LS);
operators.push_back(&AS_LS_LS);
operators.push_back(&AS_ARROW);
operators.push_back(&AS_AND);
operators.push_back(&AS_OR);
operators.push_back(&AS_COLON_COLON);
operators.push_back(&AS_PLUS);
operators.push_back(&AS_MINUS);
operators.push_back(&AS_MULT);
operators.push_back(&AS_DIV);
operators.push_back(&AS_MOD);
operators.push_back(&AS_QUESTION);
operators.push_back(&AS_COLON);
operators.push_back(&AS_ASSIGN);
operators.push_back(&AS_LS);
operators.push_back(&AS_GR);
operators.push_back(&AS_NOT);
operators.push_back(&AS_BIT_OR);
operators.push_back(&AS_BIT_AND);
operators.push_back(&AS_BIT_NOT);
operators.push_back(&AS_BIT_XOR);
operators.push_back(&AS_OPERATOR);
operators.push_back(&AS_COMMA);
operators.push_back(&AS_RETURN);
}
/**
* Build the vector of pre-block statements.
* Used by ONLY ASBeautifier.cpp
*
* @param preBlockStatements a reference to the vector to be built.
*/
void ASResource::buildPreBlockStatements(Vector<const WString*> &preBlockStatements)
{
preBlockStatements.push_back(&AS_CLASS);
preBlockStatements.push_back(&AS_STRUCT);
preBlockStatements.push_back(&AS_UNION);
preBlockStatements.push_back(&AS_INTERFACE);
preBlockStatements.push_back(&AS_NAMESPACE);
preBlockStatements.push_back(&AS_THROWS);
preBlockStatements.push_back(&AS_EXTERN);
}
/**
* Build the vector of pre-command headers.
* Used by ONLY ASFormatter.cpp
*
* @param preCommandHeaders a reference to the vector to be built.
*/
void ASResource::buildPreCommandHeaders(Vector<const WString*> &preCommandHeaders)
{
preCommandHeaders.push_back(&AS_EXTERN);
preCommandHeaders.push_back(&AS_THROWS);
preCommandHeaders.push_back(&AS_CONST);
}
/**
* Build the vector of pre-definition headers.
* Used by ONLY ASFormatter.cpp
*
* @param preDefinitionHeaders a reference to the vector to be built.
*/
void ASResource::buildPreDefinitionHeaders(Vector<const WString*> &preDefinitionHeaders)
{
preDefinitionHeaders.push_back(&AS_CLASS);
preDefinitionHeaders.push_back(&AS_INTERFACE);
preDefinitionHeaders.push_back(&AS_NAMESPACE);
preDefinitionHeaders.push_back(&AS_STRUCT);
}
} // end namespace astyle

View file

@ -1,86 +1,86 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* astyle.h
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
#include "ASStringTools.hpp"
///////////////////////////////////////////////////////////////////////////////////////////
// Replaces a chunk in a string with a new string
void ASString_Replace(WString &s, int Pos, int Len, WString const &newString)
{
if(Pos < 0 || Pos >= s.GetCount())
return;
s.Remove(Pos, Len);
s.Insert(Pos, newString);
} // END ASString_Replace()
///////////////////////////////////////////////////////////////////////////////////////////
// Find first character in a string *not* contained in another string
int ASString_Find_First_Not_Of(WString const &s, WString const &Pattern, int pos)
{
if(pos < 0 || pos >= s.GetCount())
return -1;
int len = s.GetCount();
while(pos < len && Pattern.Find(s[pos]) != -1)
pos++;
if(pos < len)
return pos;
else
return -1;
} // END ASString_Find_First_Not_Of()
///////////////////////////////////////////////////////////////////////////////////////////
// Find last character in a string *not* contained in another string
int ASString_Find_Last_Not_Of(WString const &s, WString const &Pattern, int pos)
{
if(pos < 0 || pos >= s.GetCount())
pos = s.GetCount() -1;
while(pos > 0 && Pattern.Find(s[pos]) != -1)
pos--;
return pos;
} // END ASString_Find_Last_Not_Of()
///////////////////////////////////////////////////////////////////////////////////////////
// Finds a substring starting at the end of a given string
int ASString_ReverseFind(WString const &s, WString const &Pattern)
{
int pos = -1;
int k = 0;
while( (k = s.Find(Pattern, k)) >= 0)
pos = k++;
return pos;
} // END ASString_ReverseFind()
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* astyle.h
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
#include "ASStringTools.hpp"
///////////////////////////////////////////////////////////////////////////////////////////
// Replaces a chunk in a string with a new string
void ASString_Replace(WString &s, int Pos, int Len, WString const &newString)
{
if(Pos < 0 || Pos >= s.GetCount())
return;
s.Remove(Pos, Len);
s.Insert(Pos, newString);
} // END ASString_Replace()
///////////////////////////////////////////////////////////////////////////////////////////
// Find first character in a string *not* contained in another string
int ASString_Find_First_Not_Of(WString const &s, WString const &Pattern, int pos)
{
if(pos < 0 || pos >= s.GetCount())
return -1;
int len = s.GetCount();
while(pos < len && Pattern.Find(s[pos]) != -1)
pos++;
if(pos < len)
return pos;
else
return -1;
} // END ASString_Find_First_Not_Of()
///////////////////////////////////////////////////////////////////////////////////////////
// Find last character in a string *not* contained in another string
int ASString_Find_Last_Not_Of(WString const &s, WString const &Pattern, int pos)
{
if(pos < 0 || pos >= s.GetCount())
pos = s.GetCount() -1;
while(pos > 0 && Pattern.Find(s[pos]) != -1)
pos--;
return pos;
} // END ASString_Find_Last_Not_Of()
///////////////////////////////////////////////////////////////////////////////////////////
// Finds a substring starting at the end of a given string
int ASString_ReverseFind(WString const &s, WString const &Pattern)
{
int pos = -1;
int k = 0;
while( (k = s.Find(Pattern, k)) >= 0)
pos = k++;
return pos;
} // END ASString_ReverseFind()

View file

@ -1,58 +1,58 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* astyle.h
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
#ifndef __ASSTRINGTOOLS_HPP
#define __ASSTRINGTOOLS_HPP
#include <Core/Core.h>
using namespace Upp;
///////////////////////////////////////////////////////////////////////////////////////////
// Replaces a chunk in a string with a new string
void ASString_Replace(WString &s, int Pos, int Len, WString const &newString);
///////////////////////////////////////////////////////////////////////////////////////////
// Find first character in a string *not* contained in another string
int ASString_Find_First_Not_Of(WString const &s, WString const &Pattern, int from = 0);
///////////////////////////////////////////////////////////////////////////////////////////
// Find last character in a string *not* contained in another string
int ASString_Find_Last_Not_Of(WString const &s, WString const &Pattern, int from = -1);
///////////////////////////////////////////////////////////////////////////////////////////
// Finds a substring starting at the end of a given string
int ASString_ReverseFind(WString const &s, WString const &Pattern);
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* astyle.h
*
* 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
*
* The "Artistic Style" project, including all files needed to
* compile it, 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 2.1 of the License, or (at your option) any later
* version.
*
* This program 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 this project; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
2008-01-26 Patches by Massimo Del Fedele :
- modified sources to use Ultimate++ containers instead std:: ones
- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
- modified to work with unicode
*/
#ifndef __ASSTRINGTOOLS_HPP
#define __ASSTRINGTOOLS_HPP
#include <Core/Core.h>
using namespace Upp;
///////////////////////////////////////////////////////////////////////////////////////////
// Replaces a chunk in a string with a new string
void ASString_Replace(WString &s, int Pos, int Len, WString const &newString);
///////////////////////////////////////////////////////////////////////////////////////////
// Find first character in a string *not* contained in another string
int ASString_Find_First_Not_Of(WString const &s, WString const &Pattern, int from = 0);
///////////////////////////////////////////////////////////////////////////////////////////
// Find last character in a string *not* contained in another string
int ASString_Find_Last_Not_Of(WString const &s, WString const &Pattern, int from = -1);
///////////////////////////////////////////////////////////////////////////////////////////
// Finds a substring starting at the end of a given string
int ASString_ReverseFind(WString const &s, WString const &Pattern);
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,12 @@
uses
Core;
file
ASStringTools.hpp,
ASStringTools.cpp,
astyle.h,
ASBeautifier.cpp,
ASEnhancer.cpp,
ASFormatter.cpp,
ASResource.cpp;
uses
Core;
file
ASStringTools.hpp,
ASStringTools.cpp,
astyle.h,
ASBeautifier.cpp,
ASEnhancer.cpp,
ASFormatter.cpp,
ASResource.cpp;

File diff suppressed because it is too large Load diff