forked from qt-creator/qt-creator
Added different parsing mode to TranslationUnit/CppDocument.
This commit is contained in:
@@ -251,9 +251,31 @@ QSet<QByteArray> Document::macroNames() const
|
||||
return _macroNames;
|
||||
}
|
||||
|
||||
void Document::parse()
|
||||
bool Document::parse(ParseMode mode)
|
||||
{
|
||||
_translationUnit->parse();
|
||||
TranslationUnit::ParseMode m = TranslationUnit::ParseTranlationUnit;
|
||||
switch (mode) {
|
||||
case ParseTranlationUnit:
|
||||
m = TranslationUnit::ParseTranlationUnit;
|
||||
break;
|
||||
|
||||
case ParseDeclaration:
|
||||
m = TranslationUnit::ParseDeclaration;
|
||||
break;
|
||||
|
||||
case ParseExpression:
|
||||
m = TranslationUnit::ParseExpression;
|
||||
break;
|
||||
|
||||
case ParseStatement:
|
||||
m = TranslationUnit::ParseStatement;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return _translationUnit->parse(m);
|
||||
}
|
||||
|
||||
void Document::check()
|
||||
@@ -264,7 +286,10 @@ void Document::check()
|
||||
|
||||
_globalNamespace = _control->newNamespace(0);
|
||||
Scope *globals = _globalNamespace->members();
|
||||
if (TranslationUnitAST *ast = _translationUnit->ast()) {
|
||||
if (! _translationUnit->ast())
|
||||
return; // nothing to do.
|
||||
|
||||
if (TranslationUnitAST *ast = _translationUnit->ast()->asTranslationUnit()) {
|
||||
for (DeclarationAST *decl = ast->declarations; decl; decl = decl->next) {
|
||||
semantic.check(decl, globals);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,14 @@ public:
|
||||
void startSkippingBlocks(unsigned offset);
|
||||
void stopSkippingBlocks(unsigned offset);
|
||||
|
||||
void parse(); // ### remove
|
||||
enum ParseMode { // ### keep in sync with CPlusPlus::TranslationUnit
|
||||
ParseTranlationUnit,
|
||||
ParseDeclaration,
|
||||
ParseExpression,
|
||||
ParseStatement
|
||||
};
|
||||
|
||||
bool parse(ParseMode mode = ParseTranlationUnit);
|
||||
void check();
|
||||
void releaseTranslationUnit();
|
||||
|
||||
|
||||
@@ -81,34 +81,17 @@ ExpressionAST *TypeOfExpression::expressionAST() const
|
||||
|
||||
ExpressionAST *TypeOfExpression::extractExpressionAST(Document::Ptr doc) const
|
||||
{
|
||||
TranslationUnitAST *translationUnitAST = doc->translationUnit()->ast();
|
||||
if (! doc->translationUnit()->ast())
|
||||
return 0;
|
||||
|
||||
// ### evaluate the expression
|
||||
ExpressionAST *expressionAST = 0;
|
||||
if (translationUnitAST) {
|
||||
DeclarationAST *declaration = translationUnitAST->declarations;
|
||||
SimpleDeclarationAST *simpleDecl = 0;
|
||||
if (declaration)
|
||||
simpleDecl = declaration->asSimpleDeclaration();
|
||||
if (simpleDecl && simpleDecl->decl_specifier_seq) {
|
||||
if (TypeofSpecifierAST *typeOfSpec = simpleDecl->decl_specifier_seq->asTypeofSpecifier())
|
||||
expressionAST = typeOfSpec->expression;
|
||||
}
|
||||
}
|
||||
return expressionAST;
|
||||
return doc->translationUnit()->ast()->asExpression();
|
||||
}
|
||||
|
||||
Document::Ptr TypeOfExpression::documentForExpression(const QString &expression) const
|
||||
{
|
||||
// create a __typeof__ specifier
|
||||
QByteArray declaration;
|
||||
declaration += "__typeof__ ";
|
||||
declaration += expression.toLatin1(); // C++ code needs to be in latin1
|
||||
declaration += ";";
|
||||
|
||||
// create the expression's AST.
|
||||
Document::Ptr doc = Document::create(QLatin1String("<completion>"));
|
||||
doc->setSource(declaration);
|
||||
doc->parse();
|
||||
doc->setSource(expression.toUtf8());
|
||||
doc->parse(Document::ParseExpression);
|
||||
return doc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user