2007-05-24 15:09:23 +02:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "CommonCheck.h"
|
|
|
|
#include "tokenize.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2008-02-22 15:30:43 +01:00
|
|
|
#include <list>
|
|
|
|
#include <algorithm>
|
2007-05-24 15:09:23 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2007-07-18 08:12:16 +02:00
|
|
|
bool HasErrors;
|
2008-02-22 15:30:43 +01:00
|
|
|
bool OnlyReportUniqueErrors;
|
2008-02-16 16:46:32 +01:00
|
|
|
std::ostringstream errout;
|
2007-07-18 08:12:16 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2007-05-24 15:09:23 +02:00
|
|
|
|
2008-03-16 14:17:43 +01:00
|
|
|
std::string FileLine(const TOKEN *tok)
|
2007-05-24 15:09:23 +02:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "[" << Files[tok->FileIndex] << ":" << tok->linenr << "]";
|
|
|
|
return ostr.str();
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2008-02-22 15:30:43 +01:00
|
|
|
std::list<std::string> ErrorList;
|
|
|
|
|
2008-03-22 18:09:08 +01:00
|
|
|
void ReportErr(const std::string &errmsg)
|
2007-05-24 15:09:23 +02:00
|
|
|
{
|
2008-02-22 15:30:43 +01:00
|
|
|
if ( OnlyReportUniqueErrors )
|
|
|
|
{
|
|
|
|
if ( std::find( ErrorList.begin(), ErrorList.end(), errmsg ) != ErrorList.end() )
|
|
|
|
return;
|
|
|
|
ErrorList.push_back( errmsg );
|
|
|
|
}
|
2008-02-16 16:46:32 +01:00
|
|
|
errout << errmsg << std::endl;
|
2007-07-18 08:12:16 +02:00
|
|
|
HasErrors = true;
|
2007-05-24 15:09:23 +02:00
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2007-05-25 08:45:47 +02:00
|
|
|
bool IsName(const char str[])
|
|
|
|
{
|
|
|
|
return (str[0]=='_' || std::isalpha(str[0]));
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool IsNumber(const char str[])
|
|
|
|
{
|
|
|
|
return std::isdigit(str[0]);
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2007-07-20 08:20:31 +02:00
|
|
|
bool IsStandardType(const char str[])
|
|
|
|
{
|
|
|
|
if (!str)
|
|
|
|
return false;
|
|
|
|
bool Ret = false;
|
|
|
|
const char *type[] = {"bool","char","short","int","long","float","double",0};
|
|
|
|
for (int i = 0; type[i]; i++)
|
|
|
|
Ret |= (strcmp(str,type[i])==0);
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
2007-05-25 08:45:47 +02:00
|
|
|
|
2008-03-24 08:24:49 +01:00
|
|
|
const TOKEN *FindFunction( const TOKEN *tok, const char funcname[] )
|
2008-03-23 17:18:31 +01:00
|
|
|
{
|
|
|
|
int indentlevel = 0;
|
2008-03-24 08:24:49 +01:00
|
|
|
for ( ; tok; tok = tok->next )
|
2008-03-23 17:18:31 +01:00
|
|
|
{
|
|
|
|
if ( tok->str[0] == '{' )
|
|
|
|
indentlevel++;
|
|
|
|
|
|
|
|
else if ( tok->str[0] == '}' )
|
|
|
|
indentlevel--;
|
|
|
|
|
2008-03-24 08:24:49 +01:00
|
|
|
else if (indentlevel==0 && match(tok,"var ("))
|
2008-03-23 17:18:31 +01:00
|
|
|
{
|
|
|
|
// Check if this is the first token of a function implementation..
|
|
|
|
bool haspar = false;
|
|
|
|
bool foundname = false;
|
|
|
|
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next )
|
|
|
|
{
|
|
|
|
haspar |= bool(tok2->str[0] == '(');
|
|
|
|
if ( ! haspar && match(tok2,"var (") )
|
|
|
|
{
|
2008-03-24 08:24:49 +01:00
|
|
|
if ( funcname && strcmp(funcname, tok2->str) != 0 )
|
2008-03-23 17:18:31 +01:00
|
|
|
break;
|
|
|
|
foundname = true;
|
|
|
|
}
|
|
|
|
if ( tok2->str[0] == ';' )
|
2008-03-24 08:24:49 +01:00
|
|
|
{
|
|
|
|
tok = tok2;
|
2008-03-23 17:18:31 +01:00
|
|
|
break;
|
2008-03-24 08:24:49 +01:00
|
|
|
}
|
2008-03-23 17:18:31 +01:00
|
|
|
if ( tok2->str[0] == '{' )
|
|
|
|
break;
|
|
|
|
if ( foundname && haspar && match(tok2, ") {") )
|
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|