Commit b2a394bc authored by Davis King's avatar Davis King

Improved declaration pretty printing

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403723
parent 465ee3d4
...@@ -808,50 +808,129 @@ string pretty_print_declaration ( ...@@ -808,50 +808,129 @@ string pretty_print_declaration (
) )
{ {
string temp; string temp;
long angle_count = 0;
long paren_count = 0;
if (decl.size() == 0) if (decl.size() == 0)
return temp; return temp;
else if (decl.size() >= 1)
{ temp = decl[0].second;
temp = decl[0].second;
if (temp == "template")
temp += " "; bool just_closed_template = false;
} bool in_template = false;
bool last_was_scope_res = false;
bool seen_operator = false;
if (temp == "operator")
seen_operator = true;
for (unsigned long i = 1; i < decl.size(); ++i) for (unsigned long i = 1; i < decl.size(); ++i)
{ {
bool add_trailing_space = false; bool last_was_less_than = false;
if (decl[i-1].first == tok_type::OTHER && decl[i-1].second == "<")
last_was_less_than = true;
if (decl[i].first == tok_type::IDENTIFIER || if (decl[i].first == tok_type::OTHER && decl[i].second == "<")
decl[i].first == tok_type::KEYWORD) ++angle_count;
if (decl[i-1].first == tok_type::KEYWORD && decl[i-1].second == "template" &&
decl[i].first == tok_type::OTHER && decl[i].second == "<")
{ {
if (decl[i-1].first == tok_type::IDENTIFIER || in_template = true;
decl[i-1].first == tok_type::KEYWORD || temp += " <\n ";
decl[i-1].second == "," ||
decl[i-1].second == "&" ||
decl[i-1].second == "*" ||
decl[i-1].second == ">"
)
{
temp += " ";
}
} }
else if (i+1 < decl.size()) else if (decl[i].first == tok_type::OTHER && decl[i].second == ">")
{ {
if(decl[i].first == tok_type::OTHER) --angle_count;
if (angle_count == 0 && in_template)
{ {
if (decl[i].second == ":" && decl[i-1].second != ":" && decl[i+1].second != ":") temp += "\n>\n";
{ just_closed_template = true;
temp += " "; in_template = false;
add_trailing_space = true;
}
} }
else
{
temp += ">";
}
}
else if (decl[i].first == tok_type::OTHER && decl[i].second == "<")
{
temp += "<";
}
else if (decl[i].first == tok_type::OTHER && decl[i].second == ",")
{
if (in_template || (paren_count != 0 && angle_count == 0))
temp += ",\n ";
else
temp += ",";
}
else if (decl[i].first == tok_type::OTHER && decl[i].second == "&")
{
temp += "&";
} }
else if (decl[i].first == tok_type::OTHER && decl[i].second == "*")
{
temp += "*";
}
else if (decl[i].first == tok_type::KEYWORD && decl[i].second == "operator")
{
temp += "\noperator";
seen_operator = true;
}
else if (decl[i].first == tok_type::OTHER && decl[i].second == ":" &&
(decl[i-1].second == ":" || (i+1<decl.size() && decl[i+1].second == ":") ) )
{
temp += ":";
last_was_scope_res = true;
}
else if (decl[i].first == tok_type::OTHER && decl[i].second == "(")
{
const bool next_is_paren = (i+1 < decl.size() && decl[i+1].first == tok_type::OTHER && decl[i+1].second == ")");
if (paren_count == 0 && next_is_paren == false)
temp += " (\n ";
else
temp += "(";
++paren_count;
}
else if (decl[i].first == tok_type::OTHER && decl[i].second == ")")
{
--paren_count;
if (paren_count == 0 && decl[i-1].second != "(")
temp += "\n)";
else
temp += ")";
}
else if (decl[i].first == tok_type::IDENTIFIER && i+1 < decl.size() &&
decl[i+1].first == tok_type::OTHER && decl[i+1].second == "(")
{
if (just_closed_template || paren_count != 0 || decl[i-1].second == "~")
temp += decl[i].second;
else if (seen_operator)
temp += " " + decl[i].second;
else
temp += "\n" + decl[i].second;
just_closed_template = false;
last_was_scope_res = false;
}
else
{
if (just_closed_template || last_was_scope_res || last_was_less_than ||
(seen_operator && paren_count == 0 && decl[i].first == tok_type::OTHER ))
temp += decl[i].second;
else
temp += " " + decl[i].second;
just_closed_template = false;
last_was_scope_res = false;
}
temp += decl[i].second;
if (add_trailing_space)
temp += " ";
} }
return temp; return temp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment