Fixed icheck build.

This commit is contained in:
Erik Verbruggen
2010-04-23 15:25:05 +02:00
parent 25837759ea
commit a8fc1f48d4
4 changed files with 206 additions and 231 deletions

View File

@@ -622,11 +622,12 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type, unsigned
(void) switchDocument(previousDoc); (void) switchDocument(previousDoc);
#else #else
(void) switchDocument(previousDoc);
Document::CheckMode mode = Document::FastCheck; Document::CheckMode mode = Document::FastCheck;
mode = Document::FullCheck; mode = Document::FullCheck;
doc->parse(); doc->parse();
doc->check(mode); doc->check(mode);
(void) switchDocument(previousDoc);
#endif #endif
} }

View File

@@ -1,6 +1,7 @@
# ---------------------------------------------------- # ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in. # This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------ # ------------------------------------------------------
HEADERS += \ HEADERS += \
$$REL_PATH_TO_SRC/shared/cplusplus/AST.h \ $$REL_PATH_TO_SRC/shared/cplusplus/AST.h \
$$REL_PATH_TO_SRC/shared/cplusplus/ASTMatcher.h \ $$REL_PATH_TO_SRC/shared/cplusplus/ASTMatcher.h \
@@ -57,7 +58,8 @@ HEADERS += \
$$REL_PATH_TO_SRC/shared/cplusplus/TypeMatcher.h \ $$REL_PATH_TO_SRC/shared/cplusplus/TypeMatcher.h \
$$REL_PATH_TO_SRC/libs/cplusplus/TypePrettyPrinter.h \ $$REL_PATH_TO_SRC/libs/cplusplus/TypePrettyPrinter.h \
$$REL_PATH_TO_SRC/shared/cplusplus/TypeVisitor.h \ $$REL_PATH_TO_SRC/shared/cplusplus/TypeVisitor.h \
$$REL_PATH_TO_SRC/plugins/cpptools/cpptools_global.h $$REL_PATH_TO_SRC/plugins/cpptools/cpptools_global.h \
$$REL_PATH_TO_SRC/shared/cplusplus/QtContextKeywords.h
SOURCES += \ SOURCES += \
$$REL_PATH_TO_SRC/shared/cplusplus/AST.cpp \ $$REL_PATH_TO_SRC/shared/cplusplus/AST.cpp \
$$REL_PATH_TO_SRC/shared/cplusplus/ASTMatch0.cpp \ $$REL_PATH_TO_SRC/shared/cplusplus/ASTMatch0.cpp \
@@ -113,4 +115,5 @@ SOURCES += \
$$REL_PATH_TO_SRC/shared/cplusplus/Type.cpp \ $$REL_PATH_TO_SRC/shared/cplusplus/Type.cpp \
$$REL_PATH_TO_SRC/shared/cplusplus/TypeMatcher.cpp \ $$REL_PATH_TO_SRC/shared/cplusplus/TypeMatcher.cpp \
$$REL_PATH_TO_SRC/libs/cplusplus/TypePrettyPrinter.cpp \ $$REL_PATH_TO_SRC/libs/cplusplus/TypePrettyPrinter.cpp \
$$REL_PATH_TO_SRC/shared/cplusplus/TypeVisitor.cpp $$REL_PATH_TO_SRC/shared/cplusplus/TypeVisitor.cpp \
$$REL_PATH_TO_SRC/shared/cplusplus/QtContextKeywords.cpp

View File

@@ -30,6 +30,10 @@
#include "parsemanager.h" #include "parsemanager.h"
#include "cplusplus/CppDocument.h" #include "cplusplus/CppDocument.h"
#include "Control.h" #include "Control.h"
#include "Literals.h"
#include "Overview.h"
#include "Scope.h"
#include "Semantic.h"
#include "TranslationUnit.h" #include "TranslationUnit.h"
#include "AST.h" #include "AST.h"
#include "Symbols.h" #include "Symbols.h"
@@ -68,48 +72,52 @@ Q_PROPERTY( ConnectionState state READ state NOTIFY stateChanged);
******************************************************************/ ******************************************************************/
bool PROPERTYITEM::isEqualTo(PROPERTYITEM *cpppt) bool PROPERTYITEM::isEqualTo(PROPERTYITEM *cpppt)
{ {
QString thistype = this->trlUnit->spell(this->ast->type_token); if (!ast->type_id || !cpppt->ast->type_id)
QString cppttype = cpppt->trlUnit->spell(cpppt->ast->type_token); return false;
if (type != cpppt->type)
if(thistype != cppttype)
return false; return false;
QString thistypename = this->trlUnit->spell(this->ast->type_name_token); if (!ast->property_name || !ast->property_name->name || !ast->property_name->name->identifier())
QString cppttypename = cpppt->trlUnit->spell(cpppt->ast->type_name_token); return false;
QString thistypename = ast->property_name->name->identifier()->chars();
if (!cpppt->ast->property_name || !cpppt->ast->property_name->name || !cpppt->ast->property_name->name->identifier())
return false;
QString cppttypename = cpppt->ast->property_name->name->identifier()->chars();
if(thistypename != cppttypename) if(thistypename != cppttypename)
return false; return false;
if(this->readdefined != cpppt->readdefined) if ((this->readAst == 0) != (cpppt->readAst == 0))
return false; return false;
if(this->writedefined != cpppt->writedefined) if((this->writeAst == 0) != (cpppt->writeAst == 0))
return false; return false;
if(this->resetdefined != cpppt->resetdefined) if((this->resetAst == 0) != (cpppt->resetAst == 0))
return false; return false;
if(this->notifydefined != cpppt->notifydefined) if((this->notifyAst == 0) != (cpppt->notifyAst == 0))
return false; return false;
//check for read function //check for read function
if(this->readdefined){ if(this->readAst){
if(!this->readFct || !cpppt->readFct) if(!this->readFct || !cpppt->readFct)
return false; return false;
if(!this->readFct->isEqualTo(cpppt->readFct)) if(!this->readFct->isEqualTo(cpppt->readFct))
return false; return false;
} }
//check for write function //check for write function
if(this->writedefined){ if(this->writeAst){
if(!this->writeFct || !cpppt->writeFct) if(!this->writeFct || !cpppt->writeFct)
return false; return false;
if(!this->writeFct->isEqualTo(cpppt->writeFct)) if(!this->writeFct->isEqualTo(cpppt->writeFct))
return false; return false;
} }
//check for reset function //check for reset function
if(this->resetdefined){ if(this->resetAst){
if(!this->resetFct || !cpppt->resetFct) if(!this->resetFct || !cpppt->resetFct)
return false; return false;
if(!this->resetFct->isEqualTo(cpppt->resetFct)) if(!this->resetFct->isEqualTo(cpppt->resetFct))
return false; return false;
} }
//check for notify function //check for notify function
if(this->notifydefined){ if(this->notifyAst){
if(!this->notifyFct || !cpppt->notifyFct) if(!this->notifyFct || !cpppt->notifyFct)
return false; return false;
if(!this->notifyFct->isEqualTo(cpppt->notifyFct)) if(!this->notifyFct->isEqualTo(cpppt->notifyFct))
@@ -380,9 +388,8 @@ void ParseManager::getElements(QList<FUNCTIONITEM*> &functionlist
/********** /**********
Functions Functions
**********/ **********/
FunctionDefinitionAST *pfctdef = pmemberlist->value->asFunctionDefinition(); if (FunctionDefinitionAST *pfctdef = pmemberlist->value->asFunctionDefinition()){
if(pfctdef){ FUNCTIONITEM* item = new FUNCTIONITEM;
FUNCTIONITEM* item = new FUNCTIONITEM();
item->trlUnit = classitem->trlUnit; item->trlUnit = classitem->trlUnit;
item->function = pfctdef->symbol; item->function = pfctdef->symbol;
item->classAst = classitem->classspec; item->classAst = classitem->classspec;
@@ -427,64 +434,46 @@ void ParseManager::getElements(QList<FUNCTIONITEM*> &functionlist
/********** /**********
Q_PROPERTY Q_PROPERTY
**********/ **********/
QPropertyDeclarationAST *ppdecl = pmemberlist->value->asQPropertyDeclarationAST(); if(QtPropertyDeclarationAST *ppdecl = pmemberlist->value->asQtPropertyDeclaration()) {
if(ppdecl){ propertylist.push_back(PROPERTYITEM::create(ppdecl, highestlevelclass));
PROPERTYITEM* item = new PROPERTYITEM(); if (ppdecl->property_name && ppdecl->property_name->name && ppdecl->property_name->name->identifier()) {
item->ast = ppdecl; Trace(" - Q_PROPERTY: " + QLatin1String(ppdecl->property_name->name->identifier()->chars()) + " found");
item->highestlevelclass = highestlevelclass;
item->trlUnit = classitem->trlUnit;
item->readdefined = (ppdecl->read_token > 0);
item->writedefined = (ppdecl->write_token > 0);
item->resetdefined = (ppdecl->reset_token > 0);
item->notifydefined = (ppdecl->notify_token > 0);
propertylist.push_back(item);
if(item->ast->type_name_token > 0){
QString propertyname = item->trlUnit->spell(item->ast->type_name_token);
Trace(" - Q_PROPERTY: " + classname + "::" + propertyname + " found");
} }
} } else{
else{
/********** /**********
Q_ENUM Q_ENUM
**********/ **********/
QEnumDeclarationAST *pqenum = pmemberlist->value->asQEnumDeclarationAST(); if (QtEnumDeclarationAST *pqenum = pmemberlist->value->asQtEnumDeclaration()) {
if(pqenum){ for (NameListAST *plist = pqenum->enumerator_list; plist; plist = plist->next) {
if(pqenum->enumerator_list){ QENUMITEM* item = new QENUMITEM;
for (EnumeratorListAST *plist = pqenum->enumerator_list; plist; plist = plist->next) { item->name = plist->value->name->identifier()->chars();
QENUMITEM* item = new QENUMITEM();
item->ast = plist->value;
item->highestlevelclass = highestlevelclass; item->highestlevelclass = highestlevelclass;
item->trlUnit = classitem->trlUnit;
qenumlist.push_back(item); qenumlist.push_back(item);
QString enumname = item->trlUnit->spell(item->ast->firstToken()); Trace(" - Q_ENUM: " + classname + "::" + item->name + " found");
Trace(" - Q_ENUM: " + classname + "::" + enumname + " found");
} }
} }
}
else{ else{
/********** /**********
Q_FLAGS Q_FLAGS
**********/ **********/
QFlagsDeclarationAST *pqflags = pmemberlist->value->asQFlagsDeclarationAST(); if (QtFlagsDeclarationAST *pqflags = pmemberlist->value->asQtFlagsDeclaration()){
if(pqflags){ for (NameListAST *plist = pqflags->flag_enums_list; plist; plist = plist->next) {
if(pqflags->enumerator_list){ QFLAGITEM* item = new QFLAGITEM;
for (EnumeratorListAST *plist = pqflags->enumerator_list; plist; plist = plist->next) { item->name = plist->value->name;
QFLAGITEM* item = new QFLAGITEM();
item->ast = plist->value;
item->highestlevelclass = highestlevelclass; item->highestlevelclass = highestlevelclass;
item->trlUnit = classitem->trlUnit;
qflaglist.push_back(item); qflaglist.push_back(item);
QString enumname = item->trlUnit->spell(plist->firstToken()); Trace(" - Q_FLAGS: " + classname + "::" + item->name->identifier()->chars() + " found");
Trace(" - Q_FLAGS: " + classname + "::" + enumname + " found");
}
} }
} }
#if 0
The code for Q_DECLARE_FLAGS was wrong. It's optional, and only does a typedef.
That means, if you do the typedef yourself and not use Q_DECLARE_FLAGS, that *is* valid.
Meaning, if one would want to do a check like the ones in this app, one has to check the defined types in the class scope.
else { else {
/**************** /****************
Q_DECLARE_FLAGS Q_DECLARE_FLAGS
****************/ ****************/
QDeclareFlagsDeclarationAST *pqdeclflags = pmemberlist->value->asQDeclareFlagsDeclarationAST(); QtDeclareFlagsDeclarationAST *pqdeclflags = pmemberlist->value->asQDeclareFlagsDeclarationAST();
if(pqdeclflags){ if(pqdeclflags){
QDECLAREFLAGSITEM* item = new QDECLAREFLAGSITEM(); QDECLAREFLAGSITEM* item = new QDECLAREFLAGSITEM();
item->ast = pqdeclflags; item->ast = pqdeclflags;
@@ -493,6 +482,7 @@ void ParseManager::getElements(QList<FUNCTIONITEM*> &functionlist
qdeclareflaglist.push_back(item); qdeclareflaglist.push_back(item);
} }
} }
#endif
} }
} }
} }
@@ -841,8 +831,6 @@ QStringList ParseManager::getErrorMessage(FUNCTIONITEM* fct)
fctstring += "::"; fctstring += "::";
unsigned int token = fct->function->sourceLocation() - 1; unsigned int token = fct->function->sourceLocation() - 1;
if(token >= 0){
//tok.isNot(T_EOF_SYMBOL)
while(fct->trlUnit->tokenAt(token).isNot(T_EOF_SYMBOL)){ while(fct->trlUnit->tokenAt(token).isNot(T_EOF_SYMBOL)){
fctstring += fct->trlUnit->tokenAt(token).spell(); fctstring += fct->trlUnit->tokenAt(token).spell();
if(*fct->trlUnit->tokenAt(token).spell() == ')') if(*fct->trlUnit->tokenAt(token).spell() == ')')
@@ -850,7 +838,6 @@ QStringList ParseManager::getErrorMessage(FUNCTIONITEM* fct)
fctstring += " "; fctstring += " ";
token++; token++;
} }
}
Function* pfct = fct->function; Function* pfct = fct->function;
if(pfct){ if(pfct){
@@ -925,7 +912,7 @@ QList<PROPERTYITEM*> ParseManager::checkMetadataProperties(const QList<QList<PRO
else { else {
foreach(PROPERTYITEM *pprop, ipropertylist){ foreach(PROPERTYITEM *pprop, ipropertylist){
pprop->classWichIsNotFound << "<all classes>"; pprop->classWichIsNotFound << "<all classes>";
QString name = pprop->trlUnit->spell(pprop->ast->type_name_token); QString name = pprop->ast->property_name->name->identifier()->chars();
Trace("- Property: <all classes>::" + name + " not found!"); Trace("- Property: <all classes>::" + name + " not found!");
} }
ippts.append(ipropertylist); ippts.append(ipropertylist);
@@ -935,6 +922,15 @@ QList<PROPERTYITEM*> ParseManager::checkMetadataProperties(const QList<QList<PRO
return missingiprops; return missingiprops;
} }
static QString findName(ExpressionAST *ast)
{
// The "old" icheck code assumed that functions were only a single identifier, so I'll assume the same:
if (NameAST *nameAST = ast->asName())
return nameAST->name->identifier()->chars();
else
return QString();
}
/************************************** /**************************************
Function that resolves the dependensies Function that resolves the dependensies
between Q_PROPERTY between Q_PROPERTY
@@ -944,28 +940,26 @@ functions.
void ParseManager::assignPropertyFunctions(PROPERTYITEM* prop, const QList<QList<FUNCTIONITEM*> > &fctlookuplist) void ParseManager::assignPropertyFunctions(PROPERTYITEM* prop, const QList<QList<FUNCTIONITEM*> > &fctlookuplist)
{ {
//get the name of the needed functions //get the name of the needed functions
QString type;
QString readfctname; QString readfctname;
QString writefctname; QString writefctname;
QString resetfctname; QString resetfctname;
QString notifyfctname; QString notifyfctname;
int needtofind = 0; int needtofind = 0;
type = prop->trlUnit->spell(prop->ast->type_token); if(prop->readAst){
if(prop->readdefined){ readfctname = findName(prop->readAst);
readfctname = prop->trlUnit->spell(prop->ast->read_function_token);
needtofind++; needtofind++;
} }
if(prop->writedefined){ if(prop->writeAst){
writefctname = prop->trlUnit->spell(prop->ast->write_function_token); writefctname = findName(prop->writeAst);
needtofind++; needtofind++;
} }
if(prop->resetdefined){ if(prop->resetAst){
resetfctname = prop->trlUnit->spell(prop->ast->reset_function_token); resetfctname = findName(prop->resetAst);
needtofind++; needtofind++;
} }
if(prop->notifydefined){ if(prop->notifyAst){
notifyfctname = prop->trlUnit->spell(prop->ast->notify_function_token); notifyfctname = findName(prop->notifyAst);
needtofind++; needtofind++;
} }
//Now iterate over all function to find all functions wich are defined in the Q_PROPERTY macro //Now iterate over all function to find all functions wich are defined in the Q_PROPERTY macro
@@ -975,24 +969,24 @@ void ParseManager::assignPropertyFunctions(PROPERTYITEM* prop, const QList<QList
foreach(FUNCTIONITEM* pfct, fctlist){ foreach(FUNCTIONITEM* pfct, fctlist){
QString fctname = pfct->trlUnit->spell(pfct->function->sourceLocation()); QString fctname = pfct->trlUnit->spell(pfct->function->sourceLocation());
//check the function type against the property type //check the function type against the property type
QString fcttype =pfct->trlUnit->spell(pfct->function->sourceLocation() - 1); FullySpecifiedType retTy = pfct->function->returnType();
if(fctname.length() > 0 && fcttype.length() > 0){ if (!fctname.isEmpty() && retTy.isValid()) {
if(prop->readdefined && fctname == readfctname){ if(prop->readAst && fctname == readfctname){
if(type != fcttype) if (prop->type != retTy)
continue; continue;
prop->readFct = pfct; prop->readFct = pfct;
needtofind--; needtofind--;
} }
if(prop->writedefined && fctname == writefctname){ if(prop->writeAst && fctname == writefctname){
prop->writeFct = pfct; prop->writeFct = pfct;
needtofind--; needtofind--;
} }
if(prop->resetdefined && fctname == resetfctname){ if(prop->resetAst && fctname == resetfctname){
prop->resetFct = pfct; prop->resetFct = pfct;
needtofind--; needtofind--;
} }
if(prop->notifydefined && fctname == notifyfctname){ if(prop->notifyAst && fctname == notifyfctname){
prop->notifyFct = pfct; prop->notifyFct = pfct;
needtofind--; needtofind--;
} }
@@ -1033,7 +1027,7 @@ QList<PROPERTYITEM*> ParseManager::containsAllPropertyFunction(const QList<PROPE
if(propt->isEqualTo(ipropt)){ if(propt->isEqualTo(ipropt)){
found = true; found = true;
missingimplinclasses.clear(); missingimplinclasses.clear();
Trace("- Property: " + classname + "::" + propt->trlUnit->spell(propt->ast->type_name_token) + " found"); Trace("- Property: " + classname + "::" + propt->ast->property_name->name->identifier()->chars() + " found");
break; break;
} }
} }
@@ -1041,12 +1035,13 @@ QList<PROPERTYITEM*> ParseManager::containsAllPropertyFunction(const QList<PROPE
ipropt->classWichIsNotFound.append(missingimplinclasses); ipropt->classWichIsNotFound.append(missingimplinclasses);
ret.push_back(ipropt); ret.push_back(ipropt);
QString classname = ipropt->trlUnit->spell(ipropt->highestlevelclass->classspec->name->firstToken()); QString classname = ipropt->trlUnit->spell(ipropt->highestlevelclass->classspec->name->firstToken());
Trace("- Property: " + classname + "::" + ipropt->trlUnit->spell(ipropt->ast->type_name_token) + " not found!"); Trace("- Property: " + classname + "::" + ipropt->ast->property_name->name->identifier()->chars() + " not found!");
} }
} }
else{ else{
QString classname = ipropt->trlUnit->spell(ipropt->highestlevelclass->classspec->name->firstToken()); QString classname = ipropt->trlUnit->spell(ipropt->highestlevelclass->classspec->name->firstToken());
QString proptype = ipropt->trlUnit->spell(ipropt->ast->type_name_token); Overview oo;
QString proptype = oo(ipropt->type);
Trace("- Property: " + classname + "::" + proptype + " functions are missing!"); Trace("- Property: " + classname + "::" + proptype + " functions are missing!");
ret.push_back(ipropt); ret.push_back(ipropt);
} }
@@ -1080,13 +1075,13 @@ QStringList ParseManager::getErrorMessage(PROPERTYITEM* ppt)
out << ppt->trlUnit->spell(i) << " "; out << ppt->trlUnit->spell(i) << " ";
} }
out << endl << " -"; out << endl << " -";
if(ppt->readdefined && !ppt->readFct) if(ppt->readAst && !ppt->readFct)
out << "READ "; out << "READ ";
if(ppt->writedefined && !ppt->writeFct) if(ppt->writeAst && !ppt->writeFct)
out << "WRITE "; out << "WRITE ";
if(ppt->resetdefined && !ppt->resetFct) if(ppt->resetAst && !ppt->resetFct)
out << "RESET."; out << "RESET.";
if(ppt->notifydefined && !ppt->notifyFct) if(ppt->notifyAst && !ppt->notifyFct)
out << "NOTIFY "; out << "NOTIFY ";
out << "functions missing." << endl; out << "functions missing." << endl;
ret << tmp; ret << tmp;
@@ -1154,8 +1149,7 @@ QList<QENUMITEM*> ParseManager::checkMetadataEnums(const QList<QList<QENUMITEM*>
else { else {
foreach(QENUMITEM *qenum, iqenumlist){ foreach(QENUMITEM *qenum, iqenumlist){
qenum->classWichIsNotFound << "<all classes>"; qenum->classWichIsNotFound << "<all classes>";
QString name= qenum->trlUnit->spell(qenum->ast->firstToken()); Trace("- Enum: <all classes>::" + qenum->name + " not found!");
Trace("- Enum: <all classes>::" + name + " not found!");
} }
iqenums.append(iqenumlist); iqenums.append(iqenumlist);
} }
@@ -1210,18 +1204,13 @@ between Q_ENUMS and enums.
***************************************/ ***************************************/
void ParseManager::assignEnumValues(QENUMITEM* qenum, const QList<QList<ENUMITEM*> > &enumlookuplist) void ParseManager::assignEnumValues(QENUMITEM* qenum, const QList<QList<ENUMITEM*> > &enumlookuplist)
{ {
QString enumname;
EnumeratorAST *penum = qenum->ast->asEnumerator();
if(penum){
//get the name of the enum definition
enumname = qenum->trlUnit->spell(penum->firstToken());
//iterate over all enums and find the one with the same name like enumname //iterate over all enums and find the one with the same name like enumname
bool found = false; bool found = false;
foreach (QList<ENUMITEM*> penumlist, enumlookuplist) { foreach (QList<ENUMITEM*> penumlist, enumlookuplist) {
foreach(ENUMITEM *penum, penumlist){ foreach(ENUMITEM *penum, penumlist){
EnumSpecifierAST *penumsec = penum->ast; EnumSpecifierAST *penumsec = penum->ast;
QString enumname1 = penum->trlUnit->spell(penumsec->name->firstToken()); QString enumname1 = penum->trlUnit->spell(penumsec->name->firstToken());
if(enumname == enumname1){ if(qenum->name == enumname1){
qenum->values << getEnumValueStringList(penum); qenum->values << getEnumValueStringList(penum);
found = true; found = true;
break; break;
@@ -1231,7 +1220,6 @@ void ParseManager::assignEnumValues(QENUMITEM* qenum, const QList<QList<ENUMITEM
qenum->foundallenums = false; qenum->foundallenums = false;
} }
} }
}
/*********************************** /***********************************
Function that checkt if the Q_ENUMS Function that checkt if the Q_ENUMS
@@ -1240,6 +1228,8 @@ Enum values are the same.
***********************************/ ***********************************/
QList<QENUMITEM*> ParseManager::containsAllEnums(const QList<QENUMITEM*> &classqenumlist, const QList<QENUMITEM*> &iclassqenumlist) QList<QENUMITEM*> ParseManager::containsAllEnums(const QList<QENUMITEM*> &classqenumlist, const QList<QENUMITEM*> &iclassqenumlist)
{ {
Overview oo;
QList<QENUMITEM*> ret; QList<QENUMITEM*> ret;
foreach(QENUMITEM* iqenum, iclassqenumlist){ foreach(QENUMITEM* iqenum, iclassqenumlist){
bool found = false; bool found = false;
@@ -1250,23 +1240,22 @@ QList<QENUMITEM*> ParseManager::containsAllEnums(const QList<QENUMITEM*> &classq
if(clspec != qenum->highestlevelclass->classspec){ if(clspec != qenum->highestlevelclass->classspec){
clspec = qenum->highestlevelclass->classspec; clspec = qenum->highestlevelclass->classspec;
//get the classname //get the classname
unsigned int firsttoken = clspec->name->firstToken(); classname += oo(clspec->symbol);
classname += qenum->trlUnit->spell(firsttoken);
if(missingimplinclasses.indexOf(classname) < 0) if(missingimplinclasses.indexOf(classname) < 0)
missingimplinclasses.push_back(classname); missingimplinclasses.push_back(classname);
} }
if(qenum->isEqualTo(iqenum)){ if(qenum->isEqualTo(iqenum)){
found = true; found = true;
missingimplinclasses.clear(); missingimplinclasses.clear();
Trace("- Enum: " + classname + "::" + qenum->trlUnit->spell(qenum->ast->firstToken()) + " found"); Trace("- Enum: " + classname + "::" + qenum->name + " found");
break; break;
} }
} }
if(!found){ if(!found){
iqenum->classWichIsNotFound.append(missingimplinclasses); iqenum->classWichIsNotFound.append(missingimplinclasses);
ret.push_back(iqenum); ret.push_back(iqenum);
QString classname = iqenum->trlUnit->spell(iqenum->highestlevelclass->classspec->name->firstToken()); QString classname = oo(iqenum->highestlevelclass->classspec->symbol);
Trace("- Enum: " + classname + "::" + iqenum->trlUnit->spell(iqenum->ast->firstToken()) + " not found!"); Trace("- Enum: " + classname + "::" + iqenum->name + " not found!");
} }
} }
return ret; return ret;
@@ -1278,6 +1267,7 @@ string for a Q_ENUMS mismatch.
************************************/ ************************************/
QStringList ParseManager::getErrorMessage(QENUMITEM* qenum) QStringList ParseManager::getErrorMessage(QENUMITEM* qenum)
{ {
Overview oo;
QStringList ret; QStringList ret;
if(!qenum->foundallenums) if(!qenum->foundallenums)
@@ -1285,18 +1275,8 @@ QStringList ParseManager::getErrorMessage(QENUMITEM* qenum)
QString tmp; QString tmp;
QTextStream out(&tmp); QTextStream out(&tmp);
unsigned int firsttoken = qenum->highestlevelclass->classspec->name->firstToken(); out << oo(qenum->highestlevelclass->classspec->symbol);
unsigned int lasttoken = qenum->highestlevelclass->classspec->name->lastToken(); out << "::Q_ENUMS " << qenum->name << " enum missing.";
for(unsigned int i = firsttoken; i < lasttoken; i++){
out << qenum->trlUnit->spell(i);
}
out << "::Q_ENUMS ( ";
firsttoken = qenum->ast->firstToken();
lasttoken = qenum->ast->lastToken();
for(unsigned int i = firsttoken; i < lasttoken; i++)
out << qenum->trlUnit->spell(i) << " ";
out << ")";
out << endl << " - one or more Enums missing." << endl;
ret << tmp; ret << tmp;
} }
@@ -1304,13 +1284,8 @@ QStringList ParseManager::getErrorMessage(QENUMITEM* qenum)
QString tmp; QString tmp;
QTextStream out(&tmp); QTextStream out(&tmp);
out << qenum->classWichIsNotFound[i] << "::Q_ENUMS ( "; out << qenum->classWichIsNotFound[i] << "::Q_ENUMS "
<< qenum->name;
unsigned int firsttoken = qenum->ast->firstToken();
unsigned int lasttoken = qenum->ast->lastToken();
for(unsigned int i = firsttoken; i < lasttoken; i++)
out << qenum->trlUnit->spell(i) << " ";
out << ")";
ret << tmp; ret << tmp;
} }
return ret; return ret;
@@ -1360,7 +1335,7 @@ QList<QFLAGITEM*> ParseManager::checkMetadataFlags(const QList<QList<QFLAGITEM*>
else { else {
foreach(QFLAGITEM *pflag, iqflaglist){ foreach(QFLAGITEM *pflag, iqflaglist){
pflag->classWichIsNotFound << "<all classes>"; pflag->classWichIsNotFound << "<all classes>";
QString name= pflag->trlUnit->spell(pflag->ast->firstToken()); QString name= pflag->name->identifier()->chars();
Trace("- Flag: <all classes>::" + name + " not found!"); Trace("- Flag: <all classes>::" + name + " not found!");
} }
iqflags.append(iqflaglist); iqflags.append(iqflaglist);
@@ -1377,36 +1352,26 @@ and enums.
***************************************/ ***************************************/
void ParseManager::assignFlagValues(QFLAGITEM* qflags, const QList<QList<QDECLAREFLAGSITEM*> > &qdeclareflagslookuplist, const QList<QList<ENUMITEM*> > &enumlookuplist) void ParseManager::assignFlagValues(QFLAGITEM* qflags, const QList<QList<QDECLAREFLAGSITEM*> > &qdeclareflagslookuplist, const QList<QList<ENUMITEM*> > &enumlookuplist)
{ {
QString qflagname;
QString enumname; QString enumname;
//read the flag names
EnumeratorAST *pflags = qflags->ast->asEnumerator();
if(pflags){
qflagname = qflags->trlUnit->spell(pflags->firstToken());
enumname = qflagname;
//try to find if there is a deflare flag macro with the same name as in qflagname //try to find if there is a deflare flag macro with the same name as in qflagname
bool found = false; Scope *classMembers = qflags->highestlevelclass->classspec->symbol->members();
foreach(QList<QDECLAREFLAGSITEM*> qdeclarelist, qdeclareflagslookuplist){ Symbol *s = classMembers->lookat(qflags->name);
foreach(QDECLAREFLAGSITEM* qdeclare, qdeclarelist){ if (s->isTypedef()) {
QString declarename = qdeclare->trlUnit->spell(qdeclare->ast->flag_token); FullySpecifiedType ty = s->type();
if(declarename == qflagname){ if (Enum *e = ty->asEnumType()) {
//now map the right enum name to the flag enumname = e->name()->identifier()->chars();
enumname = qdeclare->trlUnit->spell(qdeclare->ast->enum_token);
found = true;
break;
} }
} }
if(found)
break;
}
//now we have the right enum name now we need to find the enum //now we have the right enum name now we need to find the enum
found = false; bool found = false;
foreach(QList<ENUMITEM*> enumitemlist, enumlookuplist){ foreach(QList<ENUMITEM*> enumitemlist, enumlookuplist){
foreach(ENUMITEM* enumitem, enumitemlist){ foreach(ENUMITEM* enumitem, enumitemlist){
EnumSpecifierAST *penumspec = enumitem->ast; EnumSpecifierAST *penumspec = enumitem->ast;
QString enumspecname = enumitem->trlUnit->spell(penumspec->name->firstToken()); QString enumspecname = enumitem->trlUnit->spell(penumspec->name->firstToken());
if(enumspecname == enumname){ if(enumspecname == enumname){
qflags->enumvalues << getEnumValueStringList(enumitem, qflagname); qflags->enumvalues << getEnumValueStringList(enumitem, qflags->name->identifier()->chars());
found = true; found = true;
break; break;
} }
@@ -1417,7 +1382,6 @@ void ParseManager::assignFlagValues(QFLAGITEM* qflags, const QList<QList<QDECLAR
if(!found) if(!found)
qflags->foundallenums = false; qflags->foundallenums = false;
} }
}
/***************************************** /*****************************************
Function that compares if all enums Function that compares if all enums
@@ -1437,23 +1401,22 @@ QList<QFLAGITEM*> ParseManager::containsAllFlags(const QList<QFLAGITEM*> &classq
if(clspec != qflags->highestlevelclass->classspec){ if(clspec != qflags->highestlevelclass->classspec){
clspec = qflags->highestlevelclass->classspec; clspec = qflags->highestlevelclass->classspec;
//get the classname //get the classname
unsigned int firsttoken = clspec->name->firstToken(); classname += clspec->symbol->name()->identifier()->chars();
classname += qflags->trlUnit->spell(firsttoken);
if(missingimplinclasses.indexOf(classname) < 0) if(missingimplinclasses.indexOf(classname) < 0)
missingimplinclasses.push_back(classname); missingimplinclasses.push_back(classname);
} }
if(qflags->isEqualTo(iqflags)){ if(qflags->isEqualTo(iqflags)){
found = true; found = true;
missingimplinclasses.clear(); missingimplinclasses.clear();
Trace("- Flag: " + classname + "::" + qflags->trlUnit->spell(qflags->ast->firstToken()) + " found"); Trace("- Flag: " + classname + "::" + qflags->name->identifier()->chars() + " found");
break; break;
} }
} }
if(!found){ if(!found){
iqflags->classWichIsNotFound.append(missingimplinclasses); iqflags->classWichIsNotFound.append(missingimplinclasses);
ret.push_back(iqflags); ret.push_back(iqflags);
QString classname = iqflags->trlUnit->spell(iqflags->highestlevelclass->classspec->name->firstToken()); QString classname = iqflags->highestlevelclass->classspec->symbol->name()->identifier()->chars();
Trace("- Flag: " + classname + "::" + iqflags->trlUnit->spell(iqflags->ast->firstToken()) + " not found!"); Trace("- Flag: " + classname + "::" + iqflags->name->identifier()->chars() + " not found!");
} }
} }
else else
@@ -1468,6 +1431,7 @@ string for a Q_FLAGS mismatch.
************************************/ ************************************/
QStringList ParseManager::getErrorMessage(QFLAGITEM* pfg) QStringList ParseManager::getErrorMessage(QFLAGITEM* pfg)
{ {
Overview oo;
QStringList ret; QStringList ret;
if(!pfg->foundallenums) if(!pfg->foundallenums)
@@ -1475,31 +1439,15 @@ QStringList ParseManager::getErrorMessage(QFLAGITEM* pfg)
QString tmp; QString tmp;
QTextStream out(&tmp); QTextStream out(&tmp);
unsigned int firsttoken = pfg->highestlevelclass->classspec->name->firstToken(); out << oo(pfg->highestlevelclass->classspec->symbol->name());
unsigned int lasttoken = pfg->highestlevelclass->classspec->name->lastToken(); out << "::Q_FLAGS "<<pfg->name->identifier()->chars()<< ": enum missing.";
for(unsigned int i = firsttoken; i < lasttoken; i++){
out << pfg->trlUnit->spell(i);
}
out << "::Q_FLAGS ( ";
firsttoken = pfg->ast->firstToken();
lasttoken = pfg->ast->lastToken();
for(unsigned int i = firsttoken; i < lasttoken; i++)
out << pfg->trlUnit->spell(i) << " ";
out << ")";
out << endl << " - one or more Enums missing." << endl;
ret << tmp; ret << tmp;
} }
for(int i = 0; i < pfg->classWichIsNotFound.size(); i++){ for(int i = 0; i < pfg->classWichIsNotFound.size(); i++){
QString tmp; QString tmp;
QTextStream out(&tmp); QTextStream out(&tmp);
out << pfg->classWichIsNotFound[i] << "::Q_FLAGS ( "; out << pfg->classWichIsNotFound[i] << "::Q_FLAGS " << oo(pfg->name);
unsigned int firsttoken = pfg->ast->firstToken();
unsigned int lasttoken = pfg->ast->lastToken();
for(unsigned int i = firsttoken; i < lasttoken; i++)
out << pfg->trlUnit->spell(i) << " ";
out << ")";
ret << tmp; ret << tmp;
} }
return ret; return ret;
@@ -1546,4 +1494,35 @@ void ParseManager::Trace(QString value)
out << value << endl; out << value << endl;
} }
} }
PROPERTYITEM *PROPERTYITEM::create(QtPropertyDeclarationAST *ast, const CLASSLISTITEM *clazz)
{
PROPERTYITEM *item = new PROPERTYITEM;
item->ast = ast;
item->highestlevelclass = clazz;
item->trlUnit = clazz->trlUnit;
if (ast->type_id) {
Semantic mySem(item->trlUnit);
item->type = mySem.check(ast->type_id, clazz->classspec->symbol->asClass()->members());
}
for (QtPropertyDeclarationItemListAST *it = ast->property_declaration_items;
it; it = it->next) {
if (!it->value->item_name_token)
continue;
const char *name = item->trlUnit->spell(it->value->item_name_token);
if (!qstrcmp(name, "READ"))
item->readAst = it->value->expression;
else if (!qstrcmp(name, "WRITE"))
item->writeAst = it->value->expression;
else if (!qstrcmp(name, "RESET"))
item->resetAst = it->value->expression;
else if (!qstrcmp(name, "NOTIFY"))
item->notifyAst = it->value->expression;
}
return item;
}
//---> //--->

View File

@@ -61,11 +61,14 @@
#ifndef PARSEMANAGER_H #ifndef PARSEMANAGER_H
#define PARSEMANAGER_H #define PARSEMANAGER_H
#include "cplusplus/CppDocument.h"
#include "ASTfwd.h"
#include "FullySpecifiedType.h"
#include <QObject> #include <QObject>
#include <QList> #include <QList>
#include <QFuture> #include <QFuture>
#include <QStringList> #include <QStringList>
#include "cplusplus/CppDocument.h"
#include <QFile> #include <QFile>
namespace CppTools{ namespace CppTools{
@@ -75,15 +78,6 @@ namespace CppTools{
} }
namespace CPlusPlus { namespace CPlusPlus {
class TranslationUnit;
class AST;
class ClassSpecifierAST;
class QPropertyDeclarationAST;
class QDeclareFlagsDeclarationAST;
class EnumSpecifierAST;
class Function;
class EnumeratorAST;
class CLASSLISTITEM class CLASSLISTITEM
{ {
public: public:
@@ -106,6 +100,7 @@ namespace CPlusPlus {
CPlusPlus::Function* function; CPlusPlus::Function* function;
bool isEqualTo(FUNCTIONITEM* cpfct, bool ignoreName = true); bool isEqualTo(FUNCTIONITEM* cpfct, bool ignoreName = true);
FUNCTIONITEM() FUNCTIONITEM()
{ {
highestlevelclass = 0; highestlevelclass = 0;
@@ -119,15 +114,16 @@ namespace CPlusPlus {
public: public:
const CLASSLISTITEM* highestlevelclass; const CLASSLISTITEM* highestlevelclass;
QStringList classWichIsNotFound; QStringList classWichIsNotFound;
QPropertyDeclarationAST *ast; QtPropertyDeclarationAST *ast;
CPlusPlus::TranslationUnit* trlUnit; CPlusPlus::TranslationUnit* trlUnit;
bool readdefined; FullySpecifiedType type;
ExpressionAST *readAst;
FUNCTIONITEM *readFct; FUNCTIONITEM *readFct;
bool writedefined; ExpressionAST *writeAst;
FUNCTIONITEM *writeFct; FUNCTIONITEM *writeFct;
bool resetdefined; ExpressionAST *resetAst;
FUNCTIONITEM *resetFct; FUNCTIONITEM *resetFct;
bool notifydefined; ExpressionAST *notifyAst;
FUNCTIONITEM *notifyFct; FUNCTIONITEM *notifyFct;
bool foundalldefinedfct; bool foundalldefinedfct;
@@ -137,25 +133,26 @@ namespace CPlusPlus {
highestlevelclass = 0; highestlevelclass = 0;
ast = 0; ast = 0;
trlUnit = 0; trlUnit = 0;
readdefined = false; readAst = 0;
readFct = 0; readFct = 0;
writedefined = false; writeAst = 0;
writeFct = 0; writeFct = 0;
resetdefined = false; resetAst = 0;
resetFct = 0; resetFct = 0;
notifydefined = false; notifyAst = 0;
notifyFct = 0; notifyFct = 0;
foundalldefinedfct = false; foundalldefinedfct = false;
} }
static PROPERTYITEM *create(QtPropertyDeclarationAST *ast, const CLASSLISTITEM *clazz);
}; };
class QENUMITEM class QENUMITEM
{ {
public: public:
const CLASSLISTITEM* highestlevelclass; const CLASSLISTITEM* highestlevelclass;
CPlusPlus::TranslationUnit* trlUnit;
QStringList classWichIsNotFound; QStringList classWichIsNotFound;
EnumeratorAST* ast; QString name;
//an item in this list will be shown like: //an item in this list will be shown like:
//EnumName.EnumItemName.Value //EnumName.EnumItemName.Value
//ConnectionState.disconnected.0 //ConnectionState.disconnected.0
@@ -166,8 +163,6 @@ namespace CPlusPlus {
QENUMITEM() QENUMITEM()
{ {
highestlevelclass = 0; highestlevelclass = 0;
trlUnit = 0;
ast = 0;
values.clear(); values.clear();
foundallenums = true; foundallenums = true;
} }
@@ -193,9 +188,8 @@ namespace CPlusPlus {
{ {
public: public:
const CLASSLISTITEM* highestlevelclass; const CLASSLISTITEM* highestlevelclass;
CPlusPlus::TranslationUnit* trlUnit; const Name *name;
QStringList classWichIsNotFound; QStringList classWichIsNotFound;
EnumeratorAST* ast;
QStringList enumvalues; QStringList enumvalues;
bool foundallenums; bool foundallenums;
@@ -203,8 +197,6 @@ namespace CPlusPlus {
QFLAGITEM() QFLAGITEM()
{ {
highestlevelclass = 0; highestlevelclass = 0;
trlUnit = 0;
ast = 0;
enumvalues.clear(); enumvalues.clear();
foundallenums = true; foundallenums = true;
} }
@@ -216,7 +208,7 @@ namespace CPlusPlus {
const CLASSLISTITEM* highestlevelclass; const CLASSLISTITEM* highestlevelclass;
CPlusPlus::TranslationUnit* trlUnit; CPlusPlus::TranslationUnit* trlUnit;
QStringList classWichIsNotFound; QStringList classWichIsNotFound;
QDeclareFlagsDeclarationAST* ast; QtFlagsDeclarationAST* ast;
QDECLAREFLAGSITEM() QDECLAREFLAGSITEM()
{ {