CTU: Add 'column'

This commit is contained in:
Daniel Marjamäki 2019-09-12 10:46:33 +02:00
parent 8855978f8a
commit b8e3d3b982
2 changed files with 27 additions and 19 deletions

View File

@ -32,8 +32,9 @@ static const char ATTR_CALL_ARGEXPR[] = "call-argexpr";
static const char ATTR_CALL_ARGVALUETYPE[] = "call-argvaluetype"; static const char ATTR_CALL_ARGVALUETYPE[] = "call-argvaluetype";
static const char ATTR_CALL_ARGVALUE[] = "call-argvalue"; static const char ATTR_CALL_ARGVALUE[] = "call-argvalue";
static const char ATTR_WARNING[] = "warning"; static const char ATTR_WARNING[] = "warning";
static const char ATTR_LOC_FILENAME[] = "filename"; static const char ATTR_LOC_FILENAME[] = "file";
static const char ATTR_LOC_LINENR[] = "linenr"; static const char ATTR_LOC_LINENR[] = "line";
static const char ATTR_LOC_COLUMN[] = "col";
static const char ATTR_INFO[] = "info"; static const char ATTR_INFO[] = "info";
static const char ATTR_MY_ID[] = "my-id"; static const char ATTR_MY_ID[] = "my-id";
static const char ATTR_MY_ARGNR[] = "my-argnr"; static const char ATTR_MY_ARGNR[] = "my-argnr";
@ -49,7 +50,8 @@ std::string CTU::getFunctionId(const Tokenizer *tokenizer, const Function *funct
CTU::FileInfo::Location::Location(const Tokenizer *tokenizer, const Token *tok) CTU::FileInfo::Location::Location(const Tokenizer *tokenizer, const Token *tok)
: fileName(tokenizer->list.file(tok)) : fileName(tokenizer->list.file(tok))
, linenr(tok->linenr()) , lineNumber(tok->linenr())
, column(tok->column())
{ {
} }
@ -77,7 +79,8 @@ std::string CTU::FileInfo::CallBase::toBaseXmlString() const
<< " " << ATTR_CALL_FUNCNAME << "=\"" << callFunctionName << "\"" << " " << ATTR_CALL_FUNCNAME << "=\"" << callFunctionName << "\""
<< " " << ATTR_CALL_ARGNR << "=\"" << callArgNr << "\"" << " " << ATTR_CALL_ARGNR << "=\"" << callArgNr << "\""
<< " " << ATTR_LOC_FILENAME << "=\"" << location.fileName << "\"" << " " << ATTR_LOC_FILENAME << "=\"" << location.fileName << "\""
<< " " << ATTR_LOC_LINENR << "=\"" << location.linenr << "\""; << " " << ATTR_LOC_LINENR << "=\"" << location.lineNumber << "\""
<< " " << ATTR_LOC_COLUMN << "=\"" << location.column << "\"";
return out.str(); return out.str();
} }
@ -99,6 +102,7 @@ std::string CTU::FileInfo::FunctionCall::toXmlString() const
out << " <path" out << " <path"
<< " " << ATTR_LOC_FILENAME << "=\"" << loc.getfile() << "\"" << " " << ATTR_LOC_FILENAME << "=\"" << loc.getfile() << "\""
<< " " << ATTR_LOC_LINENR << "=\"" << loc.line << "\"" << " " << ATTR_LOC_LINENR << "=\"" << loc.line << "\""
<< " " << ATTR_LOC_COLUMN << "=\"" << loc.column << "\""
<< " " << ATTR_INFO << "=\"" << loc.getinfo() << "\"/>\n"; << " " << ATTR_INFO << "=\"" << loc.getinfo() << "\"/>\n";
out << "</function-call>"; out << "</function-call>";
} }
@ -124,7 +128,8 @@ std::string CTU::FileInfo::UnsafeUsage::toString() const
<< " " << ATTR_MY_ARGNR << "=\"" << myArgNr << '\"' << " " << ATTR_MY_ARGNR << "=\"" << myArgNr << '\"'
<< " " << ATTR_MY_ARGNAME << "=\"" << myArgumentName << '\"' << " " << ATTR_MY_ARGNAME << "=\"" << myArgumentName << '\"'
<< " " << ATTR_LOC_FILENAME << "=\"" << location.fileName << '\"' << " " << ATTR_LOC_FILENAME << "=\"" << location.fileName << '\"'
<< " " << ATTR_LOC_LINENR << "=\"" << location.linenr << '\"' << " " << ATTR_LOC_LINENR << "=\"" << location.lineNumber << '\"'
<< " " << ATTR_LOC_COLUMN << "=\"" << location.column << '\"'
<< " " << ATTR_VALUE << "=\"" << value << "\"" << " " << ATTR_VALUE << "=\"" << value << "\""
<< "/>\n"; << "/>\n";
return out.str(); return out.str();
@ -176,7 +181,8 @@ bool CTU::FileInfo::CallBase::loadBaseFromXml(const tinyxml2::XMLElement *xmlEle
callFunctionName = readAttrString(xmlElement, ATTR_CALL_FUNCNAME, &error); callFunctionName = readAttrString(xmlElement, ATTR_CALL_FUNCNAME, &error);
callArgNr = readAttrInt(xmlElement, ATTR_CALL_ARGNR, &error); callArgNr = readAttrInt(xmlElement, ATTR_CALL_ARGNR, &error);
location.fileName = readAttrString(xmlElement, ATTR_LOC_FILENAME, &error); location.fileName = readAttrString(xmlElement, ATTR_LOC_FILENAME, &error);
location.linenr = readAttrInt(xmlElement, ATTR_LOC_LINENR, &error); location.lineNumber = readAttrInt(xmlElement, ATTR_LOC_LINENR, &error);
location.column = readAttrInt(xmlElement, ATTR_LOC_COLUMN, &error);
return !error; return !error;
} }
@ -196,6 +202,7 @@ bool CTU::FileInfo::FunctionCall::loadFromXml(const tinyxml2::XMLElement *xmlEle
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(readAttrString(e2, ATTR_LOC_FILENAME, &error)); loc.setfile(readAttrString(e2, ATTR_LOC_FILENAME, &error));
loc.line = readAttrInt(e2, ATTR_LOC_LINENR, &error); loc.line = readAttrInt(e2, ATTR_LOC_LINENR, &error);
loc.column = readAttrInt(e2, ATTR_LOC_COLUMN, &error);
loc.setinfo(readAttrString(e2, ATTR_INFO, &error)); loc.setinfo(readAttrString(e2, ATTR_INFO, &error));
} }
return !error; return !error;
@ -248,7 +255,8 @@ std::list<CTU::FileInfo::UnsafeUsage> CTU::loadUnsafeUsageListFromXml(const tiny
unsafeUsage.myArgNr = readAttrInt(e, ATTR_MY_ARGNR, &error); unsafeUsage.myArgNr = readAttrInt(e, ATTR_MY_ARGNR, &error);
unsafeUsage.myArgumentName = readAttrString(e, ATTR_MY_ARGNAME, &error); unsafeUsage.myArgumentName = readAttrString(e, ATTR_MY_ARGNAME, &error);
unsafeUsage.location.fileName = readAttrString(e, ATTR_LOC_FILENAME, &error); unsafeUsage.location.fileName = readAttrString(e, ATTR_LOC_FILENAME, &error);
unsafeUsage.location.linenr = readAttrInt(e, ATTR_LOC_LINENR, &error); unsafeUsage.location.lineNumber = readAttrInt(e, ATTR_LOC_LINENR, &error);
unsafeUsage.location.column = readAttrInt(e, ATTR_LOC_COLUMN, &error);
unsafeUsage.value = readAttrInt(e, ATTR_VALUE, &error); unsafeUsage.value = readAttrInt(e, ATTR_VALUE, &error);
if (!error) if (!error)
@ -317,8 +325,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
functionCall.callValueType = value.valueType; functionCall.callValueType = value.valueType;
functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function()); functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function());
functionCall.callFunctionName = tok->astOperand1()->expressionString(); functionCall.callFunctionName = tok->astOperand1()->expressionString();
functionCall.location.fileName = tokenizer->list.file(tok); functionCall.location = FileInfo::Location(tokenizer,tok);
functionCall.location.linenr = tok->linenr();
functionCall.callArgNr = argnr + 1; functionCall.callArgNr = argnr + 1;
functionCall.callArgumentExpression = argtok->expressionString(); functionCall.callArgumentExpression = argtok->expressionString();
functionCall.callArgValue = value.intvalue; functionCall.callArgValue = value.intvalue;
@ -327,6 +334,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(tokenizer->list.file(i.first)); loc.setfile(tokenizer->list.file(i.first));
loc.line = i.first->linenr(); loc.line = i.first->linenr();
loc.column = i.first->column();
loc.setinfo(i.second); loc.setinfo(i.second);
functionCall.callValuePath.push_back(loc); functionCall.callValuePath.push_back(loc);
} }
@ -338,8 +346,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
functionCall.callValueType = ValueFlow::Value::ValueType::BUFFER_SIZE; functionCall.callValueType = ValueFlow::Value::ValueType::BUFFER_SIZE;
functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function()); functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function());
functionCall.callFunctionName = tok->astOperand1()->expressionString(); functionCall.callFunctionName = tok->astOperand1()->expressionString();
functionCall.location.fileName = tokenizer->list.file(tok); functionCall.location = FileInfo::Location(tokenizer, tok);
functionCall.location.linenr = tok->linenr();
functionCall.callArgNr = argnr + 1; functionCall.callArgNr = argnr + 1;
functionCall.callArgumentExpression = argtok->expressionString(); functionCall.callArgumentExpression = argtok->expressionString();
functionCall.callArgValue = argtok->variable()->dimension(0) * argtok->valueType()->typeSize(*tokenizer->getSettings()); functionCall.callArgValue = argtok->variable()->dimension(0) * argtok->valueType()->typeSize(*tokenizer->getSettings());
@ -352,8 +359,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
functionCall.callValueType = ValueFlow::Value::ValueType::BUFFER_SIZE; functionCall.callValueType = ValueFlow::Value::ValueType::BUFFER_SIZE;
functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function()); functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function());
functionCall.callFunctionName = tok->astOperand1()->expressionString(); functionCall.callFunctionName = tok->astOperand1()->expressionString();
functionCall.location.fileName = tokenizer->list.file(tok); functionCall.location = FileInfo::Location(tokenizer, tok);
functionCall.location.linenr = tok->linenr();
functionCall.callArgNr = argnr + 1; functionCall.callArgNr = argnr + 1;
functionCall.callArgumentExpression = argtok->expressionString(); functionCall.callArgumentExpression = argtok->expressionString();
functionCall.callArgValue = argtok->astOperand1()->valueType()->typeSize(*tokenizer->getSettings()); functionCall.callArgValue = argtok->astOperand1()->valueType()->typeSize(*tokenizer->getSettings());
@ -374,8 +380,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
functionCall.callValueType = ValueFlow::Value::ValueType::UNINIT; functionCall.callValueType = ValueFlow::Value::ValueType::UNINIT;
functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function()); functionCall.callId = getFunctionId(tokenizer, tok->astOperand1()->function());
functionCall.callFunctionName = tok->astOperand1()->expressionString(); functionCall.callFunctionName = tok->astOperand1()->expressionString();
functionCall.location.fileName = tokenizer->list.file(tok); functionCall.location = FileInfo::Location(tokenizer, tok);
functionCall.location.linenr = tok->linenr();
functionCall.callArgNr = argnr + 1; functionCall.callArgNr = argnr + 1;
functionCall.callArgValue = 0; functionCall.callArgValue = 0;
functionCall.callArgumentExpression = argtok->expressionString(); functionCall.callArgumentExpression = argtok->expressionString();
@ -543,14 +548,16 @@ std::list<ErrorLogger::ErrorMessage::FileLocation> CTU::FileInfo::getErrorPath(I
ErrorLogger::ErrorMessage::FileLocation fileLoc; ErrorLogger::ErrorMessage::FileLocation fileLoc;
fileLoc.setfile(path[index]->location.fileName); fileLoc.setfile(path[index]->location.fileName);
fileLoc.line = path[index]->location.linenr; fileLoc.line = path[index]->location.lineNumber;
fileLoc.column = path[index]->location.column;
fileLoc.setinfo("Calling function " + path[index]->callFunctionName + ", " + MathLib::toString(path[index]->callArgNr) + getOrdinalText(path[index]->callArgNr) + " argument is " + value1); fileLoc.setinfo("Calling function " + path[index]->callFunctionName + ", " + MathLib::toString(path[index]->callArgNr) + getOrdinalText(path[index]->callArgNr) + " argument is " + value1);
locationList.push_back(fileLoc); locationList.push_back(fileLoc);
} }
ErrorLogger::ErrorMessage::FileLocation fileLoc2; ErrorLogger::ErrorMessage::FileLocation fileLoc2;
fileLoc2.setfile(unsafeUsage.location.fileName); fileLoc2.setfile(unsafeUsage.location.fileName);
fileLoc2.line = unsafeUsage.location.linenr; fileLoc2.line = unsafeUsage.location.lineNumber;
fileLoc2.column = unsafeUsage.location.column;
fileLoc2.setinfo(replaceStr(info, "ARG", unsafeUsage.myArgumentName)); fileLoc2.setinfo(replaceStr(info, "ARG", unsafeUsage.myArgumentName));
locationList.push_back(fileLoc2); locationList.push_back(fileLoc2);

View File

@ -40,9 +40,10 @@ namespace CTU {
struct Location { struct Location {
Location() = default; Location() = default;
Location(const Tokenizer *tokenizer, const Token *tok); Location(const Tokenizer *tokenizer, const Token *tok);
Location(const std::string &fileName, nonneg int linenr) : fileName(fileName), linenr(linenr) {} Location(const std::string &fileName, nonneg int lineNumber, nonneg int column) : fileName(fileName), lineNumber(lineNumber), column(column) {}
std::string fileName; std::string fileName;
nonneg int linenr; nonneg int lineNumber;
nonneg int column;
}; };
struct UnsafeUsage { struct UnsafeUsage {