Synopsis - Cross-Reference

File: src/Synopsis/PTree/Lists.cc
  1//
  2// Copyright (C) 1997-2000 Shigeru Chiba
  3// Copyright (C) 2004 Stefan Seefeld
  4// All rights reserved.
  5// Licensed to the public under the terms of the GNU LGPL (>= 2),
  6// see the file COPYING for details.
  7//
  8#include <Synopsis/PTree/Lists.hh>
  9#include <Synopsis/PTree/operations.hh>
 10#include <Synopsis/PTree/Encoding.hh>
 11#include <iostream>
 12
 13using namespace Synopsis;
 14using namespace PTree;
 15
 16Declarator::Declarator(Node *n)
 17  : List(n ? n->car() : 0, n ? n->cdr() : 0),
 18    my_declared_name(0),
 19    my_comments(0)
 20{
 21}
 22
 23Declarator::Declarator(Node *list, Encoding const &t, Encoding const &n, Node *dname)
 24  : List(list->car(), list->cdr()),
 25    my_type(t),
 26    my_name(n),
 27    my_declared_name(dname),
 28    my_comments(0)
 29{
 30}
 31
 32Declarator::Declarator(Encoding const &t, Encoding const &n, Node *dname)
 33  : List(0, 0),
 34    my_type(t),
 35    my_name(n),
 36    my_declared_name(dname),
 37    my_comments(0)
 38{
 39}
 40
 41Declarator::Declarator(Node *p, Node *q, Encoding const &t, Encoding const &n, Node *dname)
 42  : List(p, q),
 43    my_type(t),
 44    my_name(n),
 45    my_declared_name(dname),
 46    my_comments(0)
 47{
 48}
 49
 50Declarator::Declarator(Node *list, Encoding const &t)
 51  : List(list->car(), list->cdr()),
 52    my_type(t),
 53    my_declared_name(0),
 54    my_comments(0)
 55{
 56}
 57
 58Declarator::Declarator(Encoding const &t)
 59  : List(0, 0),
 60    my_type(t),
 61    my_declared_name(0),
 62    my_comments(0)
 63{
 64}
 65
 66Declarator::Declarator(Declarator *decl, Node *p, Node *q)
 67  : List(p, q),
 68    my_type(decl->my_type),
 69    my_name(decl->my_name),
 70    my_declared_name(decl->my_declared_name),
 71    my_comments(0)
 72{
 73}
 74
 75Node *Declarator::initializer()
 76{
 77  size_t l = PTree::length(this);
 78  if (l < 2) return 0;
 79  if (Node *assign = nth(this, l - 2))
 80    if (*assign == '=')
 81      return tail(this, l - 1); // initializer-clause
 82  if (Node *expr = nth(this, l - 1))
 83    if (!expr->is_atom() && first(expr) && *first(expr) == '(')
 84      return second(expr); // expression-list
 85  return 0;
 86}
 87
 88Name::Name(Node *p, const Encoding &name)
 89  : List(p->car(), p->cdr()),
 90    my_name(name)
 91{
 92}
 93
 94FstyleCastExpr::FstyleCastExpr(const Encoding &type, Node *p, Node *q)
 95  : List(p, q),
 96    my_type(type)
 97{
 98}
 99
100ClassSpec::ClassSpec(Node *p, Node *q, Node *c)
101  : List(p, q),
102    my_comments(c)
103{
104}
105
106ClassSpec::ClassSpec(const Encoding &name, Node *car, Node *cdr, Node *c)
107  : List(car, cdr),
108    my_name(name),
109    my_comments(c)
110{
111}
112
113ClassBody *ClassSpec::body() 
114{
115  return dynamic_cast<ClassBody *>(PTree::nth(this, 3));
116}