glslsymbols.cpp 3.25 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** 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.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30

#include "glslsymbols.h"
31
#include "glsltypes.h"
32
#include <QDebug>
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

using namespace GLSL;

Argument::Argument(Function *scope)
    : Symbol(scope)
    , _type(0)
{
}

const Type *Argument::type() const
{
    return _type;
}

void Argument::setType(const Type *type)
{
    _type = type;
}

Block::Block(Scope *enclosingScope)
    : Scope(enclosingScope)
{
}

57
QList<Symbol *> Block::members() const
58
{
59
    return _members.values();
60 61
}

Roberto Raggi's avatar
Roberto Raggi committed
62
void Block::add(Symbol *symbol)
63
{
Roberto Raggi's avatar
Roberto Raggi committed
64
    _members.insert(symbol->name(), symbol);
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
}

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)
81
    , _qualifiers(0)
82 83 84 85 86 87 88 89 90 91 92 93
{
}

const Type *Variable::type() const
{
    return _type;
}

void Variable::setType(const Type *type)
{
    _type = type;
}
Roberto Raggi's avatar
Roberto Raggi committed
94 95 96 97 98 99 100 101 102 103

Namespace::Namespace()
{
}

Namespace::~Namespace()
{
    qDeleteAll(_overloadSets);
}

104
QList<Symbol *> Namespace::members() const
105
{
106
    return _members.values();
107 108
}

Roberto Raggi's avatar
Roberto Raggi committed
109 110 111
void Namespace::add(Symbol *symbol)
{
    Symbol *&sym = _members[symbol->name()];
112
    if (! sym) {
Roberto Raggi's avatar
Roberto Raggi committed
113
        sym = symbol;
114
    } else if (Function *fun = symbol->asFunction()) {
Roberto Raggi's avatar
Roberto Raggi committed
115 116 117 118 119
        if (OverloadSet *o = sym->asOverloadSet()) {
            o->addFunction(fun);
        } else if (Function *firstFunction = sym->asFunction()) {
            OverloadSet *o = new OverloadSet(this);
            _overloadSets.append(o);
120
            o->setName(symbol->name());
Roberto Raggi's avatar
Roberto Raggi committed
121 122 123
            o->addFunction(firstFunction);
            o->addFunction(fun);
            sym = o;
124
        } else {
Roberto Raggi's avatar
Roberto Raggi committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
            // ### warning? return false?
        }
    } else {
        // ### warning? return false?
    }
}

const Type *Namespace::type() const
{
    return 0;
}

Symbol *Namespace::find(const QString &name) const
{
    return _members.value(name);
}