memberhandler.cpp 15.3 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2 3 4 5
/******************************************************************************
 *
 * $Id$
 *
 *
6
 * Copyright (C) 1997-2006 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

#include "memberhandler.h"
#include "sectionhandler.h"
#include "dochandler.h"
#include "mainhandler.h"
#include "linkedtexthandler.h"
21 22
#include "paramhandler.h"
#include "compoundhandler.h"
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "debug.h"

//------------------------------------------------------------------------------

class MemberTypeMap
{
  public:
    MemberTypeMap()
    {
      m_map.setAutoDelete(TRUE);
      m_map.insert("define",new int(IMember::Define));
      m_map.insert("property",new int(IMember::Property));
      m_map.insert("variable",new int(IMember::Variable));
      m_map.insert("typedef",new int(IMember::Typedef));
      m_map.insert("enum",new int(IMember::Enum));
      m_map.insert("function",new int(IMember::Function));
      m_map.insert("signal",new int(IMember::Signal));
      m_map.insert("prototype",new int(IMember::Prototype));
      m_map.insert("friend",new int(IMember::Friend));
      m_map.insert("dcop",new int(IMember::DCOP));
      m_map.insert("slot",new int(IMember::Slot));
44
      m_map.insert("enumvalue",new int(IMember::EnumValue));
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    }
    IMember::MemberKind map(const QString &s)
    {
      int *val = m_map.find(s);
      if (val==0) 
      {
        debug(1,"Warning: `%s' is an invalid member type\n",s.data());
        return IMember::Invalid;
      }
      else return (IMember::MemberKind)*val;
    }
  private: 
    QDict<int> m_map;
};

static MemberTypeMap *s_typeMap;

void memberhandler_init()
{
  s_typeMap = new MemberTypeMap;
}

void memberhandler_exit()
{
  delete s_typeMap;
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
71 72 73 74 75 76 77 78 79 80

//------------------------------------------------------------------------------

void MemberReference::initialize(MainHandler *mh)
{
  m_mainHandler = mh;
}

IMember *MemberReference::member() const
{
81 82
  //return m_mainHandler->memberById(m_memId);
  return 0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
83 84 85 86 87
}

//------------------------------------------------------------------------------


88 89 90
#if 0
EnumValueHandler::EnumValueHandler(IBaseHandler *parent) : 
  m_parent(parent), m_brief(0), m_detailed(0), m_linkedTextHandler(0)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
91 92 93 94 95 96
{
  addEndHandler("enumvalue",this,&EnumValueHandler::endEnumValue);

  addStartHandler("name",this,&EnumValueHandler::startName);
  addEndHandler("name",this,&EnumValueHandler::endName);
  addStartHandler("initializer",this,&EnumValueHandler::startInitializer);
97 98 99 100 101

  addStartHandler("briefdescription",this,&EnumValueHandler::startBriefDesc);

  addStartHandler("detaileddescription",this,&EnumValueHandler::startDetailedDesc);

102 103 104 105 106 107 108 109
  m_initializer.setAutoDelete(TRUE);
}

EnumValueHandler::~EnumValueHandler()
{
  delete m_brief;
  delete m_detailed;
  delete m_linkedTextHandler;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
}

void EnumValueHandler::startEnumValue(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this); 
}

void EnumValueHandler::endEnumValue()
{
  m_parent->setDelegate(0); 
}

void EnumValueHandler::startName(const QXmlAttributes& /*attrib*/)
{
  m_curString="";
}

void EnumValueHandler::endName()
{
  m_name = m_curString;
}

void EnumValueHandler::startInitializer(const QXmlAttributes& /*attrib*/)
{
134 135 136
  delete m_linkedTextHandler;
  m_linkedTextHandler = new LinkedTextHandler(this,m_initializer);
  m_linkedTextHandler->start("initializer");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
137 138
}

139 140 141 142 143 144 145 146 147 148 149 150 151
void EnumValueHandler::startBriefDesc(const QXmlAttributes& attrib)
{
  DocHandler *docHandler = new DocHandler(this);
  docHandler->startDoc(attrib);
  m_brief = docHandler;
}

void EnumValueHandler::startDetailedDesc(const QXmlAttributes& attrib)
{
  DocHandler *docHandler = new DocHandler(this);
  docHandler->startDoc(attrib);
  m_detailed = docHandler;
}
152
#endif
153

Dimitri van Heesch's avatar
Dimitri van Heesch committed
154 155 156
//------------------------------------------------------------------------------

MemberHandler::MemberHandler(IBaseHandler *parent)
157 158
  : m_brief(0), m_detailed(0), m_inbody(0), 
    m_compound(0), m_section(0), m_parent(parent)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
159
{
160
  //printf("MemberHandler::MemberHandler() %p\n",this);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
161 162
  addEndHandler("memberdef",this,&MemberHandler::endMember);

163 164
  addStartHandler("templateparamlist",this,&MemberHandler::startTemplateParamList);
  addEndHandler("templateparamlist",this,&MemberHandler::endTemplateParamList);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
165

166
  addStartHandler("type",this,&MemberHandler::startType);
167 168 169 170 171 172 173

  addStartHandler("definition",this,&MemberHandler::startDefinition);
  addEndHandler("definition",this,&MemberHandler::endDefinition);

  addStartHandler("argsstring",this,&MemberHandler::startArgsString);
  addEndHandler("argsstring",this,&MemberHandler::endArgsString);

174
  addStartHandler("name",this,&MemberHandler::startName);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
175 176
  addEndHandler("name",this,&MemberHandler::endName);

177 178 179 180 181 182
  addStartHandler("read",this,&MemberHandler::startRead);
  addEndHandler("read",this,&MemberHandler::endRead);

  addStartHandler("write",this,&MemberHandler::startWrite);
  addEndHandler("write",this,&MemberHandler::endWrite);

183 184 185 186 187 188
  addStartHandler("reimplements",this,&MemberHandler::startReimplements);
  addEndHandler("reimplements",this,&MemberHandler::endReimplements);
  
  addStartHandler("reimplementedby",this,&MemberHandler::startReimplementedBy);
  addEndHandler("reimplementedby",this,&MemberHandler::endReimplementedBy);

Dimitri van Heesch's avatar
Dimitri van Heesch committed
189 190
  addStartHandler("param",this,&MemberHandler::startParam);

191 192 193 194
  addStartHandler("enumvalue",this,&MemberHandler::startEnumValue2);
  addEndHandler("enumvalue",this,&MemberHandler::endMember);

  addStartHandler("initializer",this,&MemberHandler::startInitializer);
195
  addStartHandler("exceptions",this,&MemberHandler::startException);
196

Dimitri van Heesch's avatar
Dimitri van Heesch committed
197 198 199 200
  addStartHandler("briefdescription",this,&MemberHandler::startBriefDesc);

  addStartHandler("detaileddescription",this,&MemberHandler::startDetailedDesc);

201
  addStartHandler("inbodydescription",this,&MemberHandler::startInbodyDesc);
202 203 204 205
  
  addStartHandler("location",this,&MemberHandler::startLocation);
  addEndHandler("location");

Dimitri van Heesch's avatar
Dimitri van Heesch committed
206 207 208 209 210 211
  addStartHandler("references",this,&MemberHandler::startReferences);
  addEndHandler("references",this,&MemberHandler::endReferences);
  
  addStartHandler("referencedby",this,&MemberHandler::startReferencedBy);
  addEndHandler("referencedby",this,&MemberHandler::endReferencedBy);

212 213 214
  m_type.setAutoDelete(TRUE);
  m_initializer.setAutoDelete(TRUE);
  m_exception.setAutoDelete(TRUE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
215 216 217 218 219 220 221 222 223 224
  m_params.setAutoDelete(TRUE);
  m_references.setAutoDelete(TRUE);
  m_referencedBy.setAutoDelete(TRUE);
  m_reimplements = 0;
  m_reimplementedBy.setAutoDelete(TRUE);
  m_enumValues.setAutoDelete(TRUE);
  m_linkedTextHandler = 0;
  m_defLine=0;
  m_bodyStart=0;
  m_bodyEnd=0;
225 226
  m_insideTemplateParamList=FALSE;
  m_hasTemplateParamList=FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
227 228 229 230
}

MemberHandler::~MemberHandler()
{
231
  debug(2,"MemberHandler::~MemberHandler() %p\n",this);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
232 233
  delete m_brief;
  delete m_detailed;
234
  delete m_inbody;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
235
  delete m_linkedTextHandler;
236
  delete m_reimplements;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
237 238 239 240 241
}

void MemberHandler::startMember(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
242
  m_kindString = attrib.value("kind");
243
  //printf("startMember kindString=`%s'\n",m_kindString.data());
244
  m_kind = s_typeMap->map(m_kindString);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
245 246
  m_id = attrib.value("id");
  m_protection = attrib.value("prot");
247
  m_isStatic = attrib.value("static")=="yes";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
248
  m_isConst = attrib.value("const")=="yes";
249 250 251
  m_isExplicit = attrib.value("explicit")=="yes";
  m_isInline = attrib.value("inline")=="yes";
  m_virtualness = attrib.value("virt");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
252
  m_isVolatile = attrib.value("volatile")=="yes";
253 254 255 256
  m_isMutable = attrib.value("mutable")=="yes";
  m_isReadable = attrib.value("readable")=="yes";
  m_isWritable = attrib.value("writable")=="yes";

257 258
  debug(2,"member kind=`%s' id=`%s' prot=`%s' virt=`%s'\n",
      m_kindString.data(),m_id.data(),m_protection.data(),m_virtualness.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
259 260
}

261 262 263 264
void MemberHandler::startEnumValue(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
  m_kindString = "enumvalue";
265
  //printf("startEnumValue kindString=`%s'\n",m_kindString.data());
266 267 268
  m_kind = s_typeMap->map(m_kindString);
  m_id = attrib.value("id");
  m_protection = attrib.value("prot");
269
  m_isStatic = FALSE;
270
  m_isConst = FALSE;
271 272 273
  m_isExplicit = FALSE;
  m_isInline = FALSE;
  m_virtualness = "non-virtual";
274
  m_isVolatile = FALSE;
275 276 277
  m_isMutable = FALSE;
  m_isReadable = FALSE;
  m_isWritable = FALSE;
278 279 280 281 282 283 284 285 286 287 288 289
  debug(2,"member kind=`%s' id=`%s' prot=`%s' virt=`%s'\n",
      m_kindString.data(),m_id.data(),m_protection.data(),m_virtualness.data());
}

void MemberHandler::startEnumValue2(const QXmlAttributes& attrib)
{
  MemberHandler *mh = new MemberHandler(this);
  mh->startEnumValue(attrib);
  m_enumValues.append(mh);
}


Dimitri van Heesch's avatar
Dimitri van Heesch committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303
void MemberHandler::startBriefDesc(const QXmlAttributes& attrib)
{
  DocHandler *docHandler = new DocHandler(this);
  docHandler->startDoc(attrib);
  m_brief = docHandler;
}

void MemberHandler::startDetailedDesc(const QXmlAttributes& attrib)
{
  DocHandler *docHandler = new DocHandler(this);
  docHandler->startDoc(attrib);
  m_detailed = docHandler;
}

304 305 306 307 308 309 310
void MemberHandler::startInbodyDesc(const QXmlAttributes& attrib)
{
  DocHandler *docHandler = new DocHandler(this);
  docHandler->startDoc(attrib);
  m_inbody = docHandler;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
311 312 313
void MemberHandler::startLocation(const QXmlAttributes& attrib)
{
  m_defFile = attrib.value("file");
314
  m_bodyFile = attrib.value("bodyfile");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
315 316 317 318 319 320 321 322 323 324 325 326
  QCString s;
  s = attrib.value("line");
  if (!s.isEmpty()) m_defLine=s.toInt();
  s = attrib.value("bodystart");
  if (!s.isEmpty()) m_bodyStart=s.toInt();
  s = attrib.value("bodyend");
  if (!s.isEmpty()) m_bodyEnd=s.toInt();
}

void MemberHandler::startReferences(const QXmlAttributes& attrib)
{
  MemberReference *mr = new MemberReference;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
327
  mr->m_memId = attrib.value("refid");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
328 329 330 331 332 333 334 335 336 337 338 339
  m_references.append(mr);
  m_curString="";
}

void MemberHandler::endReferences()
{
  m_references.getLast()->m_name = m_curString;
}

void MemberHandler::startReferencedBy(const QXmlAttributes& attrib)
{
  MemberReference *mr = new MemberReference;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
340
  mr->m_memId = attrib.value("refid");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
341 342 343 344 345 346 347 348 349 350 351 352
  m_referencedBy.append(mr);
  m_curString="";
}

void MemberHandler::endReferencedBy()
{
  m_referencedBy.getLast()->m_name = m_curString;
}

void MemberHandler::startReimplements(const QXmlAttributes& attrib)
{
  m_reimplements = new MemberReference;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
353
  m_reimplements->m_memId = attrib.value("refid");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
354 355 356 357 358 359 360 361 362 363 364
  m_curString="";
}

void MemberHandler::endReimplements()
{
  m_reimplements->m_name = m_curString;
}

void MemberHandler::startReimplementedBy(const QXmlAttributes& attrib)
{
  MemberReference *mr = new MemberReference;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
365
  mr->m_memId = attrib.value("refid");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
  m_reimplementedBy.append(mr);
  m_curString="";
}

void MemberHandler::endReimplementedBy()
{
  m_reimplementedBy.getLast()->m_name = m_curString;
}

void MemberHandler::endMember()
{
  m_parent->setDelegate(0);
}

void MemberHandler::startType(const QXmlAttributes &)
{
382
  debug(2,"startType!\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
383 384 385 386 387 388 389
  delete m_linkedTextHandler;
  m_linkedTextHandler = new LinkedTextHandler(this,m_type);
  m_linkedTextHandler->start("type");
}

void MemberHandler::startInitializer(const QXmlAttributes &)
{
390
  debug(2,"startInitializer!\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
391 392 393 394 395 396 397
  delete m_linkedTextHandler;
  m_linkedTextHandler = new LinkedTextHandler(this,m_initializer);
  m_linkedTextHandler->start("initializer");
}

void MemberHandler::startException(const QXmlAttributes &)
{
398
  debug(2,"startException!\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
399 400
  delete m_linkedTextHandler;
  m_linkedTextHandler = new LinkedTextHandler(this,m_exception);
401
  m_linkedTextHandler->start("exceptions");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
402 403
}

404 405 406 407 408
void MemberHandler::startName(const QXmlAttributes &)
{
  m_curString="";
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
409 410 411
void MemberHandler::endName()
{
  m_name = m_curString.stripWhiteSpace();
412
  debug(2,"member name=`%s'\n",m_name.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
413 414
}

415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
void MemberHandler::startRead(const QXmlAttributes &)
{
  m_curString="";
}

void MemberHandler::endRead()
{
  m_read = m_curString.stripWhiteSpace();
  debug(2,"member read=`%s'\n",m_read.data());
}

void MemberHandler::startWrite(const QXmlAttributes &)
{
  m_curString="";
}

void MemberHandler::endWrite()
{
  m_write = m_curString.stripWhiteSpace();
  debug(2,"member write=`%s'\n",m_write.data());
}

void MemberHandler::startDefinition(const QXmlAttributes&)
{
  m_curString="";
}

void MemberHandler::endDefinition()
{
  m_definition = m_curString.stripWhiteSpace();
  debug(2,"definition=%s\n",m_definition.data());
}
  
void MemberHandler::startArgsString(const QXmlAttributes&)
{
  m_curString="";
}

void MemberHandler::endArgsString()
{
  m_argsstring = m_curString.stripWhiteSpace();
  debug(2,"arggstring=%s\n",m_argsstring.data());
}
  
Dimitri van Heesch's avatar
Dimitri van Heesch committed
459 460 461 462
void MemberHandler::startParam(const QXmlAttributes& attrib)
{
  ParamHandler *paramHandler = new ParamHandler(this);
  paramHandler->startParam(attrib);
463 464 465 466 467 468 469 470
  if (m_insideTemplateParamList)
  {
    m_templateParams.append(paramHandler);
  }
  else
  {
    m_params.append(paramHandler);
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
471 472
}

473 474 475 476 477 478 479 480 481 482 483
void MemberHandler::startTemplateParamList(const QXmlAttributes&)
{
  m_insideTemplateParamList = TRUE;
  m_hasTemplateParamList = TRUE;
}

void MemberHandler::endTemplateParamList()
{
  m_insideTemplateParamList = FALSE;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
void MemberHandler::initialize(MainHandler *mh)
{
  {
    QListIterator<MemberReference> mli(m_references);
    MemberReference *mr;
    for (;(mr=mli.current());++mli)
    {
      mr->initialize(mh);
    }
  }
  {
    QListIterator<MemberReference> mli(m_referencedBy);
    MemberReference *mr;
    for (;(mr=mli.current());++mli)
    {
      mr->initialize(mh);
    }
  }
  {
    QListIterator<MemberReference> mli(m_reimplementedBy);
    MemberReference *mr;
    for (;(mr=mli.current());++mli)
    {
      mr->initialize(mh);
    }
  }
  if (m_reimplements) m_reimplements->initialize(mh);
}

513 514 515 516 517 518 519 520
void MemberHandler::setCompoundHandler(CompoundHandler *c)
{
  m_compound = c;
}

ICompound *MemberHandler::compound() const
{
  m_compound->addref();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
521
  return m_compound->toICompound();
522 523 524 525 526 527 528 529 530 531 532 533
}

void MemberHandler::setSectionHandler(SectionHandler *c)
{
  m_section = c;
}

ISection *MemberHandler::section() const
{
  return m_section;
}

534 535 536 537 538
IMemberIterator *MemberHandler::enumValues() const
{ 
  return new MemberIterator(m_enumValues); 
}

539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
ILinkedTextIterator *MemberHandler::type() const 
{ 
  return new LinkedTextIterator(m_type); 
}

const IString *MemberHandler::typeString() const
{ 
  MemberHandler *that = (MemberHandler *)this;
  that->m_typeString = LinkedTextHandler::toString(m_type); 
  return &m_typeString;
}

IParamIterator *MemberHandler::parameters() const 
{ 
  return new ParamIterator(m_params); 
}

IParamIterator *MemberHandler::templateParameters() const 
{ 
  return m_hasTemplateParamList ? new ParamIterator(m_templateParams) : 0; 
}

IMemberReferenceIterator *MemberHandler::references() const 
{ 
  return new MemberReferenceIterator(m_references); 
}

IMemberReferenceIterator *MemberHandler::referencedBy() const 
{ 
  return new MemberReferenceIterator(m_referencedBy); 
}

ILinkedTextIterator *MemberHandler::initializer() const
{ 
  return new LinkedTextIterator(m_initializer); 
}

ILinkedTextIterator *MemberHandler::exceptions() const
{ 
  return new LinkedTextIterator(m_exception); 
}

IMemberReferenceIterator *MemberHandler::reimplementedBy() const
{ 
  return new MemberReferenceIterator(m_reimplementedBy); 
}

IDocRoot *MemberHandler::briefDescription() const
{ 
  return m_brief; 
}
    
IDocRoot *MemberHandler::detailedDescription() const
{ 
  return m_detailed; 
}
595

596 597 598 599 600
IDocRoot *MemberHandler::inbodyDescription() const
{ 
  return m_inbody; 
}