Synopsis - Cross-Reference
File: /Synopsis/Parsers/Cxx/TypeInfo.hh1// 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 TypeInfo_hh_ 10#define TypeInfo_hh_ 11 12#include "Types.hh" 13 14 15// The TypeInfo class determines information about a type 16class TypeInfo : public Types::Visitor 17{ 18public: 19 Types::Type* type; 20 bool is_const; 21 bool is_volatile; 22 bool is_null; 23 size_t deref; 24 25 //. Constructor 26 TypeInfo(Types::Type* t) 27 { 28 type = t; 29 is_const = is_volatile = is_null = false; 30 deref = 0; 31 set(t); 32 } 33 //. Set to the given type 34 void set(Types::Type* t) 35 { 36 type = t; 37 t->accept(this); 38 } 39 //. Base -- null is flagged since it is special 40 void visit_base(Types::Base* base) 41 { 42 if (base->name().back() == "__null_t") 43 is_null = true; 44 } 45 //. Modifiers -- recurse on the alias type 46 void visit_modifier(Types::Modifier* mod) 47 { 48 Types::Type::Mods::const_iterator iter; 49 // Check for const 50 for (iter = mod->pre().begin(); iter != mod->pre().end(); iter++) 51 if (*iter == "const") 52 is_const = true; 53 else if (*iter == "volatile") 54 is_volatile = true; 55 // Check for derefs 56 for (iter = mod->post().begin(); iter != mod->post().end(); iter++) 57 if (*iter == "*") 58 deref++; 59 else if (*iter == "[]") 60 deref++; 61 62 set(mod->alias()); 63 } 64 //. Declared -- check for typedef 65 void visit_declared(Types::Declared* t) 66 { 67 try 68 { 69 ASG::Typedef* tdef = Types::declared_cast<ASG::Typedef>(t); 70 // Recurse on typedef alias 71 set(tdef->alias()); 72 } 73 catch (const Types::wrong_type_cast&) 74 { /* Ignore -- just means not a typedef */ 75 } 76 } 77}; 78 79//. Output operator for debugging 80std::ostream& operator << (std::ostream& o, TypeInfo& i); 81#endif 82// vim: set ts=8 sts=4 sw=4 et: