diff --git a/src/libs/glsl/glslsemantic.cpp b/src/libs/glsl/glslsemantic.cpp index 177c547de7d..ea4e81c60b4 100644 --- a/src/libs/glsl/glslsemantic.cpp +++ b/src/libs/glsl/glslsemantic.cpp @@ -86,16 +86,35 @@ Scope *Semantic::translationUnit(TranslationUnitAST *ast) { Namespace *globalScope = _engine->newNamespace(); Scope *previousScope = switchScope(globalScope); - for (List *it = ast->declarations; it; it = it->next) { - DeclarationAST *decl = it->value; - declaration(decl); + if (ast) { + for (List *it = ast->declarations; it; it = it->next) { + DeclarationAST *decl = it->value; + declaration(decl); + } } return switchScope(previousScope); } -void Semantic::functionIdentifier(FunctionIdentifierAST *ast) +Semantic::ExprResult Semantic::functionIdentifier(FunctionIdentifierAST *ast) { - accept(ast); + ExprResult result; + if (ast) { + if (ast->name) { + if (Symbol *s = _scope->lookup(*ast->name)) { + if (s->asOverloadSet() != 0 || s->asFunction() != 0) + result.type = s->type(); + else + _engine->error(ast->lineno, QString("`%1' cannot be used as a function").arg(*ast->name)); + } else { + // ### _engine->error(ast->lineno, QString("`%1' was not declared in this scope").arg(*ast->name)); + } + } else if (ast->type) { + const Type *ty = type(ast->type); + result.type = ty; + } + } + + return result; } Symbol *Semantic::field(StructTypeAST::Field *ast) @@ -127,9 +146,8 @@ bool Semantic::visit(TranslationUnitAST *ast) bool Semantic::visit(FunctionIdentifierAST *ast) { - // ast->name - const Type *ty = type(ast->type); - Q_UNUSED(ty); + Q_UNUSED(ast); + Q_ASSERT(!"unreachable"); return false; } @@ -151,7 +169,7 @@ bool Semantic::visit(IdentifierExpressionAST *ast) if (ast->name->startsWith(QLatin1String("gl_")) || ast->name->startsWith(QLatin1String("qgl_"))) { // ### well, at least for now. } else { - _engine->error(ast->lineno, QString("Undefined symbol `%1'").arg(*ast->name)); + _engine->error(ast->lineno, QString("`%1' was not declared in this scope").arg(*ast->name)); } } } @@ -216,7 +234,7 @@ bool Semantic::visit(MemberAccessExpressionAST *ast) bool Semantic::visit(FunctionCallExpressionAST *ast) { ExprResult expr = expression(ast->expr); - functionIdentifier(ast->id); + ExprResult id = functionIdentifier(ast->id); for (List *it = ast->arguments; it; it = it->next) { ExprResult arg = expression(it->value); } diff --git a/src/libs/glsl/glslsemantic.h b/src/libs/glsl/glslsemantic.h index 9dcbeed869d..78574d9ea7f 100644 --- a/src/libs/glsl/glslsemantic.h +++ b/src/libs/glsl/glslsemantic.h @@ -55,7 +55,7 @@ public: const Type *type(TypeAST *ast); void declaration(DeclarationAST *ast); Scope *translationUnit(TranslationUnitAST *ast); - void functionIdentifier(FunctionIdentifierAST *ast); + ExprResult functionIdentifier(FunctionIdentifierAST *ast); Symbol *field(StructTypeAST::Field *ast); void parameterDeclaration(ParameterDeclarationAST *ast, Function *fun); diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index a420c1ce489..26a55b7e1e4 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -269,6 +270,10 @@ void GLSLTextEditor::updateDocumentNow() Parser parser(&engine, preprocessedCode.constData(), preprocessedCode.size(), variant); TranslationUnitAST *ast = parser.parse(); + Semantic sem(&engine); + Scope *globalScope = sem.translationUnit(ast); + Q_UNUSED(globalScope); + QTextCharFormat errorFormat; errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); errorFormat.setUnderlineColor(Qt::red); @@ -295,9 +300,6 @@ void GLSLTextEditor::updateDocumentNow() setExtraSelections(CodeWarningsSelection, sels); - // ### process the ast - (void) ast; - // refresh the identifiers. m_identifiers = engine.identifiers(); }