diff options
author | Roberto Raggi <[email protected]> | 2010-11-25 14:15:59 +0100 |
---|---|---|
committer | Roberto Raggi <[email protected]> | 2010-11-25 14:17:58 +0100 |
commit | 58ab00203d4b5490fa4cd86afa3768c11b8f41b7 (patch) | |
tree | 6b65468e35b8f09b5f33884fb6b868f48fabf81d /src/libs | |
parent | 2960c735df99a35d49c7cc6f39e9b6c11c271bd9 (diff) |
Initial work on the GLSL symbols.
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/glsl/glsl-lib.pri | 4 | ||||
-rw-r--r-- | src/libs/glsl/glsl.h | 7 | ||||
-rw-r--r-- | src/libs/glsl/glslsymbol.cpp | 21 | ||||
-rw-r--r-- | src/libs/glsl/glslsymbol.h | 26 | ||||
-rw-r--r-- | src/libs/glsl/glslsymbols.cpp | 107 | ||||
-rw-r--r-- | src/libs/glsl/glslsymbols.h | 94 | ||||
-rw-r--r-- | src/libs/glsl/glsltype.h | 3 | ||||
-rw-r--r-- | src/libs/glsl/glsltypes.cpp | 75 | ||||
-rw-r--r-- | src/libs/glsl/glsltypes.h | 50 |
9 files changed, 366 insertions, 21 deletions
diff --git a/src/libs/glsl/glsl-lib.pri b/src/libs/glsl/glsl-lib.pri index 2e0edcef781..27dfb2e541c 100644 --- a/src/libs/glsl/glsl-lib.pri +++ b/src/libs/glsl/glsl-lib.pri @@ -1,9 +1,9 @@ HEADERS += $$PWD/glsl.h $$PWD/glsllexer.h $$PWD/glslparser.h $$PWD/glslparsertable_p.h $$PWD/glslast.h \ $$PWD/glslastvisitor.h $$PWD/glslengine.h $$PWD/glslmemorypool.h $$PWD/glslastdump.h \ - $$PWD/glslsemantic.h $$PWD/glsltype.h $$PWD/glsltypes.h $$PWD/glslsymbol.h + $$PWD/glslsemantic.h $$PWD/glsltype.h $$PWD/glsltypes.h $$PWD/glslsymbol.h $$PWD/glslsymbols.h SOURCES += $$PWD/glslkeywords.cpp $$PWD/glslparser.cpp $$PWD/glslparsertable.cpp \ $$PWD/glsllexer.cpp $$PWD/glslast.cpp \ $$PWD/glslastvisitor.cpp $$PWD/glslengine.cpp $$PWD/glslmemorypool.cpp $$PWD/glslastdump.cpp \ - $$PWD/glslsemantic.cpp $$PWD/glsltype.cpp $$PWD/glsltypes.cpp $$PWD/glslsymbol.cpp + $$PWD/glslsemantic.cpp $$PWD/glsltype.cpp $$PWD/glsltypes.cpp $$PWD/glslsymbol.cpp $$PWD/glslsymbols.cpp OTHER_FILES = $$PWD/glsl.g diff --git a/src/libs/glsl/glsl.h b/src/libs/glsl/glsl.h index 016a270bb40..de6a151153a 100644 --- a/src/libs/glsl/glsl.h +++ b/src/libs/glsl/glsl.h @@ -61,6 +61,13 @@ class OpaqueType; class VectorType; class MatrixType; +// symbols +class Struct; +class Function; +class Argument; +class Block; +class Variable; + class AST; template <typename T> class List; } diff --git a/src/libs/glsl/glslsymbol.cpp b/src/libs/glsl/glslsymbol.cpp index cc69332616f..fc429d8f218 100644 --- a/src/libs/glsl/glslsymbol.cpp +++ b/src/libs/glsl/glslsymbol.cpp @@ -31,31 +31,36 @@ using namespace GLSL; +Symbol::Symbol(Scope *scope) + : _scope(scope) +{ +} + Symbol::~Symbol() { } -Scope::Scope(Scope *enclosingScope) - : _enclosingScope(enclosingScope) +Scope *Symbol::scope() const { + return _scope; } -Scope *Scope::enclosingScope() const +void Symbol::setScope(Scope *scope) { - return _enclosingScope; + _scope = scope; } -void Scope::setEnclosingScope(Scope *enclosingScope) +Scope::Scope(Scope *enclosingScope) + : Symbol(enclosingScope) { - _enclosingScope = enclosingScope; } Symbol *Scope::lookup(const QString &name) const { if (Symbol *s = find(name)) return s; - else if (Scope *e = enclosingScope()) - return e->lookup(name); + else if (Scope *s = scope()) + return s->lookup(name); else return 0; } diff --git a/src/libs/glsl/glslsymbol.h b/src/libs/glsl/glslsymbol.h index b7ba9ca37ab..e8393f14e48 100644 --- a/src/libs/glsl/glslsymbol.h +++ b/src/libs/glsl/glslsymbol.h @@ -37,31 +37,37 @@ namespace GLSL { class Symbol; class Scope; -class Symbol +class GLSL_EXPORT Symbol { public: + Symbol(Scope *scope = 0); virtual ~Symbol(); + Scope *scope() const; + void setScope(Scope *scope); + virtual Scope *asScope() { return 0; } + virtual Struct *asStruct() { return 0; } + virtual Function *asFunction() { return 0; } + virtual Argument *asArgument() { return 0; } + virtual Block *asBlock() { return 0; } + virtual Variable *asVariable() { return 0; } + + virtual const Type *type() const = 0; - virtual Type *type() const = 0; +private: + Scope *_scope; }; -class Scope: public Symbol +class GLSL_EXPORT Scope: public Symbol { public: - Scope(Scope *enclosingScope = 0); - - Scope *enclosingScope() const; - void setEnclosingScope(Scope *enclosingScope); + Scope(Scope *sscope = 0); Symbol *lookup(const QString &name) const; virtual Symbol *find(const QString &name) const = 0; virtual Scope *asScope() { return this; } - -private: - Scope *_enclosingScope; }; } // end of namespace GLSL diff --git a/src/libs/glsl/glslsymbols.cpp b/src/libs/glsl/glslsymbols.cpp new file mode 100644 index 00000000000..c70dd2a7afb --- /dev/null +++ b/src/libs/glsl/glslsymbols.cpp @@ -0,0 +1,107 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation ([email protected]) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "glsltypes.h" +#include "glslsymbols.h" +#include <QtCore/qglobal.h> + +using namespace GLSL; + +Argument::Argument(Function *scope) + : Symbol(scope) + , _type(0) +{ +} + +QString Argument::name() const +{ + return _name; +} + +void Argument::setName(const QString &name) +{ + _name = name; +} + +const Type *Argument::type() const +{ + return _type; +} + +void Argument::setType(const Type *type) +{ + _type = type; +} + +Block::Block(Scope *enclosingScope) + : Scope(enclosingScope) +{ +} + +void Block::addMember(const QString &name, Symbol *symbol) +{ + _members.insert(name, symbol); +} + +const Type *Block::type() const +{ + // ### assert? + return 0; +} + +Symbol *Block::find(const QString &name) const +{ + return _members.value(name); +} + +Variable::Variable(Scope *scope) + : Symbol(scope) + , _type(0) +{ +} + +QString Variable::name() const +{ + return _name; +} + +void Variable::setName(const QString &name) +{ + _name = name; +} + +const Type *Variable::type() const +{ + return _type; +} + +void Variable::setType(const Type *type) +{ + _type = type; +} diff --git a/src/libs/glsl/glslsymbols.h b/src/libs/glsl/glslsymbols.h new file mode 100644 index 00000000000..47d175a711d --- /dev/null +++ b/src/libs/glsl/glslsymbols.h @@ -0,0 +1,94 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation ([email protected]) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ +#ifndef GLSLSYMBOLS_H +#define GLSLSYMBOLS_H + +#include "glsltype.h" +#include "glslsymbol.h" +#include <QtCore/QVector> +#include <QtCore/QString> +#include <QtCore/QHash> + +namespace GLSL { + +class GLSL_EXPORT Argument: public Symbol +{ +public: + Argument(Function *scope); + + QString name() const; + void setName(const QString &name); + + virtual const Type *type() const; + void setType(const Type *type); + + virtual Argument *asArgument() { return this; } + +private: + QString _name; + const Type *_type; +}; + +class GLSL_EXPORT Variable: public Symbol +{ +public: + Variable(Scope *scope); + + QString name() const; + void setName(const QString &name); + + virtual const Type *type() const; + void setType(const Type *type); + + virtual Variable *asVariable() { return this; } + +private: + QString _name; + const Type *_type; +}; + +class GLSL_EXPORT Block: public Scope +{ +public: + Block(Scope *enclosingScope = 0); + + void addMember(const QString &name, Symbol *symbol); + + virtual Block *asBlock() { return this; } + + virtual const Type *type() const; + virtual Symbol *find(const QString &name) const; + +private: + QHash<QString, Symbol *> _members; +}; + +} // end of namespace GLSL + +#endif // GLSLSYMBOLS_H diff --git a/src/libs/glsl/glsltype.h b/src/libs/glsl/glsltype.h index be42b19c003..a1608b8adec 100644 --- a/src/libs/glsl/glsltype.h +++ b/src/libs/glsl/glsltype.h @@ -49,6 +49,9 @@ public: virtual const VectorType *asVectorType() const { return 0; } virtual const MatrixType *asMatrixType() const { return 0; } + virtual const Struct *asStructType() const { return 0; } + virtual const Function *asFunctionType() const { return 0; } + virtual bool isEqualTo(const Type *other) const = 0; virtual bool isLessThan(const Type *other) const = 0; }; diff --git a/src/libs/glsl/glsltypes.cpp b/src/libs/glsl/glsltypes.cpp index 14c8c7f02f3..898e8707268 100644 --- a/src/libs/glsl/glsltypes.cpp +++ b/src/libs/glsl/glsltypes.cpp @@ -28,7 +28,7 @@ **************************************************************************/ #include "glsltypes.h" -#include <QtCore/qglobal.h> +#include "glslsymbols.h" using namespace GLSL; @@ -195,3 +195,76 @@ bool MatrixType::isLessThan(const Type *other) const return false; } +bool Struct::isEqualTo(const Type *other) const +{ + Q_UNUSED(other); + return false; +} + +bool Struct::isLessThan(const Type *other) const +{ + Q_UNUSED(other); + return false; +} + +QString Function::name() const +{ + return _name; + +} + +void Function::setName(const QString &name) +{ + _name = name; +} + +const Type *Function::returnType() const +{ + return _returnType; +} + +void Function::setReturnType(const Type *returnType) +{ + _returnType = returnType; +} + +QVector<Argument *> Function::arguments() const +{ + return _arguments; +} + +void Function::addArgument(Argument *arg) +{ + _arguments.append(arg); +} + +int Function::argumentCount() const +{ + return _arguments.size(); +} + +Argument *Function::argumentAt(int index) const +{ + return _arguments.at(index); +} + +bool Function::isEqualTo(const Type *other) const +{ + Q_UNUSED(other); + return false; +} + +bool Function::isLessThan(const Type *other) const +{ + Q_UNUSED(other); + return false; +} + +Symbol *Function::find(const QString &name) const +{ + foreach (Argument *arg, _arguments) { + if (arg->name() == name) + return arg; + } + return 0; +} diff --git a/src/libs/glsl/glsltypes.h b/src/libs/glsl/glsltypes.h index 624493485af..a930a8a3e7f 100644 --- a/src/libs/glsl/glsltypes.h +++ b/src/libs/glsl/glsltypes.h @@ -30,6 +30,9 @@ #define GLSLTYPES_H #include "glsltype.h" +#include "glslsymbol.h" +#include <QtCore/QVector> +#include <QtCore/QString> namespace GLSL { @@ -133,6 +136,53 @@ private: int _rows; }; +class GLSL_EXPORT Struct: public Type, public Symbol +{ +public: + Struct(Scope *scope = 0); + + // as Type + virtual const Struct *asStructType() const { return this; } + virtual bool isEqualTo(const Type *other) const; + virtual bool isLessThan(const Type *other) const; + + // as Symbol + virtual Struct *asStruct() { return this; } // as Symbol +}; + +class GLSL_EXPORT Function: public Type, public Scope +{ +public: + Function(Scope *scope = 0); + + QString name() const; + void setName(const QString &name); + + const Type *returnType() const; + void setReturnType(const Type *returnType); + + QVector<Argument *> arguments() const; + void addArgument(Argument *arg); + int argumentCount() const; + Argument *argumentAt(int index) const; + + // as Type + virtual const Function *asFunctionType() const { return this; } + virtual bool isEqualTo(const Type *other) const; + virtual bool isLessThan(const Type *other) const; + + // as Symbol + virtual Function *asFunction() { return this; } + virtual const Type *type() const { return this; } + + virtual Symbol *find(const QString &name) const; + +private: + QString _name; + const Type *_returnType; + QVector<Argument *> _arguments; +}; + } // end of namespace GLSL #endif // GLSLTYPES_H |