Provide basic indentation for template instantiation argument lists
This commit is contained in:
parent
f3cd3f7c51
commit
1bad21fe6b
@ -180,6 +180,7 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other)
|
|||||||
isInStatement = other.isInStatement;
|
isInStatement = other.isInStatement;
|
||||||
isInHeader = other.isInHeader;
|
isInHeader = other.isInHeader;
|
||||||
isInTemplate = other.isInTemplate;
|
isInTemplate = other.isInTemplate;
|
||||||
|
isInTemplateInstantiation = other.isInTemplateInstantiation;
|
||||||
isInDefine = other.isInDefine;
|
isInDefine = other.isInDefine;
|
||||||
isInDefineDefinition = other.isInDefineDefinition;
|
isInDefineDefinition = other.isInDefineDefinition;
|
||||||
classIndent = other.classIndent;
|
classIndent = other.classIndent;
|
||||||
@ -345,6 +346,7 @@ void ASBeautifier::init(ASSourceIterator* iter)
|
|||||||
isInLet = false;
|
isInLet = false;
|
||||||
isInHeader = false;
|
isInHeader = false;
|
||||||
isInTemplate = false;
|
isInTemplate = false;
|
||||||
|
isInTemplateInstantiation = false;
|
||||||
isInConditional = false;
|
isInConditional = false;
|
||||||
|
|
||||||
indentCount = 0;
|
indentCount = 0;
|
||||||
@ -2114,7 +2116,7 @@ void ASBeautifier::computePreliminaryIndentation()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInTemplate)
|
if (isInTemplate || isInTemplateInstantiation)
|
||||||
{
|
{
|
||||||
// Use symmetrical layout for closing brace in template argument list:
|
// Use symmetrical layout for closing brace in template argument list:
|
||||||
//
|
//
|
||||||
@ -2576,10 +2578,12 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
|||||||
else
|
else
|
||||||
currentHeader = NULL;
|
currentHeader = NULL;
|
||||||
|
|
||||||
if (isCStyle() && isInTemplate
|
if (isCStyle()
|
||||||
&& (ch == '<' || ch == '>')
|
&& (ch == '<' || ch == '>')
|
||||||
&& !(line.length() > i + 1 && line.compare(i, 2, ">=") == 0))
|
&& !(line.length() > i + 1 && line.compare(i, 2, ">=") == 0))
|
||||||
{
|
{
|
||||||
|
if (isInTemplate)
|
||||||
|
{
|
||||||
if (ch == '<')
|
if (ch == '<')
|
||||||
{
|
{
|
||||||
++templateDepth;
|
++templateDepth;
|
||||||
@ -2597,6 +2601,44 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (parenDepth == 0 && !isInClassHeader)
|
||||||
|
{
|
||||||
|
// A template instantiation cannot start with <<
|
||||||
|
if (ch == '<'
|
||||||
|
&& !(line.length() > i + 1 && line.compare(i, 2, "<<") == 0))
|
||||||
|
{
|
||||||
|
if (!isInStatement && templateDepth == 0)
|
||||||
|
{
|
||||||
|
isInTemplateInstantiation = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++templateDepth;
|
||||||
|
|
||||||
|
if (isInTemplateInstantiation)
|
||||||
|
{
|
||||||
|
inStatementIndentStackSizeStack->push_back(inStatementIndentStack->size());
|
||||||
|
registerInStatementIndent(line, i, spaceIndentCount, tabIncrementIn, 0, true);
|
||||||
|
isInStatement = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch == '>' && templateDepth > 0)
|
||||||
|
{
|
||||||
|
if (isInTemplateInstantiation
|
||||||
|
&& !inStatementIndentStackSizeStack->empty())
|
||||||
|
{
|
||||||
|
popLastInStatementIndent();
|
||||||
|
}
|
||||||
|
if (--templateDepth <= 0)
|
||||||
|
{
|
||||||
|
ch = ';';
|
||||||
|
isInTemplateInstantiation = false;
|
||||||
|
templateDepth = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// handle parentheses
|
// handle parentheses
|
||||||
if (ch == '(' || ch == '[' || ch == ')' || ch == ']')
|
if (ch == '(' || ch == '[' || ch == ')' || ch == ']')
|
||||||
@ -3085,10 +3127,13 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((ch == ';' || (parenDepth > 0 && ch == ',')) && !inStatementIndentStackSizeStack->empty())
|
if ((ch == ';' || (parenDepth > 0 && ch == ',')) && !inStatementIndentStackSizeStack->empty())
|
||||||
|
{
|
||||||
while ((int) inStatementIndentStackSizeStack->back() + (parenDepth > 0 ? 1 : 0)
|
while ((int) inStatementIndentStackSizeStack->back() + (parenDepth > 0 ? 1 : 0)
|
||||||
< (int) inStatementIndentStack->size())
|
< (int) inStatementIndentStack->size())
|
||||||
|
{
|
||||||
inStatementIndentStack->pop_back();
|
inStatementIndentStack->pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (ch == ',' && isInEnum && isNonInStatementArray && !inStatementIndentStack->empty())
|
else if (ch == ',' && isInEnum && isNonInStatementArray && !inStatementIndentStack->empty())
|
||||||
inStatementIndentStack->pop_back();
|
inStatementIndentStack->pop_back();
|
||||||
|
|
||||||
@ -3234,7 +3279,17 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parenDepth == 0 && ch == ';')
|
if (parenDepth == 0 && ch == ';')
|
||||||
|
{
|
||||||
isInStatement = false;
|
isInStatement = false;
|
||||||
|
isInTemplateInstantiation = false;
|
||||||
|
templateDepth = 0;
|
||||||
|
|
||||||
|
// This is the end of a statement, so the inStatementIndentStack
|
||||||
|
// should be reset to its default state
|
||||||
|
while (inStatementIndentStackSizeStack->size() > 1)
|
||||||
|
inStatementIndentStackSizeStack->pop_back();
|
||||||
|
inStatementIndentStack->clear();
|
||||||
|
}
|
||||||
if (isInObjCMethodDefinition)
|
if (isInObjCMethodDefinition)
|
||||||
isImmediatelyPostObjCMethodDefinition = true;
|
isImmediatelyPostObjCMethodDefinition = true;
|
||||||
|
|
||||||
@ -3411,7 +3466,8 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
|||||||
if (foundNonAssignmentOp == &AS_LAMBDA)
|
if (foundNonAssignmentOp == &AS_LAMBDA)
|
||||||
foundPreCommandHeader = true;
|
foundPreCommandHeader = true;
|
||||||
|
|
||||||
if (isInTemplate && foundNonAssignmentOp == &AS_GR_GR)
|
if ((isInTemplate || isInTemplateInstantiation)
|
||||||
|
&& foundNonAssignmentOp == &AS_GR_GR)
|
||||||
foundNonAssignmentOp = NULL;
|
foundNonAssignmentOp = NULL;
|
||||||
|
|
||||||
// Since findHeader's boundary checking was not used above, it is possible
|
// Since findHeader's boundary checking was not used above, it is possible
|
||||||
|
@ -444,6 +444,7 @@ private: // variables
|
|||||||
bool isInStatement;
|
bool isInStatement;
|
||||||
bool isInHeader;
|
bool isInHeader;
|
||||||
bool isInTemplate;
|
bool isInTemplate;
|
||||||
|
bool isInTemplateInstantiation;
|
||||||
bool isInDefine;
|
bool isInDefine;
|
||||||
bool isInDefineDefinition;
|
bool isInDefineDefinition;
|
||||||
bool classIndent;
|
bool classIndent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user