Synopsis - Cross-Reference

File: /Synopsis/Parsers/Cxx/Decoder.hh
  1//
  2// Copyright (C) 2002 Stephen Davies
  3// Copyright (C) 2002 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
  9#ifndef Decoder_hh_
 10#define Decoder_hh_
 11
 12#include <Synopsis/PTree/Encoding.hh>
 13#include <string>
 14#include <vector>
 15
 16// Forward decl of Types::Type
 17namespace Types
 18{
 19class Type;
 20class Parameterized;
 21}
 22
 23// bad duplicate typedef.. hmm
 24typedef std::vector<std::string> ScopedName;
 25
 26// Forward decl of Builder
 27class Builder;
 28
 29class Lookup;
 30
 31//. A string type for the encoded names and types
 32typedef Synopsis::PTree::Encoding::Code code;
 33//. A string iterator type for the encoded names and types
 34typedef code::iterator code_iter;
 35
 36//. Decoder for OCC encodings. This class can be used to decode the names and
 37//. types encoded by OCC for function and variable types and names.
 38class Decoder
 39{
 40public:
 41    //. Constructor
 42    Decoder(Builder*);
 43
 44    //. Initialise the type decoder
 45  void init(const Synopsis::PTree::Encoding &);
 46
 47    //. Returns the iterator used in decoding
 48    code_iter& iter()
 49    {
 50        return m_iter;
 51    }
 52
 53    //. Return a Type object from the encoded type.
 54    //. @preconditions You must call init() first.
 55    Types::Type* decodeType();
 56
 57    //. Decodes a Qualified type. iter must be just after the Q
 58    Types::Type* decodeQualType();
 59
 60    //. Decodes a Template type. iter must be just after the T
 61    Types::Parameterized* decodeTemplate();
 62
 63    //. Decodes a FuncPtr type. iter must be just after the F. The vector is
 64    //. the postmod - if it contains a * then it will be removed and given to
 65    //. the funcptr instead
 66    Types::Type* decodeFuncPtr(std::vector<std::string>&);
 67
 68    //. Decode a name
 69    std::string decodeName();
 70
 71    //. Decode a qualified name
 72    ScopedName decodeQualified();
 73
 74    //. Decode a name starting from the given iterator.
 75    //. Note the iterator passed need not be from the currently decoding
 76    //. string since this is a simple method.
 77    std::string decodeName(code_iter);
 78
 79    //. Decode a name starting from the given char*
 80  std::string decodeName(const Synopsis::PTree::Encoding &);
 81
 82    //. Decode a qualified name with only names in it
 83    void decodeQualName(ScopedName& names);
 84
 85    //. Returns true if the char* is pointing to a name (that starts with a
 86    //. length). This is needed since char can be signed or unsigned, and
 87    //. explicitly casting to one or the other is ugly
 88  bool isName(const Synopsis::PTree::Encoding &);
 89
 90private:
 91    //. The encoded type string currently being decoded
 92    code m_string;
 93    //. The current position in m_enc_iter
 94    code_iter m_iter;
 95
 96    //. The builder
 97    Builder* m_builder;
 98
 99    //. The lookup
100    Lookup* m_lookup;
101};
102
103inline bool Decoder::isName(const Synopsis::PTree::Encoding &e)
104{
105  return !e.empty() && e.at(0) > 0x80;
106}
107
108#endif // header guard
109// vim: set ts=8 sts=4 sw=4 et: