~ubuntu-branches/ubuntu/precise/qtscriptgenerator/precise

« back to all changes in this revision

Viewing changes to generator/parser/name_compiler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2009-04-25 16:16:02 UTC
  • Revision ID: james.westby@ubuntu.com-20090425161602-vrlxapa3fbo2k3x7
Tags: upstream-0.1.0
ImportĀ upstreamĀ versionĀ 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
 
4
** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
 
5
**
 
6
** This file is part of the Qt Script Generator project on Trolltech Labs.
 
7
**
 
8
** This file may be used under the terms of the GNU General Public
 
9
** License version 2.0 as published by the Free Software Foundation
 
10
** and appearing in the file LICENSE.GPL included in the packaging of
 
11
** this file.  Please review the following information to ensure GNU
 
12
** General Public Licensing requirements will be met:
 
13
** http://www.trolltech.com/products/qt/opensource.html
 
14
**
 
15
** If you are unsure which license is appropriate for your use, please
 
16
** review the following information:
 
17
** http://www.trolltech.com/products/qt/licensing.html or contact the
 
18
** sales department at sales@trolltech.com.
 
19
**
 
20
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
21
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
22
**
 
23
****************************************************************************/
 
24
 
 
25
 
 
26
#include "name_compiler.h"
 
27
#include "type_compiler.h"
 
28
#include "declarator_compiler.h"
 
29
#include "lexer.h"
 
30
#include "symbol.h"
 
31
#include "binder.h"
 
32
 
 
33
#include <QtCore/qdebug.h>
 
34
 
 
35
NameCompiler::NameCompiler(Binder *binder)
 
36
  : _M_binder (binder), _M_token_stream (binder->tokenStream ())
 
37
{
 
38
}
 
39
 
 
40
QString NameCompiler::decode_operator(std::size_t index) const
 
41
{
 
42
  const Token &tk = _M_token_stream->token((int) index);
 
43
  return QString::fromUtf8(&tk.text[tk.position], (int) tk.size);
 
44
}
 
45
 
 
46
QString NameCompiler::internal_run(AST *node)
 
47
{
 
48
  _M_name.clear();
 
49
  visit(node);
 
50
  return name();
 
51
}
 
52
 
 
53
void NameCompiler::visitUnqualifiedName(UnqualifiedNameAST *node)
 
54
{
 
55
  QString tmp_name;
 
56
 
 
57
  if (node->tilde)
 
58
    tmp_name += QLatin1String("~");
 
59
 
 
60
  if (node->id)
 
61
    tmp_name += _M_token_stream->symbol(node->id)->as_string();
 
62
 
 
63
  if (OperatorFunctionIdAST *op_id = node->operator_id)
 
64
    {
 
65
#if defined(__GNUC__)
 
66
#warning "NameCompiler::visitUnqualifiedName() -- implement me"
 
67
#endif
 
68
 
 
69
      if (op_id->op && op_id->op->op)
 
70
        {
 
71
          tmp_name += QLatin1String("operator");
 
72
          tmp_name += decode_operator(op_id->op->op);
 
73
          if (op_id->op->close)
 
74
            tmp_name += decode_operator(op_id->op->close);
 
75
        }
 
76
      else if (op_id->type_specifier)
 
77
        {
 
78
#if defined(__GNUC__)
 
79
#warning "don't use an hardcoded string as cast' name"
 
80
#endif
 
81
          Token const &tk = _M_token_stream->token ((int) op_id->start_token);
 
82
          Token const &end_tk = _M_token_stream->token ((int) op_id->end_token);
 
83
          tmp_name += QString::fromLatin1 (&tk.text[tk.position],
 
84
                                           (int) (end_tk.position - tk.position)).trimmed ();
 
85
      }
 
86
    }
 
87
 
 
88
  _M_name += tmp_name;
 
89
  if (node->template_arguments)
 
90
    {
 
91
      // ### cleanup
 
92
      _M_name.last() += QLatin1String("<");
 
93
      visitNodes(this, node->template_arguments);
 
94
      _M_name.last().truncate(_M_name.last().count() - 1); // remove the last ','
 
95
      _M_name.last() += QLatin1String(">");
 
96
    }
 
97
 
 
98
}
 
99
 
 
100
void NameCompiler::visitTemplateArgument(TemplateArgumentAST *node)
 
101
{
 
102
  if (node->type_id && node->type_id->type_specifier)
 
103
    {
 
104
      TypeCompiler type_cc(_M_binder);
 
105
      type_cc.run(node->type_id->type_specifier);
 
106
 
 
107
      DeclaratorCompiler decl_cc(_M_binder);
 
108
      decl_cc.run(node->type_id->declarator);
 
109
 
 
110
      if (type_cc.isConstant())
 
111
        _M_name.last() += "const ";
 
112
 
 
113
      QStringList q = type_cc.qualifiedName ();
 
114
 
 
115
      if (q.count () == 1)
 
116
        {
 
117
#if defined (RXX_RESOLVE_TYPEDEF) // ### it'll break :(
 
118
          TypeInfo tp;
 
119
          tp.setQualifiedName (q);
 
120
          tp = TypeInfo::resolveType (tp, _M_binder->currentScope ()->toItem ());
 
121
          q = tp.qualifiedName ();
 
122
#endif
 
123
 
 
124
          if (CodeModelItem item = _M_binder->model ()->findItem (q, _M_binder->currentScope ()->toItem ()))
 
125
            {
 
126
              if (item->name () == q.last ())
 
127
                q = item->qualifiedName ();
 
128
            }
 
129
        }
 
130
 
 
131
      _M_name.last() += q.join("::");
 
132
 
 
133
      if (decl_cc.isReference())
 
134
        _M_name.last() += "&";
 
135
      if (decl_cc.indirection())
 
136
        _M_name.last() += QString(decl_cc.indirection(), '*');
 
137
 
 
138
      _M_name.last() += QLatin1String(",");
 
139
    }
 
140
}
 
141
 
 
142
// kate: space-indent on; indent-width 2; replace-tabs on;