Exemple #1
0
void UmlClass::gen_cpp_decl(QCString s, bool descr) {
  const char * p = (descr)
    ? (const char *) s
    : (const char *) bypass_comment(s);

  while (*p) {
    if (!strncmp(p, "${comment}", 10))
      p += 10;
    else if (!strncmp(p, "${description}", 14))
      p += 14;
    else if (!strncmp(p, "${type}", 7)) {
      p += 7;
      bool find = FALSE;

      if (baseType().type != 0) {
	UmlClass * mother = baseType().type;
	const QVector<UmlItem> ch = children();
	
	for (unsigned i = 0; i != ch.size(); i += 1) {
	  if (ch[i]->kind() == aRelation) {
	    UmlRelation * rel = (UmlRelation *) ch[i];
	    aRelationKind k = rel->relationKind();
	    
	    if (((k == aGeneralisation) ||
		 (k == aRealization)) &&
		(rel->roleType() == mother)) {
	      rel->roleType()->write();
	      generate(actuals(), mother, TRUE);
	      find = TRUE;
	      break;
	    }
	  }
	}
      }
      if (! find)
	UmlItem::write(baseType(), cppLanguage);
    }
    else if (!strncmp(p, "${template}", 11)) {
      p += 11;
      generate(formals());
    }
    else if (!strncmp(p, "${name}", 7)) {
      p += 7;
      writeq(name());
    }
    else if (!strncmp(p, "${inherit}", 10)) {
      p += 10;

      const QVector<UmlItem> ch = children();
      const char * sep = " : ";

      for (unsigned i = 0; i != ch.size(); i += 1) {
	if (ch[i]->kind() == aRelation) {
	  UmlRelation * rel = (UmlRelation *) ch[i];
	  aRelationKind k = rel->relationKind();
	  
	  if (((k == aGeneralisation) ||
	       (k == aRealization)) &&
	      !rel->cppDecl().isEmpty()) {
	    fw.write(sep);
	    // UmlItem::write else G++ call UmlClass::write(QCString) !
	    UmlItem::write((rel->cppVisibility() == DefaultVisibility)
		           ? rel->visibility() : rel->cppVisibility(),
			   cppLanguage);
	    fw.write((rel->cppVirtualInheritance()) ? " virtual " : " ");
	    rel->roleType()->write();
	    generate(actuals(), rel->roleType(), TRUE);
	    sep = ", ";
	  }
	}
      }
    }
    else if (*p == '{') {
      if (descr)
	fw.write(*p++);
      else
	break;
    }
    else if (*p == '\r')
      p += 1;
    else if (*p == '\n') {
      if (descr) {
	fw.write("<br />");
	p += 1;
      }
      else {
	fw.write(' ');
	
	do
	  p += 1;
	while ((*p != 0) && (*p <= ' '));
      }
    }
    else if (*p == '@')
      manage_alias(p);
    else
      writeq(*p++);
  }

}
Exemple #2
0
bool UmlClass::manage_inherit(ClassContainer * container,
                              const QList<FormalParameterList> & tmplts
#ifdef REVERSE
                              , bool libp
# ifdef ROUNDTRIP
                              , bool roundtrip, QList<UmlItem *> & expected_order
                              , bool container_roundtrip, QList<UmlItem *> & container_expected_order
# endif
#endif
                             )
{
#ifdef DEBUG_DOUML
    QLOG_INFO() << name() << "->manage_inherit()\n";
#endif

    WrapperStr s = Lex::read_word(TRUE);

    while (s != "{") {
#ifdef DEBUG_DOUML
        QLOG_INFO() << "Class::manage_inherit, visibility : " << s << '\n';
#endif

        bool is_virtual;

        if (s == "virtual") {
            is_virtual = TRUE;
            s = Lex::read_word(TRUE);
        }
        else
            is_virtual = FALSE;

        aVisibility v;

        if (s == "public") {
            v = PublicVisibility;
            s = Lex::read_word(TRUE);
        }
        else if (s == "protected") {
            v = ProtectedVisibility;
            s = Lex::read_word(TRUE);
        }
        else if (s == "private") {
            v = PrivateVisibility;
            s = Lex::read_word(TRUE);
        }
        else
            v = PrivateVisibility;

        if (s.isEmpty()) {
            Lex::premature_eof();
            return FALSE;
        }

#ifdef DEBUG_DOUML
        QLOG_INFO() << "UmlClass::manage_inherit, mother : " << s << '\n';
#endif

        WrapperStr mother_name = s;
        UmlTypeSpec mother;
        WrapperStr typeform;
        UmlRelation * rel = 0;
#ifdef ROUNDTRIP
        bool is_new = TRUE;
#endif

        container->compute_type(s, mother, typeform);

        s = Lex::read_word();

        if (s == "<") {
            Lex::mark();

            // goes up to the corresponding '>'
            WrapperStr after_gt;

            Lex::finish_template(after_gt);

            s = Lex::read_word(TRUE);

            if (*s == ':') {
                // inherits 'T<...>::...'
                // don't try to solve, use a typedef named 'Type_<n>' based on T<...>::...
                // creating this typedef if it doesn't yet exist

                mother_name += "<" + Lex::region();
                mother.type = 0;  // made below
                s = Lex::read_word();
            }
            else if (mother.type == 0) {
                mother_name += "<" + after_gt;
            }
            else {
                // inherits T<...>
#ifdef ROUNDTRIP
                is_new = !roundtrip || ((rel = search_for_inherit(mother.type)) == 0);
#endif
                mother_name += "<" + after_gt;
                Lex::come_back();

                // must add inheritance before setting actuals
                if (
#ifdef ROUNDTRIP
                    is_new && (
#endif
                               (rel = UmlBaseRelation::create(aRealization, this, mother.type)) == 0
#ifdef ROUNDTRIP
                               )
#endif
                    )
                {
                    Lex::warn("cannot inherit <font color =\"red\">" +
                              Lex::quote(mother_name) + " </font>");
#ifdef DEBUG_DOUML
                    QLOG_INFO() << "cannot create <|---\n";
#endif
                    return FALSE;
                }
                else if (!get_actuals(mother.type, container, tmplts
#ifdef ROUNDTRIP
                                      , !is_new
#endif
                                     ))
                    return FALSE;

#ifdef ROUNDTRIP

                if (! is_new) {
                    if (neq(rel->stereotype(), "bind")) {
                        rel->set_Stereotype("bind");
                        the_class->set_updated();
                    }
                }
                else
#endif
                    rel->set_Stereotype("bind");

                s = Lex::read_word();
            }
        }

        if (mother.type == 0) {
            mother.type = auxilarily_typedef(mother_name
#ifdef REVERSE
                                             , libp
# ifdef ROUNDTRIP
                                             , container_roundtrip
                                             , container_expected_order
# endif
#endif
                                            );

            if (mother.type == 0)
                return FALSE;
        }

#ifdef ROUNDTRIP

        if (rel == 0)
            is_new = !roundtrip || ((rel = search_for_inherit(mother.type)) == 0);

#endif

        if ((rel == 0) &&
            ((rel = UmlBaseRelation::create(aGeneralisation, this, mother.type)) == 0)) {
            Lex::warn("cannot inherit <font color =\"red\">" +
                      Lex::quote(mother_name) + " </font>");
#ifdef DEBUG_DOUML
            QLOG_INFO() << "cannot create <|---\n";
#endif
            return FALSE;
        }

#ifdef ROUNDTRIP
        expected_order.append(rel);

        if (!is_new) {
            rel->set_usefull();

            if (neq(rel->cppDecl(), "${type}")) {
                rel->set_CppDecl("${type}");
                the_class->set_updated();
            }

            if (rel->visibility() != v) {
                rel->set_Visibility(v);
                the_class->set_updated();
            }

            if (is_virtual != rel->cppVirtualInheritance()) {
                rel->set_CppVirtualInheritance(is_virtual);
                the_class->set_updated();
            }
        }
        else {
#elif defined(REVERSE)
        Statistic::one_relation_more();
#endif
            rel->set_CppDecl("${type}");
            rel->set_Visibility(v);

            if (is_virtual)
                rel->set_CppVirtualInheritance(TRUE);

#ifdef ROUNDTRIP
        }

#endif

        if (s == ",")
            s = Lex::read_word();
    }

    Lex::unread_word();	// '{'

    return TRUE;
}