logic: c language support

* re-added gui for c project setup
* ASTVisitor now visits RecordDecls instead of CXXRecordDecls
* prevented endless recursion when parsing struct that is defined in functions signature.
This commit is contained in:
malte_langkabel
2015-12-18 16:27:49 +01:00
parent 5c0493267c
commit bed0f8f157
4 changed files with 39 additions and 31 deletions
+13 -13
View File
@@ -116,10 +116,10 @@ void QtProjectSetupScreen::loadProjectSettings()
{
m_cppStandard->setCurrentText(QString::fromStdString(projSettings->getStandard()));
}
//else if (m_language->currentIndex() == 1) // c
//{
// m_cStandard->setCurrentText(QString::fromStdString(projSettings->getStandard()));
//}
else if (m_language->currentIndex() == 1) // c
{
m_cStandard->setCurrentText(QString::fromStdString(projSettings->getStandard()));
}
}
m_sourcePaths->setList(projSettings->getSourcePaths());
@@ -150,7 +150,7 @@ void QtProjectSetupScreen::populateForm(QFormLayout* layout)
QLabel* languageLabel = new QLabel("Language");
m_language = new QComboBox();
m_language->insertItem(0, "C++");
// m_language->insertItem(1, "C");
m_language->insertItem(1, "C");
connect(m_language, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
layout->addRow(languageLabel, m_language);
@@ -167,7 +167,7 @@ void QtProjectSetupScreen::populateForm(QFormLayout* layout)
layout->addRow(m_cppStandardLabel, m_cppStandard);
/*m_cStandardLabel = new QLabel("Standard");
m_cStandardLabel = new QLabel("Standard");
m_cStandard = new QComboBox();
m_cStandard->insertItem(0, "89");
@@ -178,7 +178,7 @@ void QtProjectSetupScreen::populateForm(QFormLayout* layout)
m_cStandard->insertItem(5, "1x");
layout->addRow(m_cStandardLabel, m_cStandard);
m_cStandardLabel->hide();
m_cStandard->hide();*/
m_cStandard->hide();
QPushButton* helpButton;
@@ -244,10 +244,10 @@ void QtProjectSetupScreen::handleUpdateButtonPress()
{
projSettings->setStandard(m_cppStandard->currentText().toStdString());
}
/*else if (m_cStandard->isVisible())
else if (m_cStandard->isVisible())
{
projSettings->setStandard(m_cStandard->currentText().toStdString());
}*/
}
projSettings->setSourcePaths(m_sourcePaths->getList());
projSettings->setHeaderSearchPaths(m_includePaths->getList());
@@ -266,10 +266,10 @@ void QtProjectSetupScreen::handleUpdateButtonPress()
{
projSettings->setStandard(m_cppStandard->currentText().toStdString());
}
/*else if (m_cStandard->isVisible())
else if (m_cStandard->isVisible())
{
projSettings->setStandard(m_cStandard->currentText().toStdString());
}*/
}
MessageLoadProject(projectFile).dispatch();
clear();
@@ -310,7 +310,7 @@ void QtProjectSetupScreen::handlePreferencesButtonPress()
void QtProjectSetupScreen::handleSelectionChanged(int index)
{
/*if (index != 0)
if (index != 0)
{
m_cStandardLabel->show();
m_cStandard->show();
@@ -323,5 +323,5 @@ void QtProjectSetupScreen::handleSelectionChanged(int index)
m_cppStandard->show();
m_cStandardLabel->hide();
m_cStandard->hide();
}*/
}
}
+23 -16
View File
@@ -50,7 +50,7 @@ bool ASTVisitor::VisitTypedefDecl(clang::TypedefDecl* declaration)
return true;
}
bool ASTVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* declaration)
bool ASTVisitor::VisitRecordDecl(clang::RecordDecl* declaration)
{
if (isLocatedInUnparsedProjectFile(declaration))
{
@@ -74,18 +74,21 @@ bool ASTVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* declaration)
}
if ((declaration->isClass() || declaration->isStruct()) &&
declaration->hasDefinition() && declaration->getDefinition() == declaration && declaration->getNumBases())
declaration->isThisDeclarationADefinition())
{
for (const clang::CXXBaseSpecifier& it : declaration->bases())
if (clang::CXXRecordDecl* cxxDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(declaration))
{
m_client->onInheritanceParsed(
getParseLocation(it.getSourceRange()),
utility::getDeclNameHierarchy(declaration),
utility::qualTypeToDataType(it.getType())->getTypeNameHierarchy(),
convertAccessType(it.getAccessSpecifier())
);
for (const clang::CXXBaseSpecifier& it : cxxDecl->bases())
{
m_client->onInheritanceParsed(
getParseLocation(it.getSourceRange()),
utility::getDeclNameHierarchy(declaration),
utility::qualTypeToDataType(it.getType())->getTypeNameHierarchy(),
convertAccessType(it.getAccessSpecifier())
);
// TODO: check for template class and add arguments!
// TODO: check for template class and add arguments!
}
}
}
}
@@ -1004,17 +1007,21 @@ ParseLocation ASTVisitor::getParseLocationOfFunctionBody(const clang::FunctionDe
return ParseLocation();
}
ParseLocation ASTVisitor::getParseLocationOfRecordBody(clang::CXXRecordDecl* decl) const
ParseLocation ASTVisitor::getParseLocationOfRecordBody(clang::RecordDecl* decl) const
{
if (decl->hasDefinition() && decl->isThisDeclarationADefinition())
if (decl->isThisDeclarationADefinition())
{
clang::SourceRange range;
clang::ClassTemplateDecl* templateDecl = decl->getDescribedClassTemplate();
if (templateDecl)
if (clang::CXXRecordDecl* cxxDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(decl))
{
range = templateDecl->getSourceRange();
clang::ClassTemplateDecl* templateDecl = cxxDecl->getDescribedClassTemplate();
if (templateDecl)
{
range = templateDecl->getSourceRange();
}
}
else
if (range.isInvalid())
{
range = decl->getDefinition()->getSourceRange();
}
+2 -2
View File
@@ -28,7 +28,7 @@ public:
virtual bool VisitStmt(const clang::Stmt* statement); // avoid visiting
virtual bool VisitTypedefDecl(clang::TypedefDecl* declaration); // typedefs
virtual bool VisitCXXRecordDecl(clang::CXXRecordDecl* declaration); // structs, classes and inheritance
virtual bool VisitRecordDecl(clang::RecordDecl* declaration);
virtual bool VisitVarDecl(clang::VarDecl* declaration); // global variables and static fields
virtual bool VisitFieldDecl(clang::FieldDecl* declaration); // fields
virtual bool VisitFunctionDecl(clang::FunctionDecl* declaration); // functions
@@ -86,7 +86,7 @@ private:
ParseLocation getParseLocationForTokensInRange(const clang::SourceRange& range) const;
ParseLocation getParseLocationForNamedDecl(const clang::NamedDecl* decl) const;
ParseLocation getParseLocationOfFunctionBody(const clang::FunctionDecl* decl) const;
ParseLocation getParseLocationOfRecordBody(clang::CXXRecordDecl* decl) const;
ParseLocation getParseLocationOfRecordBody(clang::RecordDecl* decl) const;
ParseTypeUsage getParseTypeUsage(const clang::TypeLoc& typeLoc, const clang::QualType& type) const;
ParseTypeUsage getParseTypeUsage(const clang::TypeLoc& typeLoc, const std::shared_ptr<DataType> type) const;
@@ -210,6 +210,7 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
}
CxxTypeNameResolver typenNameResolver(getIgnoredContextDecls());
typenNameResolver.ignoreContextDecl(functionDecl);
std::string returnTypeString = typenNameResolver.qualTypeToDataType(functionDecl->getReturnType())->getFullTypeName();
std::string parameterString = "(";