[DEV] add {} in else and if when not set and add the good indentation of functions
This commit is contained in:
parent
f634d4281f
commit
d3921adc1c
@ -20,6 +20,17 @@ void estyle::Generator::offsetPush(int32_t _count) {
|
|||||||
m_offsetStack.pushBack(_count);
|
m_offsetStack.pushBack(_count);
|
||||||
m_offset += _count;
|
m_offset += _count;
|
||||||
}
|
}
|
||||||
|
void estyle::Generator::offsetPushAuto() {
|
||||||
|
int32_t offset = 0;
|
||||||
|
for (int64_t iii=m_output.size()-1; iii>=0; --iii) {
|
||||||
|
if ( m_output[iii] == '\n'
|
||||||
|
|| m_output[iii] == '\t') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
offsetPush(offset-m_offset);
|
||||||
|
}
|
||||||
|
|
||||||
void estyle::Generator::offsetPop() {
|
void estyle::Generator::offsetPop() {
|
||||||
m_offset -= m_offsetStack.back();
|
m_offset -= m_offsetStack.back();
|
||||||
@ -309,6 +320,7 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (elem == estyle::lexer::EQUAL) {
|
if (elem == estyle::lexer::EQUAL) {
|
||||||
|
addSpace();
|
||||||
m_output += "=";
|
m_output += "=";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -351,6 +363,13 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
m_output += getEndOfLine();
|
m_output += getEndOfLine();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (elem == estyle::lexer::ELEMENT_COMPLEX_TYPE) {
|
||||||
|
// complex type is special to generate...
|
||||||
|
etk::String type = generateType(iii);
|
||||||
|
addSpace();
|
||||||
|
m_output += type;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (elem == estyle::lexer::RESERVED_IF) {
|
if (elem == estyle::lexer::RESERVED_IF) {
|
||||||
addSpace();
|
addSpace();
|
||||||
m_output += "if ";
|
m_output += "if ";
|
||||||
@ -372,13 +391,64 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
offsetPop();
|
offsetPop();
|
||||||
|
// Check if next action is inside {} or not ...
|
||||||
|
if (nextIs(iii+1, estyle::lexer::BRACE_IN) == true) {
|
||||||
|
// no need to add one ...
|
||||||
|
int32_t countAction = countCurrent(iii+1, estyle::lexer::tocken::SEMICOLON);
|
||||||
|
// TODO: need to remove .. if needed...
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (elem == estyle::lexer::ELEMENT_FUNCTION) {
|
m_output += getEndOfLine();
|
||||||
|
addSpace();
|
||||||
|
m_output += "{";
|
||||||
|
indentationPush();
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
|
||||||
|
int32_t sectionEnd = endOfAction(iii+1);
|
||||||
|
iii = process(iii+1, sectionEnd+2);
|
||||||
|
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
indentationPop();
|
||||||
|
addSpace();
|
||||||
|
m_output += "}";
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (elem == estyle::lexer::RESERVED_ELSE) {
|
||||||
|
if (nextIs(iii+1, estyle::lexer::BRACE_IN) == true) {
|
||||||
|
int32_t countAction = countCurrent(iii+1, estyle::lexer::tocken::SEMICOLON);
|
||||||
|
addSpace();
|
||||||
|
m_output += "else";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (nextIs(iii+1, estyle::lexer::RESERVED_IF) == true) {
|
||||||
|
addSpace();
|
||||||
|
m_output += "else";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
addSpace();
|
||||||
|
m_output += "{";
|
||||||
|
indentationPush();
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
|
||||||
|
int32_t sectionEnd = endOfAction(iii+1);
|
||||||
|
iii = process(iii+1, sectionEnd+1);
|
||||||
|
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
indentationPop();
|
||||||
|
addSpace();
|
||||||
|
m_output += "}";
|
||||||
|
m_output += getEndOfLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( elem == estyle::lexer::ELEMENT_FUNCTION
|
||||||
|
|| elem == estyle::lexer::ELEMENT_FUNCTION_DECLARATION) {
|
||||||
addSpace();
|
addSpace();
|
||||||
m_output += m_lexer.getData(iii);
|
m_output += m_lexer.getData(iii);
|
||||||
m_output += " ";
|
m_output += " ";
|
||||||
offsetPush(m_lexer.getData(iii).size() + 2);
|
//offsetPush(m_lexer.getData(iii).size() + 2);
|
||||||
|
offsetPushAuto();
|
||||||
for (int64_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
|
for (int64_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
|
||||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
|
enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
|
||||||
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
||||||
@ -398,7 +468,7 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
addSpace();
|
addSpace();
|
||||||
m_output += m_lexer.getData(iii);
|
m_output += m_lexer.getData(iii);
|
||||||
}
|
}
|
||||||
return m_lexer.size();
|
return _stopId+1;
|
||||||
}
|
}
|
||||||
// go ackward and find if previous is the corect type (remove) \n and empty space ==> not comment they need to add it (wrong place but not may job ...
|
// go ackward and find if previous is the corect type (remove) \n and empty space ==> not comment they need to add it (wrong place but not may job ...
|
||||||
bool estyle::Generator::previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType) {
|
bool estyle::Generator::previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType) {
|
||||||
@ -414,6 +484,7 @@ bool estyle::Generator::previousIs(int64_t _pos, enum estyle::lexer::tocken _pre
|
|||||||
bool estyle::Generator::nextIs(int64_t _pos, enum estyle::lexer::tocken _nextType) {
|
bool estyle::Generator::nextIs(int64_t _pos, enum estyle::lexer::tocken _nextType) {
|
||||||
for (int32_t iii=_pos; iii<m_lexer.size(); ++iii) {
|
for (int32_t iii=_pos; iii<m_lexer.size(); ++iii) {
|
||||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(iii);
|
enum estyle::lexer::tocken elem = m_lexer.getTocken(iii);
|
||||||
|
ESTYLE_VERBOSE("check if next: " << _nextType << " on " << elem);
|
||||||
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -426,7 +497,7 @@ int64_t estyle::Generator::generateCondition(int64_t _pos) {
|
|||||||
int32_t sectionEnd = endOfSection(_pos);
|
int32_t sectionEnd = endOfSection(_pos);
|
||||||
int32_t nbCondition = countCurrentLevelCondition(_pos);
|
int32_t nbCondition = countCurrentLevelCondition(_pos);
|
||||||
if (nbCondition == 0) {
|
if (nbCondition == 0) {
|
||||||
process(_pos, sectionEnd+1);
|
process(_pos, sectionEnd);
|
||||||
} else {
|
} else {
|
||||||
m_output += "( ";
|
m_output += "( ";
|
||||||
offsetPush(5);
|
offsetPush(5);
|
||||||
@ -442,12 +513,13 @@ int64_t estyle::Generator::generateCondition(int64_t _pos) {
|
|||||||
offsetPush(5);
|
offsetPush(5);
|
||||||
m_output += " " + m_lexer.getData(iii) + " ";
|
m_output += " " + m_lexer.getData(iii) + " ";
|
||||||
} else {
|
} else {
|
||||||
iii = process(iii, sectionEnd, estyle::lexer::AND_AND, estyle::lexer::OR_OR, estyle::lexer::PARENTHESE_IN);
|
iii = process(iii, sectionEnd, estyle::lexer::AND_AND, estyle::lexer::OR_OR, estyle::lexer::PARENTHESE_IN, estyle::lexer::PARENTHESE_OUT);
|
||||||
iii--;
|
iii--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offsetPop();
|
offsetPop();
|
||||||
}
|
}
|
||||||
|
addSpace();
|
||||||
m_output += ")";
|
m_output += ")";
|
||||||
return sectionEnd;
|
return sectionEnd;
|
||||||
}
|
}
|
||||||
@ -456,19 +528,22 @@ int64_t estyle::Generator::generateFunction(int64_t _pos) {
|
|||||||
int32_t sectionEnd = endOfSection(_pos);
|
int32_t sectionEnd = endOfSection(_pos);
|
||||||
int32_t nbParameters = countCurrentParameters(_pos);
|
int32_t nbParameters = countCurrentParameters(_pos);
|
||||||
m_output += "(";
|
m_output += "(";
|
||||||
|
offsetPushAuto();
|
||||||
if (nbParameters == 0) {
|
if (nbParameters == 0) {
|
||||||
process(_pos + 1, sectionEnd);
|
process(_pos + 1, sectionEnd);
|
||||||
} else {
|
} else {
|
||||||
for (int64_t iii=_pos+1; iii<=sectionEnd; ++iii) {
|
for (int64_t iii=_pos+1; iii<=sectionEnd; ++iii) {
|
||||||
iii = process(iii, sectionEnd, estyle::lexer::COMA);
|
iii = process(iii, sectionEnd, estyle::lexer::COMA, estyle::lexer::PARENTHESE_OUT);
|
||||||
if (nextIs(iii, estyle::lexer::PARENTHESE_OUT) == false) {
|
if (nextIs(iii-1, estyle::lexer::PARENTHESE_OUT) == false) {
|
||||||
m_output += ",";
|
m_output += ",";
|
||||||
m_output += getEndOfLine();
|
m_output += getEndOfLine();
|
||||||
addSpace();
|
addSpace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addSpace();
|
||||||
m_output += ")";
|
m_output += ")";
|
||||||
|
offsetPop();
|
||||||
return sectionEnd;
|
return sectionEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,6 +574,22 @@ int64_t estyle::Generator::endOfSection(int64_t _pos) {
|
|||||||
}
|
}
|
||||||
return m_lexer.size();
|
return m_lexer.size();
|
||||||
}
|
}
|
||||||
|
int64_t estyle::Generator::endOfAction(int64_t _pos) {
|
||||||
|
ESTYLE_INFO(" " << m_lexer.getTocken(_pos) << " " << _pos << " [BEGIN]");
|
||||||
|
for (int64_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
|
||||||
|
enum estyle::lexer::tocken elem = m_lexer.getTocken(iii);
|
||||||
|
if (elem == estyle::lexer::SEMICOLON) {
|
||||||
|
return iii;
|
||||||
|
}
|
||||||
|
if ( elem == estyle::lexer::PARENTHESE_IN
|
||||||
|
|| elem == estyle::lexer::BRACKET_IN
|
||||||
|
|| elem == estyle::lexer::BRACE_IN) {
|
||||||
|
iii = endOfSection(iii);
|
||||||
|
return iii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_lexer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t estyle::Generator::countCurrent(int64_t _pos,
|
int32_t estyle::Generator::countCurrent(int64_t _pos,
|
||||||
@ -550,6 +641,11 @@ int32_t estyle::Generator::countCurrentParameters(int64_t _pos) {
|
|||||||
estyle::lexer::COMA);
|
estyle::lexer::COMA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t estyle::Generator::countCurrentAction(int64_t _pos) {
|
||||||
|
return countCurrent(_pos,
|
||||||
|
estyle::lexer::SEMICOLON);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t estyle::Generator::countCurrentLevelComa(int64_t _pos) {
|
int32_t estyle::Generator::countCurrentLevelComa(int64_t _pos) {
|
||||||
int32_t out = 0;
|
int32_t out = 0;
|
||||||
@ -603,3 +699,24 @@ int32_t estyle::Generator::getWhileCondition(int64_t _pos) {
|
|||||||
return m_lexer.size();
|
return m_lexer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
etk::String estyle::Generator::generateType(int64_t _pos) {
|
||||||
|
etk::String out;
|
||||||
|
enum estyle::lexer::tocken elem = m_lexer.getTocken(_pos);
|
||||||
|
if (elem == estyle::lexer::ELEMENT_COMPLEX_TYPE) {
|
||||||
|
etk::Vector<estyle::LexerElement> listElement = m_lexer.getSubList(_pos);
|
||||||
|
for (size_t iii=0; iii<listElement.size(); ++iii) {
|
||||||
|
enum estyle::lexer::tocken elem2 = listElement[iii].getTocken();
|
||||||
|
if (elem2 == estyle::lexer::RESERVED_NEW_LINE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (iii != 0) {
|
||||||
|
out += " ";
|
||||||
|
}
|
||||||
|
out += m_lexer.getDataSource(listElement[iii].getStart(), listElement[iii].getStop());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out = m_lexer.getData(_pos);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ namespace estyle {
|
|||||||
int32_t m_offset = 0; //!< number od space needed after the indentation (used for the if / else if / while / functions ....)
|
int32_t m_offset = 0; //!< number od space needed after the indentation (used for the if / else if / while / functions ....)
|
||||||
etk::Vector<int32_t> m_offsetStack;
|
etk::Vector<int32_t> m_offsetStack;
|
||||||
void offsetPush(int32_t _count);
|
void offsetPush(int32_t _count);
|
||||||
|
void offsetPushAuto();
|
||||||
void offsetPop();
|
void offsetPop();
|
||||||
|
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ namespace estyle {
|
|||||||
etk::String getDoxygenOneLine();
|
etk::String getDoxygenOneLine();
|
||||||
etk::String getDoxygenNLine(const etk::String& _data);
|
etk::String getDoxygenNLine(const etk::String& _data);
|
||||||
int64_t endOfSection(int64_t _pos);
|
int64_t endOfSection(int64_t _pos);
|
||||||
|
int64_t endOfAction(int64_t _pos);
|
||||||
int32_t countCurrent(int64_t _pos,
|
int32_t countCurrent(int64_t _pos,
|
||||||
enum estyle::lexer::tocken _type1,
|
enum estyle::lexer::tocken _type1,
|
||||||
enum estyle::lexer::tocken _type2 = estyle::lexer::END_OF_FILE,
|
enum estyle::lexer::tocken _type2 = estyle::lexer::END_OF_FILE,
|
||||||
@ -58,12 +60,14 @@ namespace estyle {
|
|||||||
enum estyle::lexer::tocken _type4 = estyle::lexer::END_OF_FILE);
|
enum estyle::lexer::tocken _type4 = estyle::lexer::END_OF_FILE);
|
||||||
int32_t countCurrentLevelCondition(int64_t _pos);
|
int32_t countCurrentLevelCondition(int64_t _pos);
|
||||||
int32_t countCurrentParameters(int64_t _pos);
|
int32_t countCurrentParameters(int64_t _pos);
|
||||||
|
int32_t countCurrentAction(int64_t _pos);
|
||||||
int64_t generateCondition(int64_t _pos);
|
int64_t generateCondition(int64_t _pos);
|
||||||
int64_t generateFunction(int64_t _pos);
|
int64_t generateFunction(int64_t _pos);
|
||||||
bool previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType);
|
bool previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType);
|
||||||
bool nextIs(int64_t _pos, enum estyle::lexer::tocken _nextType);
|
bool nextIs(int64_t _pos, enum estyle::lexer::tocken _nextType);
|
||||||
int32_t countCurrentLevelComa(int64_t _pos);
|
int32_t countCurrentLevelComa(int64_t _pos);
|
||||||
int32_t getWhileCondition(int64_t _pos);
|
int32_t getWhileCondition(int64_t _pos);
|
||||||
|
etk::String generateType(int64_t _pos);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,6 +394,9 @@ void estyle::Lexer::parse() {
|
|||||||
if (nextChar == '=') {
|
if (nextChar == '=') {
|
||||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::LESS_EQUAL, iii, iii+2));
|
m_list.pushBack(estyle::LexerElement(estyle::lexer::LESS_EQUAL, iii, iii+2));
|
||||||
iii++;
|
iii++;
|
||||||
|
} else if (nextChar == '<') {
|
||||||
|
m_list.pushBack(estyle::LexerElement(estyle::lexer::LESS_LESS, iii, iii+2));
|
||||||
|
iii++;
|
||||||
} else {
|
} else {
|
||||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::LESS, iii, iii+1));
|
m_list.pushBack(estyle::LexerElement(estyle::lexer::LESS, iii, iii+1));
|
||||||
}
|
}
|
||||||
@ -403,6 +406,9 @@ void estyle::Lexer::parse() {
|
|||||||
if (nextChar == '=') {
|
if (nextChar == '=') {
|
||||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::GREATER_EQUAL, iii, iii+2));
|
m_list.pushBack(estyle::LexerElement(estyle::lexer::GREATER_EQUAL, iii, iii+2));
|
||||||
iii++;
|
iii++;
|
||||||
|
} else if (nextChar == '>') {
|
||||||
|
m_list.pushBack(estyle::LexerElement(estyle::lexer::GREATER_GREATER, iii, iii+2));
|
||||||
|
iii++;
|
||||||
} else {
|
} else {
|
||||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::GREATER, iii, iii+1));
|
m_list.pushBack(estyle::LexerElement(estyle::lexer::GREATER, iii, iii+1));
|
||||||
}
|
}
|
||||||
@ -563,18 +569,32 @@ void estyle::Lexer::lexify(const etk::String& _input) {
|
|||||||
parse();
|
parse();
|
||||||
postAnnalyse_namespace();
|
postAnnalyse_namespace();
|
||||||
postAnnalyse_function();
|
postAnnalyse_function();
|
||||||
|
postAnnalyse_function_typeExtern();
|
||||||
|
postAnnalyse_function_typeInternal();
|
||||||
ESTYLE_DEBUG("find:");
|
ESTYLE_DEBUG("find:");
|
||||||
for (auto &it: m_list) {
|
for (auto &it: m_list) {
|
||||||
|
if ( it.getTocken() == estyle::lexer::ELEMENT_COMPLEX
|
||||||
|
|| it.getTocken() == estyle::lexer::ELEMENT_COMPLEX_TYPE) {
|
||||||
|
ESTYLE_DEBUG(" '" << it.getTocken() << "'");
|
||||||
|
for (auto &it2: it.getList()) {
|
||||||
|
ESTYLE_DEBUG(" '" << it2.getTocken() << "' ==> '" << m_stream.extract(it2.getStart(),it2.getStop()) << "'");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ESTYLE_DEBUG(" '" << it.getTocken() << "' ==> '" << m_stream.extract(it.getStart(),it.getStop()) << "'");
|
ESTYLE_DEBUG(" '" << it.getTocken() << "' ==> '" << m_stream.extract(it.getStart(),it.getStop()) << "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
etk::String estyle::Lexer::getDataSource(int32_t _start, int32_t _stop) const {
|
||||||
|
return m_stream.extract(_start, _stop);
|
||||||
|
}
|
||||||
|
|
||||||
etk::String estyle::Lexer::getData(int32_t _position) const {
|
etk::String estyle::Lexer::getData(int32_t _position) const {
|
||||||
return m_stream.extract(m_list[_position].getStart(), m_list[_position].getStop());
|
return getDataSource(m_list[_position].getStart(), m_list[_position].getStop());
|
||||||
}
|
}
|
||||||
|
|
||||||
etk::String estyle::Lexer::getValueString(int32_t _position) const {
|
etk::String estyle::Lexer::getValueString(int32_t _position) const {
|
||||||
return m_stream.extract(m_list[_position].getStart(), m_list[_position].getStop());
|
return getDataSource(m_list[_position].getStart(), m_list[_position].getStop());
|
||||||
}
|
}
|
||||||
|
|
||||||
ivec2 estyle::Lexer::getFilePosition(int32_t _position) const {
|
ivec2 estyle::Lexer::getFilePosition(int32_t _position) const {
|
||||||
@ -600,7 +620,7 @@ etk::String estyle::Lexer::getFileLine(int32_t _position) const {
|
|||||||
if (positionStart < 0) {
|
if (positionStart < 0) {
|
||||||
positionStart = 0;
|
positionStart = 0;
|
||||||
}
|
}
|
||||||
for (;positionStop< m_stream.size(); ++positionStop) {
|
for (;positionStop < int64_t(m_stream.size()); ++positionStop) {
|
||||||
if (m_stream[positionStop] == '\n') {
|
if (m_stream[positionStop] == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -666,3 +686,67 @@ void estyle::Lexer::postAnnalyse_function() {
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void estyle::Lexer::postAnnalyse_function_typeExtern() {
|
||||||
|
for (int64_t iii=0; iii<m_list.size(); ++iii) {
|
||||||
|
if (m_list[iii].getTocken() == estyle::lexer::ELEMENT_FUNCTION) {
|
||||||
|
ESTYLE_WARNING("Find function ==> check if we have a type : '" << getData(iii) << "'");
|
||||||
|
// search backward the first element availlable like const/ID/*/&/
|
||||||
|
int64_t end = iii;
|
||||||
|
for (int64_t jjj=iii-1; jjj>=0; --jjj) {
|
||||||
|
auto elem = m_list[jjj].getTocken();
|
||||||
|
if ( elem == estyle::lexer::BASIC_TYPE_INTEGER_SIZE_T
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_008
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_016
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_016_UNSIGNED
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_032
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_032_UNSIGNED
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_064
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_064_UNSIGNED
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_128
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_INTEGER_128_UNSIGNED
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_FLOAT_32
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_FLOAT_64
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_FLOAT_96
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_BOOLEAN
|
||||||
|
|| elem == estyle::lexer::BASIC_TYPE_VOID
|
||||||
|
|| elem == estyle::lexer::RESERVED_INT
|
||||||
|
|| elem == estyle::lexer::RESERVED_LONG
|
||||||
|
|| elem == estyle::lexer::RESERVED_SHORT
|
||||||
|
|| elem == estyle::lexer::RESERVED_SIGNED
|
||||||
|
|| elem == estyle::lexer::RESERVED_UNSIGNED
|
||||||
|
|| elem == estyle::lexer::RESERVED_CONST
|
||||||
|
|| elem == estyle::lexer::AND
|
||||||
|
|| elem == estyle::lexer::MULTIPLY
|
||||||
|
|| elem == estyle::lexer::GREATER
|
||||||
|
|| elem == estyle::lexer::GREATER_GREATER
|
||||||
|
|| elem == estyle::lexer::LESS
|
||||||
|
|| elem == estyle::lexer::RESERVED_NEW_LINE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// find the end
|
||||||
|
end = jjj+1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (end == iii) {
|
||||||
|
// Function call ...
|
||||||
|
} else {
|
||||||
|
estyle::LexerElement tmp = estyle::LexerElement(estyle::lexer::ELEMENT_COMPLEX_TYPE, m_list[end].getStart(), m_list[iii-1].getStop());
|
||||||
|
for (int64_t jjj=end; jjj<iii; ++jjj) {
|
||||||
|
tmp.pushElement(m_list[jjj]);
|
||||||
|
}
|
||||||
|
m_list[end] = tmp;
|
||||||
|
m_list.eraseLen(end+1, iii-end-1);
|
||||||
|
iii = end+1;
|
||||||
|
m_list[iii].setTocken(estyle::lexer::ELEMENT_FUNCTION_DECLARATION);
|
||||||
|
ESTYLE_WARNING(" ==> type: '" << getData(end) << "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void estyle::Lexer::postAnnalyse_function_typeInternal() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,16 @@ namespace estyle {
|
|||||||
void setStop(int32_t _pos) {
|
void setStop(int32_t _pos) {
|
||||||
m_stop = _pos;
|
m_stop = _pos;
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
//special case of complex element:
|
||||||
|
etk::Vector<estyle::LexerElement> m_list;
|
||||||
|
public:
|
||||||
|
void pushElement(const estyle::LexerElement& _element) {
|
||||||
|
m_list.pushBack(_element);
|
||||||
|
}
|
||||||
|
const etk::Vector<estyle::LexerElement>& getList() const {
|
||||||
|
return m_list;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class Lexer {
|
class Lexer {
|
||||||
private:
|
private:
|
||||||
@ -51,6 +61,8 @@ namespace estyle {
|
|||||||
// squash element name space like "::lklkmlk" and "lmkmlk::lmkmlk::mlklk" in 1 element
|
// squash element name space like "::lklkmlk" and "lmkmlk::lmkmlk::mlklk" in 1 element
|
||||||
void postAnnalyse_namespace();
|
void postAnnalyse_namespace();
|
||||||
void postAnnalyse_function();
|
void postAnnalyse_function();
|
||||||
|
void postAnnalyse_function_typeExtern();
|
||||||
|
void postAnnalyse_function_typeInternal();
|
||||||
public:
|
public:
|
||||||
int64_t size() const {
|
int64_t size() const {
|
||||||
return m_list.size();
|
return m_list.size();
|
||||||
@ -58,7 +70,11 @@ namespace estyle {
|
|||||||
enum estyle::lexer::tocken getTocken(int32_t _position) const {
|
enum estyle::lexer::tocken getTocken(int32_t _position) const {
|
||||||
return m_list[_position].getTocken();
|
return m_list[_position].getTocken();
|
||||||
}
|
}
|
||||||
|
const etk::Vector<estyle::LexerElement>& getSubList(int32_t _position) const {
|
||||||
|
return m_list[_position].getList();
|
||||||
|
}
|
||||||
etk::String getData(int32_t _position) const;
|
etk::String getData(int32_t _position) const;
|
||||||
|
etk::String getDataSource(int32_t _start, int32_t _stop) const;
|
||||||
etk::String getValueString(int32_t _position) const;
|
etk::String getValueString(int32_t _position) const;
|
||||||
ivec2 getFilePosition(int32_t _position) const;
|
ivec2 getFilePosition(int32_t _position) const;
|
||||||
etk::String getFileLine(int32_t _position) const;
|
etk::String getFileLine(int32_t _position) const;
|
||||||
|
@ -25,8 +25,10 @@ etk::String estyle::lexer::toString(estyle::lexer::tocken _token) {
|
|||||||
case estyle::lexer::NOT: return "!";
|
case estyle::lexer::NOT: return "!";
|
||||||
case estyle::lexer::NOT_EQUAL: return "!=";
|
case estyle::lexer::NOT_EQUAL: return "!=";
|
||||||
case estyle::lexer::LESS: return "<";
|
case estyle::lexer::LESS: return "<";
|
||||||
|
case estyle::lexer::LESS_LESS: return "<<";
|
||||||
case estyle::lexer::LESS_EQUAL: return "<=";
|
case estyle::lexer::LESS_EQUAL: return "<=";
|
||||||
case estyle::lexer::GREATER: return ">";
|
case estyle::lexer::GREATER: return ">";
|
||||||
|
case estyle::lexer::GREATER_GREATER: return ">>";
|
||||||
case estyle::lexer::GREATER_EQUAL: return ">=";
|
case estyle::lexer::GREATER_EQUAL: return ">=";
|
||||||
case estyle::lexer::PLUS: return "+";
|
case estyle::lexer::PLUS: return "+";
|
||||||
case estyle::lexer::MINUS: return "-";
|
case estyle::lexer::MINUS: return "-";
|
||||||
@ -124,6 +126,9 @@ etk::String estyle::lexer::toString(estyle::lexer::tocken _token) {
|
|||||||
case estyle::lexer::BASIC_TYPE_VOID: return "void";
|
case estyle::lexer::BASIC_TYPE_VOID: return "void";
|
||||||
|
|
||||||
case estyle::lexer::ELEMENT_FUNCTION: return "FUNCTION";
|
case estyle::lexer::ELEMENT_FUNCTION: return "FUNCTION";
|
||||||
|
case estyle::lexer::ELEMENT_FUNCTION_DECLARATION: return "FUNCTION_DECLARATION";
|
||||||
|
case estyle::lexer::ELEMENT_COMPLEX: return "COMPLEX";
|
||||||
|
case estyle::lexer::ELEMENT_COMPLEX_TYPE: return "COMPLEX_TYPE";
|
||||||
}
|
}
|
||||||
return etk::String("?[") + etk::toString(int32_t(_token)) + "]";
|
return etk::String("?[") + etk::toString(int32_t(_token)) + "]";
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,10 @@ namespace estyle {
|
|||||||
NOT, //!< element "!"
|
NOT, //!< element "!"
|
||||||
NOT_EQUAL, //!< element "!="
|
NOT_EQUAL, //!< element "!="
|
||||||
LESS, //!< element "<"
|
LESS, //!< element "<"
|
||||||
|
LESS_LESS, //!< element "<<"
|
||||||
LESS_EQUAL, //!< element "<="
|
LESS_EQUAL, //!< element "<="
|
||||||
GREATER, //!< element ">"
|
GREATER, //!< element ">"
|
||||||
|
GREATER_GREATER, //!< element ">>"
|
||||||
GREATER_EQUAL, //!< element ">="
|
GREATER_EQUAL, //!< element ">="
|
||||||
PLUS, //!< element "+"
|
PLUS, //!< element "+"
|
||||||
MINUS, //!< element "-"
|
MINUS, //!< element "-"
|
||||||
@ -131,8 +133,12 @@ namespace estyle {
|
|||||||
|
|
||||||
// post annalyse element:
|
// post annalyse element:
|
||||||
ELEMENT_FUNCTION, //!< all composed with an ID previous a (
|
ELEMENT_FUNCTION, //!< all composed with an ID previous a (
|
||||||
|
ELEMENT_FUNCTION_DECLARATION, //!< all composed with an ID previous a ( ==> and have a type on the left
|
||||||
|
|
||||||
|
|
||||||
|
ELEMENT_COMPLEX, //!< complex type with multiple tocken inside
|
||||||
|
ELEMENT_COMPLEX_TYPE, //!< complex type with multiple tocken inside
|
||||||
|
|
||||||
BASIC_TYPE_LIST_END,
|
BASIC_TYPE_LIST_END,
|
||||||
};
|
};
|
||||||
etk::String toString(estyle::lexer::tocken _token);
|
etk::String toString(estyle::lexer::tocken _token);
|
||||||
|
@ -61,7 +61,7 @@ TEST(testrestyle, test3) {
|
|||||||
|
|
||||||
|
|
||||||
etk::String source =
|
etk::String source =
|
||||||
"namespace aaa { namespace BBB { const unsigned int myFunction(int32_t& arg1, float** arg2, const double*& arg3=0x345aeF);const unsigned int myFunction(int32_t& arg1, float** arg2, const double*& arg3){ return 0;} } } if(aaa::BBB::myFunction(2452452345!=55 && 765432=5432,24523452354,\"43SFGDVEZT5R34EAQCWX\") == false && 235445 & 24545 == 'R') exit (-1); if (ploppp == 54) { return -T;}";
|
"namespace aaa { namespace BBB { const unsigned \n int myFunction(int32_t & arg1, float \t*\t\t* arg2, const\t \n double*\n& arg3=0x345aeF);const unsigned int myFunction(int32_t& arg1, float** arg2, const double*& arg3){ return 0;} } } if(aaa::BBB::myFunction(2452452345!=55 && 765432=5432,24523452354,\"43SFGDVEZT5R34EAQCWX\") == false && 235445 & 24545 == 'R') exit (-1); if (ploppp == 54) { return -T;}";
|
||||||
etk::String output = interface.process(source);
|
etk::String output = interface.process(source);
|
||||||
|
|
||||||
TEST_INFO("source:\n" << source);
|
TEST_INFO("source:\n" << source);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user