From 68ddcab8c302d90718df875d22553f51dda8e7ff Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Thu, 25 Nov 2010 13:41:59 +0100 Subject: [PATCH] Introduced GLSL::Symbol. --- src/libs/glsl/glsl-lib.pri | 4 +-- src/libs/glsl/glslsymbol.cpp | 61 +++++++++++++++++++++++++++++++ src/libs/glsl/glslsymbol.h | 69 ++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/libs/glsl/glslsymbol.cpp create mode 100644 src/libs/glsl/glslsymbol.h diff --git a/src/libs/glsl/glsl-lib.pri b/src/libs/glsl/glsl-lib.pri index daec79e7085..2e0edcef781 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/glslsemantic.h $$PWD/glsltype.h $$PWD/glsltypes.h $$PWD/glslsymbol.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/glslsemantic.cpp $$PWD/glsltype.cpp $$PWD/glsltypes.cpp $$PWD/glslsymbol.cpp OTHER_FILES = $$PWD/glsl.g diff --git a/src/libs/glsl/glslsymbol.cpp b/src/libs/glsl/glslsymbol.cpp new file mode 100644 index 00000000000..cc69332616f --- /dev/null +++ b/src/libs/glsl/glslsymbol.cpp @@ -0,0 +1,61 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 "glslsymbol.h" + +using namespace GLSL; + +Symbol::~Symbol() +{ +} + +Scope::Scope(Scope *enclosingScope) + : _enclosingScope(enclosingScope) +{ +} + +Scope *Scope::enclosingScope() const +{ + return _enclosingScope; +} + +void Scope::setEnclosingScope(Scope *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 + return 0; +} diff --git a/src/libs/glsl/glslsymbol.h b/src/libs/glsl/glslsymbol.h new file mode 100644 index 00000000000..b7ba9ca37ab --- /dev/null +++ b/src/libs/glsl/glslsymbol.h @@ -0,0 +1,69 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 GLSLSYMBOL_H +#define GLSLSYMBOL_H + +#include "glsl.h" + +namespace GLSL { + +class Symbol; +class Scope; + +class Symbol +{ +public: + virtual ~Symbol(); + + virtual Scope *asScope() { return 0; } + + virtual Type *type() const = 0; +}; + +class Scope: public Symbol +{ +public: + Scope(Scope *enclosingScope = 0); + + Scope *enclosingScope() const; + void setEnclosingScope(Scope *enclosingScope); + + 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 + +#endif // GLSLSYMBOL_H -- GitLab