Beispiel #1
0
void UmlClass::uml2cpp(bool rec) {
  if (isCppExternal())
    set_CppDecl(CppSettings::externalClassDecl());
  else {
    QCString st = CppSettings::classStereotype(stereotype());
    UmlItem * pack = parent()->parent();
    
    while (pack->kind() != aPackage)
      pack = pack->parent();
    
    if ((st == "stereotype") ||
	(st == "metaclass") ||
	(pack->stereotype() == "profile")) {
      set_CppDecl("");
      return;
    }
    
    if (st == "enum")
      set_CppDecl(CppSettings::enumDecl());
    else if (st == "union")
      set_CppDecl(CppSettings::unionDecl());
    else if (st == "struct")
      set_CppDecl(CppSettings::structDecl());
    else if (st == "typedef")
      set_CppDecl(CppSettings::typedefDecl());
    else if (st == "ignored") {
      set_CppDecl("");
      return;
    }
    else
      set_CppDecl(CppSettings::classDecl());
    
    if (rec) {
      const QVector<UmlItem> ch = children();
      unsigned n = ch.size();
      
      for (unsigned i = 0; i != n; i += 1)
	ch[i]->uml2cpp(rec);
    }
    
    if (parent()->kind() == aClassView) {
      // not nested
      UmlArtifact * art = artifact();
			 
      art->set_CppSource(CppSettings::sourceContent());
      art->set_CppHeader(CppSettings::headerContent());
    }
  }
}
Beispiel #2
0
UmlArtifact * UmlArtifact::made(UmlDeploymentView * depl_view,
				const Q3CString & s)
{
  UmlArtifact * art = UmlBaseArtifact::create(depl_view, s);
  
  if (art == 0) {
    Q3CString msg = "can't create artifact " + s + " in " + depl_view->name() + "<br>\n";
    
    UmlCom::trace(msg);
    throw 0;
  }
  
  UmlCom::trace("add artifact " + s + "<br>\n");
  art->set_Stereotype("source");
  art->set_CppHeader(CppSettings::headerContent());
  art->set_CppSource(CppSettings::sourceContent());
  art->set_JavaSource(JavaSettings::sourceContent());
  
  return art;
}
Beispiel #3
0
UmlArtifact * UmlClass::artifact() {
  // note : class is not nested
  UmlArtifact * art = associatedArtifact();
  
  if (art == 0) {
    UmlDeploymentView * depl =	((UmlClassView *) parent())->deploymentView();
    
    art = UmlArtifact::create(depl, name());
    
    if (art == 0) {
      UmlCom::trace("<b>cannot create artifact '" +
		    name() + "' in deployment view '" + depl->name() + "'</b><br>");
      throw 0;
    }
    
    art->set_Stereotype("source");
    art->addAssociatedClass(this);
  }

  return art;
}
Beispiel #4
0
void UmlArtifact::importIt(FileIn & in, Token & token, UmlItem * where)
{
    where = where->container(anArtifact, token, in);

    if (where == 0)
        return;

    WrapperStr s = token.valueOf("name");

    if (s.isEmpty()) {
        static unsigned n = 0;

        s.sprintf("anonymous_artifact_%u", ++n);
    }

    UmlArtifact * artifact = create((UmlDeploymentView *) where, s);

    if (artifact == 0)
        in.error("cannot create artifact '" + s +
                 "' in '" + where->name() + "'");

    artifact->addItem(token.xmiId(), in);

    if (! token.closed()) {
        WrapperStr k = token.what();
        const char * kstr = k;

        while (in.read(), !token.close(kstr)) {
            if (token.what() == "manifestation")
                Manifestation::import(in, token, artifact);
            else
                artifact->UmlItem::import(in, token);
        }
    }

    artifact->unload(TRUE, FALSE);
}
Beispiel #5
0
void UmlClass::upload(ClassContainer * cnt)
{
    UmlArtifact * art = associatedArtifact();
    WrapperStr na;

    if (art != 0) {
        na = ((UmlPackage *) art->parent()->parent())->cppNamespace();

        if (! na.isEmpty())
            Namespace::set(na);
    }

    the_class = cnt->upload_define(this);

    const QVector<UmlItem*> & ch = UmlItem::children();
    QVectorIterator<UmlItem*> it(ch);
    while(it.hasNext())
    {
        it.next()->upload(the_class);;
    }

    if (! na.isEmpty())
        Namespace::unset();
}
Beispiel #6
0
void UmlPackage::reverse_main(const Q3CString & type, Q3CString comment) {
  // do not lost main !
  Lex::mark();
  UmlOperation::skip_body();
  
  UmlArtifact * cp;
  
#ifdef ROUNDTRIP
  bool roundtrip = FALSE;
  
  if ((cp = UmlArtifact::get_main()) != 0) {
    roundtrip = TRUE;
    cp->set_usefull();
  }
  else
#endif
  if ((cp = UmlBaseArtifact::create(get_deploymentview(0), "main")) == 0) {
    UmlCom::trace("<font face=helvetica><b>cannot create <i>artifact main</i></b></font><br><hr>");
    return;
  }
  
  if (! comment.isEmpty()) {
    unsigned start = 0;
    
    do {
      comment.insert(start, "//");
      start = comment.find('\n', start + 2) + 1;
    } while (start != 0);
    comment.append("\n\n");
  }
  
  comment.append(type);
  comment.append(" main(");
  comment.append(Lex::region());
  comment.append("\n");
  
#ifdef ROUNDTRIP
  if (roundtrip) {
    if (cp->cppSource() != comment)
      cp->set_CppSource(comment);
    return;
  }
#endif
  
  cp->set_Stereotype("source");
  cp->set_CppSource(comment);
  cp->set_CppHeader(0);
}
Beispiel #7
0
void CppRefType::compute(Q3PtrList<CppRefType> & dependencies,
                         const WrapperStr & hdef, const WrapperStr & srcdef,
                         WrapperStr & h_incl,  WrapperStr & decl, WrapperStr & src_incl,
                         UmlArtifact * who)
{
    UmlPackage * pack = who->package();
    WrapperStr hdir;
    WrapperStr srcdir;

    if (CppSettings::isRelativePath()) {
        WrapperStr empty;

        hdir = pack->header_path(empty);
        srcdir = pack->source_path(empty);
    }
    else if (CppSettings::isRootRelativePath())
        hdir =  srcdir = UmlPackage::rootDir();

    // aze.cpp includes aze.h
    src_incl += "#include \"";

    if (CppSettings::includeWithPath())
        src_incl += pack->header_path(who->name(), srcdir);
    else {
        src_incl += who->name();
        src_incl += '.';
        src_incl += CppSettings::headerExtension();
    }

    src_incl += "\"\n";
    h_incl = "";	// to not be WrapperStr::null
    decl = "";	// to not be WrapperStr::null

    CppRefType * ref;

    for (ref = dependencies.first(); ref != 0; ref = dependencies.next())
    {
        UmlClass * cl = (ref->type.type)
                        ? ref->type.type
                        : UmlBaseClass::get(ref->type.explicit_type, 0);
        bool included = ref->included;

        WrapperStr hform;	// form in header
        WrapperStr srcform;	// form in source

        if (cl == 0) {
            WrapperStr in = CppSettings::include(ref->type.explicit_type);

            if (!in.isEmpty())
                hform = srcform = in + '\n';
            else
                // doesn't know what it is
                continue;
        }
        else if (cl->isCppExternal())
        {
            QString className = cl->name();
            hform = cl->cppDecl();

            int index;

            if ((index = hform.find('\n')) == -1)
                // wrong form
                continue;

            hform = hform.mid(index + 1) + '\n';

            for (;;) {
                if ((index = hform.find("${name}")) != -1)
                    hform.replace(index, 7, cl->name());
                else if ((index = hform.find("${Name}")) != -1)
                    hform.replace(index, 7, capitalize(cl->name()));
                else if ((index = hform.find("${NAME}")) != -1)
                    hform.replace(index, 7, cl->name().upper());
                else if ((index = hform.find("${nAME}")) != -1)
                    hform.replace(index, 7, cl->name().lower());
                else
                    break;
            }

            srcform = hform;
        }
        else {
            QString className = cl->name();
            WrapperStr st = cl->cpp_stereotype();

            if ((st == "enum") || (st == "typedef"))
                included = TRUE;

            UmlArtifact * art = cl->associatedArtifact();

            if (art != 0) {
                if (art == who)
                    // don't include itself
                    continue;

                if (CppSettings::includeWithPath()) {
                    UmlPackage * p = art->package();

                    hform = "#include \"" + p->header_path(art->name(), hdir) + "\"\n";
                    srcform = "#include \"" + p->header_path(art->name(), srcdir) + "\"\n";
                }
                else
                    srcform = hform = "#include \"" + art->name() + '.' +
                                      CppSettings::headerExtension() + "\"\n";
            }
            else if (cl->parent()->kind() != aClass) {
                write_trace_header();
                UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b> class<i> ") + cl->name() +
                              "</i> referenced but does not have associated <i>artifact</i></b></font><br>");
                incr_warning();
                continue;
            }
        }

        if (included) {
            // #include must be placed in the header file
            if ((h_incl.find(hform) == -1) && (hdef.find(hform) == -1))
                h_incl += hform;
        }
        else if ((cl != 0) &&
                 (cl->parent()->kind() != aClass)) {	// else too complicated
            // #include useless in header file, place it in the source file
            if ((src_incl.find(srcform) == -1) && (h_incl.find(hform) == -1) &&
                (hdef.find(hform) == -1) && (srcdef.find(srcform) == -1))
                src_incl += srcform;

            if (!cl->isCppExternal()) {
                // header file must contains the declaration
                hform = cl->decl();

                if (decl.find(hform) == -1)
                    decl += hform;

                if ((cl->associatedArtifact() == 0) &&
                    (cl->parent()->kind() != aClass)) {
                    write_trace_header();
                    UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b> class<i> ") + cl->name() +
                                  "</i> referenced but does not have associated <i>artifact</i></b></font><br>");
                    incr_warning();
                }
            }
        }
        else if (!hform.isEmpty()) {
            // have the #include form but does not know if it is a class or other,
            // generate the #include in the header file EXCEPT if the #include is
            // already in the header/source file to allow to optimize the generated
            // code
            if ((src_incl.find(srcform) == -1) && (h_incl.find(hform) == -1) &&
                (hdef.find(hform) == -1) && (srcdef.find(srcform) == -1))
                h_incl += hform;
        }
    }
}
Beispiel #8
0
void UmlArtifact::gen_app(const Q3CString & path) {
  Q3CString target;
  Q3CString pro;

  propertyValue("genpro target", target);
  propertyValue("genpro pro", pro);

  if (target.isEmpty()) {
    if ((target = name()) == "executable")
      target = UmlPackage::getProject()->name();
#ifdef WIN32
    target += ".exe";
#endif
  }

  if (pro.isEmpty()) {
    pro = target;
#ifdef WIN32
    if (pro.right(4) == ".exe")
      pro.resize(pro.length() - 4);
#endif
    
    QDir d(path);
    
    pro = d.absFilePath(pro + ".pro");
  }

  Q3CString tmplt;
  Q3CString config;
  Q3CString defines;
  Q3CString includepath;
  Q3CString dependpath;
  Q3CString objectsdir;
  Q3CString footer;

  if (!propertyValue("genpro tmplt", tmplt))
    tmplt = "app";
  if (!propertyValue("genpro config", config))
    config = "debug warn_on qt";
  if (!propertyValue("genpro defines", defines))
    defines = "WITHCPP WITHJAVA WITHPHP WITHPYTHON WITHIDL";
  else if (defines.find("WITHPHP") == -1) {
    int n = 0;
    
    if (defines.find("WITHCPP") != -1)
      n += 1;
    
    if (defines.find("WITHJAVA") != -1)
      n += 1;
    
    if (defines.find("WITHIDL") != -1)
      n += 1;
    
    if (n > 1)
      defines += " WITHPHP WITHPYTHON";
  }
  else if (defines.find("WITHPYTHON") == -1) {
    int n = 0;
    
    if (defines.find("WITHCPP") != -1)
      n += 1;
    
    if (defines.find("WITHJAVA") != -1)
      n += 1;
    
    if (defines.find("WITHIDL") != -1)
      n += 1;
    
    if (defines.find("WITHPHP") != -1)
      n += 1;
    
    if (n > 1)
      defines += " WITHPYTHON";
  }
  propertyValue("genpro includepath", includepath);
  propertyValue("genpro dependpath", dependpath);
  propertyValue("genpro objectsdir", objectsdir);
  propertyValue("genpro footer", footer);
  
  for (;;) {
    Dialog dialog(this, path, pro, target, tmplt, config, defines,
		  includepath, dependpath, objectsdir, footer);
    
    if (dialog.exec() != QDialog::Accepted)
      return;
    
    set_PropertyValue("genpro pro", pro);
    set_PropertyValue("genpro path", path);
    set_PropertyValue("genpro target", target);
    set_PropertyValue("genpro tmplt", tmplt);
    set_PropertyValue("genpro config", config);
    set_PropertyValue("genpro defines", defines);
    set_PropertyValue("genpro includepath", includepath);
    set_PropertyValue("genpro dependpath", dependpath);
    set_PropertyValue("genpro objectsdir", objectsdir);
    set_PropertyValue("genpro footer", footer);

    QFile f(pro);
    
    if (! f.open(QIODevice::WriteOnly))
      QMessageBox::critical((QWidget *) 0, "Error", "Cannot open " + QString(pro));
    else {
      Q3TextStream t(&f);
      QFileInfo tfi(target);
      QFileInfo pfi(pro);
      
      t << "TEMPLATE\t= " << tmplt << '\n';
      t << "TARGET\t\t= " << tfi.fileName() << '\n';
      if ((target.find('/') != -1) &&
	  (pro.find('/') != -1) &&
	  (tfi.dirPath(TRUE) != pfi.dirPath(TRUE)))
	t << "DESTDIR\t\t= " << tfi.dirPath(TRUE) << '\n';
      if (! objectsdir.isEmpty())
	t << "OBJECTS_DIR\t= " << objectsdir << '\n';
      t << "CONFIG\t\t+= " << config << '\n';
      if (!includepath.isEmpty())
	t << "INCLUDEPATH\t= " << includepath << '\n';
      if (!dependpath.isEmpty())
	t << "DEPENDPATH\t= " << dependpath << '\n';
      if (!defines.isEmpty())
	t << "DEFINES\t\t= " << defines << '\n';
      
      QString prodir = pfi.dirPath(TRUE);
      const Q3PtrVector<UmlArtifact> & arts = associatedArtifacts();
      unsigned index;
      const char * sep;
      Q3CString ext;
      
      ext = CppSettings::headerExtension();
      sep = "HEADERS\t\t= ";
      for (index = 0; index != arts.count(); index += 1) {
	UmlArtifact * art = arts[index];
	
	if ((art->stereotype() == "source") && !art->cppHeader().isEmpty()) {
	  QString s = art->way(prodir, TRUE);
	  
	  if (! s.isEmpty()) {
	    t << sep << s << art->name() << '.' << ext;
	    sep = " \\\n\t\t  ";
	  }
	}
      }
      
      t << '\n';
      
      ext = CppSettings::sourceExtension();
      sep = "SOURCES\t\t= ";
      for (index = 0; index != arts.count(); index += 1) {
	UmlArtifact * art = arts[index];
	
	if ((art->stereotype() != "source") || !art->cppSource().isEmpty()) {
	  QString s = art->way(prodir, FALSE);
	  
	  if (! s.isEmpty()) {
	    t << sep << s << art->name();
	    if (art->stereotype() == "source")
	      t << '.' << ext;
	    sep = " \\\n\t\t  ";
	  }
	}
      }
      
      t << '\n' << footer << '\n';
      
      f.close();
      return;
    }
  }
}
Beispiel #9
0
void Package::reverse_file(WrapperStr path, WrapperStr name)
{
    if (! Lex::open(path)) {
        // very strange !
        if (! scan)
            UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot open <i>")
                          + path + "</i></b></font><br>");
    }
    else {
        UmlArtifact * art = 0;
        WrapperStr file_start;
        WrapperStr file_end;

        UmlCom::message(((scan) ? "scan " : "reverse ") + path);

        // go after <?[php]
        Lex::mark();

        bool redo;
        bool before_class;

        do {
            redo = FALSE;
            before_class = TRUE;

            WrapperStr s;
            char c = Lex::read_word_bis();

            while (c != 0) {
                if (c == '<') {
                    c = Lex::read_word_bis();

                    if (c == '?') {
                        if (!scan) file_start = Lex::region();

                        s = Lex::read_word();

                        if (s.lower() == "php") {
                            if (!scan) file_start = Lex::region();

                            s = Lex::read_word();
                        }

                        break;
                    }
                }
                else
                    c = Lex::read_word_bis();
            }

            aVisibility visibility = PackageVisibility;
            bool abstractp = FALSE;
            bool finalp = FALSE;
            bool inside_namespace_brace = FALSE;

            while (!s.isEmpty()) {
                if ((s == "class") || (s == "interface")) {
#ifdef REVERSE

                    if (!scan && (art == 0)) {
                        UmlPackage * pack = get_uml(TRUE);

                        if ((art = UmlBaseArtifact::create(pack->get_deploymentview(Namespace::current()), name)) == 0) {
                            UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create<i> artifact ")
                                          + name + "</i></b></font><br>");
                            Namespace::exit();
                            Lex::close();
                            return;
                        }

                        art->set_Stereotype("source");
                    }

#endif

                    if (!Class::reverse(this, s, abstractp, finalp, path, art))
                        break;

                    visibility = PackageVisibility;
                    abstractp = FALSE;
                    finalp = FALSE;

                    before_class = FALSE;
                    Lex::mark();
                }
                else if (s == "public")
                    visibility = PublicVisibility;
                else if (s == "protected")
                    visibility = ProtectedVisibility;
                else if (s == "private")
                    visibility = PrivateVisibility;
                else if (s == "final")
                    finalp = TRUE;
                else if (s == "abstract")
                    abstractp = TRUE;
                else if ((s == "namespace") && before_class) {
                    Namespace::exit();

                    s = Lex::read_word();

                    if (s == "{")
                        inside_namespace_brace = TRUE;
                    else if (s.isEmpty()) {
                        if (!scan)
                            Lex::premature_eof();

                        break;
                    }
                    else {
                        Namespace::enter(s);
                        s = Lex::read_word();

                        if (s == "{")
                            inside_namespace_brace = TRUE;

                        // else is ';'
                    }
                }
                else if ((s == "use") && before_class) {
                    if (!scan)
                        use();
                    else
                        UmlOperation::skip_body(0);

                    Lex::finish_line();
                    Lex::clear_comments();
                }
                else if ((s == "}") && inside_namespace_brace) {
                    inside_namespace_brace = FALSE;
                    Namespace::exit();
                }
                else if (s != ";") {
                    if (before_class) {
                        if ((s == "?") && ((s = Lex::read_word()) == ">")) {
                            // this <?php ..?> doesn't contains classes
                            // search for a next <?php ..?>
                            redo = TRUE;
                            Lex::clear_comments();

                            if (!scan)
                                file_start = Lex::region();

                            break;
                        }

                        UmlOperation::skip_body(0);
                        Lex::finish_line();
                        Lex::clear_comments();

                        if (!scan)
                            file_start = Lex::region();
                    }
                    else if (!scan) {
                        // go to end of file
                        while (Lex::read_word_bis() != 0)
                            ;

                        file_end = Lex::region();
                        break;
                    }
                    else
                        break;
                }

                s = Lex::read_word();
            }
        }
        while (redo);

#ifdef REVERSE

        if (! scan) {
            if (art == 0) {
                UmlPackage * pack = get_uml(TRUE);

                if ((art = UmlBaseArtifact::create(pack->get_deploymentview(Namespace::current()), name)) == 0) {
                    UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create<i> artifact ")
                                  + name + "</i></b></font><br>");
                    Namespace::exit();
                    Lex::close();
                    return;
                }

                art->set_Stereotype("source");
            }

            if (before_class)
                art->set_PhpSource(file_start);
            else if (!Namespace::current().isEmpty()) {
                int p1 = file_start.operator QString().lastIndexOf("namespace");
                int p2 = file_start.find(';', p1);
                int p3 = file_start.find('{', p1);

                if ((p3 != -1) && ((p3 < p2) || (p2 == -1)))
                    file_start.replace(p1, p3 - p1 + 1, "${namespace}");
                else
                    file_start.replace(p1, p2 - p1 + 1, "${namespace}");

                art->set_PhpSource(file_start + "\n${definition}\n\n" + file_end);
            }
            else
                art->set_PhpSource(file_start + "\n${definition}\n\n" + file_end);

            art->unload();
        }

#endif

        Namespace::exit();

        Lex::close();
    }
}
Beispiel #10
0
void UmlClass::need_artifact(const WrapperStr & nmsp)
{
    if (parent()->kind() == aClassView) {
        UmlArtifact * cp;

        if ((cp = associatedArtifact()) == 0) {
            // search artifact
#ifdef ROUNDTRIP
            if ((cp = Package::get_artifact()) != 0) {
                cp->addAssociatedClass(this);
                return;
            }

#endif

            WrapperStr name = Package::get_fname();
            int index;

            if (name.isEmpty()) {
                // defined in a source rather than a header
                // will create it own artifact
                name = this->name();
                index = name.find('<');

                if (index != -1)
                    name = name.left(index);
            }

            UmlDeploymentView * cpv =
                ((UmlPackage *) parent()->parent())->get_deploymentview(nmsp);
            const QVector<UmlItem*> & children = cpv->children();
            int n = (int) children.count();

            for (index = 0; index != n; index += 1) {
                if ((children[index]->name() == name) &&
                    (children[index]->kind() == anArtifact)) {
                    cp = (UmlArtifact *) children[index];
                    break;
                }
            }

            if (cp == 0) {
                // does not exist, create associated artifact
                if ((cp = UmlBaseArtifact::create(cpv, name))
                    == 0) {
#ifdef REVERSE
                    UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create artifact <i>")
                                  + Lex::quote(name) + "</i> under <i>"
                                  + Lex::quote(cpv->name()) +
                                  "</b></font><br>");
                    UmlCom::message("");
                    throw 0;
#else
                    QMessageBox::critical(0, "Fatal Error",
                                          WrapperStr("<font face=helvetica><b>cannot create artifact <i>")
                                          + Lex::quote(name) + "</i> under <i>"
                                          + Lex::quote(cpv->Name()) + "</b></font><br>");
                    QApplication::exit(1);
#endif
                }

                cp->set_Stereotype("source");
                cp->set_CppHeader(CppSettings::headerContent());
            }

            cp->addAssociatedClass(this);
        }

        // source needed ?

        if (need_source() && cp->cppSource().isEmpty())
            cp->set_CppSource(CppSettings::sourceContent());
    }
}