Example #1
0
void UmlArtifact::generate_text()
{
    const WrapperStr srcdef = javaSource();

    if (srcdef.isEmpty()) {
        if (verbose())
            UmlCom::trace(WrapperStr("<hr><font face=helvetica>artifact <i>")
                          + name() + "</i> has an empty Java definition</font><br>");

        return;
    }

    UmlPackage * pack = package();
    const WrapperStr & name = UmlArtifact::name();
    WrapperStr src_path = pack->text_path(name);

    WrapperStr s = " in <i> " + src_path + "</i>";

    UmlCom::message(name);

    if (verbose())
        UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ")
                      + name + "</i>" + s + "</font><br>");
    else
        set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ")
                         + name + "</i>" + s + "</font><br>");

    if (must_be_saved(src_path, (const char *) srcdef)) {
        write_trace_header();

        FILE * fp_src;

        if ((fp_src = fopen((const char *) src_path, "wb")) == 0) {
            write_trace_header();
            UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                          + name + " : </i> cannot open <i> "
                          + src_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                          + pack->name() + "</i> Java directory specification</b></font><br>");
            incr_error();
        }
        else {
            fputs((const char *) srcdef, fp_src);
            fclose(fp_src);
        }
    }
    else if (get_trace_header().isEmpty())
        UmlCom::trace(WrapperStr("<font face=helvetica><i> ")
                      + src_path + "</i> not modified</font><br>");
}
Example #2
0
void UmlOperation::generate_enum_pattern_item(QTextStream &, int &,
        const WrapperStr &, WrapperStr)
{
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum</i> cannot have operation</b></font><br>");
    incr_warning();
}
Example #3
0
static void param_error(const WrapperStr & parent, const WrapperStr & name, unsigned rank)
{
    write_trace_header();
    UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>while compiling <i>")
                  + parent + "::" + name + "</i> parameter rank " + WrapperStr().setNum(rank)
                  + " does not exist</font></b><br>");
    incr_error();
}
Example #4
0
void UmlRelation::generate_implements(const char *& sep, QTextOStream & f,
                                      const Q3ValueList<UmlActualParameter> & actuals,
                                      const Q3CString & cl_stereotype) {
    switch (relationKind()) {
    default:
        return;
    case aGeneralisation:
    case aRealization:
        if (javaDecl().isEmpty())
            return;

        UmlClass * role_type = roleType();
        const Q3CString & other_stereotype = role_type->java_stereotype();

        if ((other_stereotype == "interface") || (other_stereotype == "@interface")) {
            if ((cl_stereotype == "union") || (cl_stereotype == "enum_pattern")) {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                              + cl_stereotype + "</i> cannot inherits</b></font><br>");
                incr_warning();
            }
            else {
                f << sep;
                sep = ", ";

                const char * p = javaDecl();

                while (*p) {
                    if (!strncmp(p, "${type}", 7)) {
                        role_type->write(f);
                        p += 7;

                        if (!actuals.isEmpty()) {
                            Q3ValueList<UmlActualParameter>::ConstIterator ita;
                            bool used = FALSE;

                            for (ita = actuals.begin(); ita != actuals.end(); ++ita) {
                                if ((*ita).superClass() == role_type) {
                                    used = TRUE;
                                    (*ita).generate(f);
                                }
                            }

                            if (used) {
                                f << ">";
                            }
                        }
                    }
                    else if (*p == '@')
                        manage_alias(p, f);
                    else
                        f << *p++;
                }
            }
        }
    }
}
Example #5
0
void erts_mtrace_init(char *receiver, char *nodename)
{
    char hostname[MAXHOSTNAMELEN + 1];
    char pid[21]; /* enough for a 64 bit number */

    socket_desc = ERTS_SOCK_INVALID_SOCKET;
    erts_mtrace_enabled = receiver != NULL;

    if (erts_mtrace_enabled) {
	unsigned a, b, c, d, p;
	byte ip_addr[4];
	Uint16 port;

        erts_mtx_init(&mtrace_buf_mutex, "mtrace_buf", NIL,
            ERTS_LOCK_FLAGS_PROPERTY_STATIC | ERTS_LOCK_FLAGS_CATEGORY_DEBUG);
        erts_mtx_init(&mtrace_op_mutex, "mtrace_op", NIL,
            ERTS_LOCK_FLAGS_PROPERTY_STATIC | ERTS_LOCK_FLAGS_CATEGORY_DEBUG);

	socket_desc = erts_sock_open();
	if (socket_desc == ERTS_SOCK_INVALID_SOCKET) {
	    disable_trace(1, "Failed to open socket", erts_sock_errno());
	    return;
	}

	if (5 != sscanf(receiver, "%u.%u.%u.%u:%u", &a, &b, &c, &d, &p)
	    || a >= (1 << 8) || b >= (1 << 8)|| c >= (1 << 8) || d >= (1 << 8)
	    || p >= (1 << 16)) {
	    disable_trace(1, "Invalid receiver address", 0);
	    return;
	}

	ip_addr[0] = (byte) a;
	ip_addr[1] = (byte) b;
	ip_addr[2] = (byte) c;
	ip_addr[3] = (byte) d; 

	port = (Uint16) p;

	if (!erts_sock_connect(socket_desc, ip_addr, 4, port)) {
	    disable_trace(1, "Failed to connect to receiver",
			  erts_sock_errno());
	    return;
	}
	tracep = trace_buffer;
	endp = trace_buffer + TRACE_BUF_SZ;
        /* gethostname requires that the len is max(hostname) + 1 */
	if (erts_sock_gethostname(hostname, MAXHOSTNAMELEN + 1) != 0)
	    hostname[0] = '\0';
	hostname[MAXHOSTNAMELEN] = '\0';
	sys_get_pid(pid, sizeof(pid));
	write_trace_header(nodename ? nodename : "", pid, hostname);
	erts_mtrace_update_heap_size();
    }
}
Example #6
0
void UmlRelation::generate_implements(const char *& sep, QTextStream & f,
                                      const Q3CString & cl_stereotype) {
    switch (relationKind()) {
    default:
        return;
    case aGeneralisation:
    case aRealization:
        if (phpDecl().isEmpty())
            return;

        UmlClass * role_type = roleType();
        const Q3CString & other_stereotype = role_type->php_stereotype();

        if (other_stereotype == "interface") {
            if (cl_stereotype == "union") {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                              + cl_stereotype + "</i> cannot inherits</b></font><br>");
                incr_warning();
            }
            else {
                f << sep;
                sep = ", ";

                const char * p = phpDecl();

                while (*p) {
                    if (!strncmp(p, "${type}", 7)) {
                        role_type->write(f);
                        p += 7;
                    }
                    else if (*p == '@')
                        manage_alias(p, f);
                    else
                        f << *p++;
                }
            }
        }
    }
}
Example #7
0
void UmlAttribute::compute_dependency(Q3PtrList<CppRefType> & dependency,
				      const Q3CString & cl_stereotype,
				      bool all_in_h) {
  if ((cl_stereotype == "enum") || (cl_stereotype == "typedef"))
    return;
  
  Q3CString decl = cppDecl();
  
  int index;
  
  if ((index = decl.find("${static}")) != -1)
    decl.remove((unsigned) index, 9);
  if ((index = decl.find("${mutable}")) != -1)
    decl.remove((unsigned) index, 10);
  if ((index = decl.find("${volatile}")) != -1)
    decl.remove((unsigned) index, 11);
  if ((index = decl.find("${const}")) != -1)
    decl.remove((unsigned) index, 8);
  if ((index = decl.find("${multiplicity}")) != -1)
    decl.remove((unsigned) index, 15);
  if ((index = decl.find("${value}")) != -1)
    decl.remove((unsigned) index, 8);
  if ((index = decl.find("${h_value}")) != -1)
    decl.remove((unsigned) index, 10);
  if ((index = decl.find("${name}")) != -1)
    decl.remove((unsigned) index, 7);
  if ((index = decl.find("${stereotype}")) != -1)
    decl.replace((unsigned) index, 13,
		 CppSettings::relationAttributeStereotype(stereotype()));
  replace_alias(decl);

  if (!UmlClassMember::compute_dependency(dependency, decl, type(), all_in_h)) {
    write_trace_header();
    UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>type missing for attribute <i>")
		  + name() + "</i></b></font><br>");
    incr_error();
  }
}
Example #8
0
void UmlRelation::generate_extends(const char *& sep, QTextStream & f,
                                   const Q3CString & cl_stereotype) {
    switch (relationKind()) {
    default:
        return;
    case aGeneralisation:
    case aRealization:
        if (phpDecl().isEmpty())
            return;

        UmlClass * role_type = roleType();
        const Q3CString & other_stereotype = role_type->php_stereotype();

        if ((cl_stereotype == "interface") || (cl_stereotype == "@interface")) {
            if ((other_stereotype != "interface") && (other_stereotype != "@interface")) {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot extends a <i>")
                              + other_stereotype + "</i></b></font><br>");
                incr_warning();
                return;
            }
        }
        else if ((other_stereotype != "interface") && (other_stereotype != "@interface")) {
            if (cl_stereotype == "union") {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                              + cl_stereotype + "</i> cannot extends</b></font><br>");
                incr_warning();
                return;
            }
            else if ((other_stereotype == "union") ||
                     (other_stereotype == "enum")) {
                write_trace_header();
                UmlCom::trace(Q3CString("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot extends an <i>")
                              + other_stereotype + "</i></b></font><br>");
                incr_warning();
                return;
            }
            else if (*sep == ',') {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>extend several classes</b></font><br>");
                incr_warning();
                return;
            }
        }
        else
            return;

        // here the code is legal
        f << sep;
        sep = ", ";

        const char * p = phpDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else
                f << *p++;
        }
    }
}
Example #9
0
void UmlArtifact::generate()
{
    if (! managed) {
        managed = TRUE;

        if (stereotype() == "text") {
            generate_text();
            return;
        }
        else if (stereotype() != "source")
            return;

        package_of_generated_artifact = package();
        current = this;

        const WrapperStr filedef = javaSource();

        if (filedef.isEmpty())
            return;

        const WrapperStr & name = this->name();
        WrapperStr path = package_of_generated_artifact->file_path(name);

        UmlCom::message(name);

        if (verbose())
            UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ")
                          + name + "</i> in " + path + "</i></font><br>");
        else
            set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ")
                             + name + "</i> in " + path + "</i></font><br>");

        // get bodies if preserve
        const QVector<UmlClass*> & cls = associatedClasses();

        if (preserve())
            UmlOperation::read_bodies(path);

        // generate file

        unsigned n = cls.count();
        unsigned index;
        WrapperStr incl;
        QSharedPointer<QByteArray> headerFile(new QByteArray());
        QTextStream f(headerFile.data(), QIODevice::WriteOnly);
        const char * p = filedef;
        const char * pp = 0;

        for (;;) {
            if (*p == 0) {
                if (pp == 0)
                    break;

                // comment management done
                p = pp;
                pp = 0;

                if (*p == 0)
                    break;
            }

            if (*p == '@')
                manage_alias(p, f);
            else if (*p != '$')
                f << *p++;
            else if (!strncmp(p, "${comment}", 10))
                manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment());
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${name}", 7)) {
                p += 7;
                f << name;
            }
            else if (!strncmp(p, "${Name}", 7)) {
                p += 7;
                f << capitalize(name);
            }
            else if (!strncmp(p, "${NAME}", 7)) {
                p += 7;
                f << name.upper();
            }
            else if (!strncmp(p, "${nAME}", 7)) {
                p += 7;
                f << name.lower();
            }
            else if (!strncmp(p, "${imports}", 10)) {
                WrapperStr indent = current_indent(p, filedef);

                for (index = 0; index != n; index += 1)
                    cls[index]->generate_import(f, indent);

                p += 10;

                if (*p == '\n')
                    p += 1;
            }
            else if (!strncmp(p, "${package}", 10)) {
                p += 10;

                const WrapperStr & package = package_of_generated_artifact->javaPackage();

                if (!package.isEmpty())
                    f << "package " << package << ";\n\n";

                if (*p == '\n')
                    p += 1;
            }
            else if (!strncmp(p, "${definition}", 13)) {
                WrapperStr indent = current_indent(p, filedef);

                for (index = 0; index != n; index += 1)
                    cls[index]->generate(f, indent);

                p += 13;

                if (*p == '\n')
                    p += 1;
            }
            else
                // strange
                f << *p++;
        }

        f << '\000';
        f.flush();

        if (must_be_saved(path, headerFile->data())) {
            write_trace_header();

            FILE * fp;

            if ((fp = fopen((const char *) path, "wb")) == 0) {
                write_trace_header();
                UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                              + name + "</i> : cannot open <i> "
                              + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                              + package_of_generated_artifact->name()
                              + "</i> Java directory specification</b></font><br>");
                incr_error();
            }
            else {
                fputs((const char *) headerFile->data(), fp);
                fclose(fp);
            }
        }
        else if (get_trace_header().isEmpty())
            UmlCom::trace(WrapperStr("<font face=helvetica><i> ")
                          + path + "</i> not modified</font><br>");

        if (imports != 0) {
            delete imports;
            imports = 0;
        }
    }
}
Example #10
0
void UmlOperation::roundtrip(const char * path, aLanguage who)
{
    char * s = read_file(path);

    if (s != 0) {
        char * p1 = s;
        char * p2;
        WrapperStr(UmlOperation::*get_body)();
        bool (UmlOperation::*set_body)(const char * s);
        bool (UmlOperation::*set_contextualbodyindent)(bool v);
        const char * prefix;
        const char * postfix;

        switch (who) {
        case cppLanguage:
            get_body = &UmlOperation::cppBody;
            set_body = &UmlOperation::set_CppBody;
            set_contextualbodyindent = &UmlOperation::set_CppContextualBodyIndent;
            prefix = BodyPrefix;
            postfix = BodyPostfix;
            break;

        case javaLanguage:
            get_body = &UmlOperation::javaBody;
            set_body = &UmlOperation::set_JavaBody;
            set_contextualbodyindent = &UmlOperation::set_JavaContextualBodyIndent;
            prefix = BodyPrefix;
            postfix = BodyPostfix;
            break;

        case phpLanguage:
            get_body = &UmlOperation::phpBody;
            set_body = &UmlOperation::set_PhpBody;
            set_contextualbodyindent = &UmlOperation::set_PhpContextualBodyIndent;
            prefix = BodyPrefix;
            postfix = BodyPostfix;
            break;

        default:
            // python
            get_body = &UmlOperation::pythonBody;
            set_body = &UmlOperation::set_PythonBody;
            set_contextualbodyindent = &UmlOperation::set_PythonContextualBodyIndent;
            prefix = BodyPythonPrefix;
            postfix = BodyPythonPostfix;
        }

        while ((p2 = strstr(p1, prefix)) != 0) {
            p2 += BodyPrefixLength;

            char * body;
            long id = strtol(p2, &body, 16);

            if (body != (p2 + 8)) {
                UmlCom::trace(WrapperStr("<font color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid preserve body identifier</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 1");
            }

            if (*body == '\r')
                body += 1;

            if (*body == '\n')
                body += 1;
            else {
                UmlCom::trace(WrapperStr("<font  color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid preserve body block, end of line expected</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 2");
            }

            UmlOperation * op = (UmlOperation *)
                                UmlBaseItem::from_id((unsigned) id, anOperation);

            if (op == 0) {
                QString n("%1");
                n.arg(QString::number((unsigned) id));
                UmlCom::trace(WrapperStr("<font  color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid operation id " + n + "</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 3");
                return;
            }

            if (((p1 = strstr(body, postfix)) == 0) ||
                (strncmp(p1 + BodyPostfixLength, p2, 8) != 0)) {
                UmlCom::trace(WrapperStr("<font  color =\"red\"> Error in ") + path +
                              linenumber(s, p2 - BodyPrefixLength) +
                              " : invalid preserve body block, wrong balanced</font><br>");
                UmlCom::bye(n_errors() + 1);
                UmlCom::fatal_error("read_bodies 4");
            }

            p2 = p1;

            while ((p2 != body) && (p2[-1] != '\n'))
                p2 -= 1;

            char c = *p2;

            *p2 = 0;

            WrapperStr previous = (op->*get_body)();

            if (!op->isBodyGenerationForced() && (body != previous)) {
                if (!(op->*set_body)(body)) {
                    write_trace_header();
                    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot update body of <i>"
                                  + op->name() +
                                  ((op->isWritable()) ? "</i>, it is probably deleted</b></font><br>"
                                   : "</i>, it is read-only</b></font><br>"));
                    incr_error();
                }
                else {
                    (op->*set_contextualbodyindent)(FALSE);

                    write_trace_header();
                    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;update body of <i>"
                                  + op->name() + "</i><br>");
                }
            }
            else if (verbose()) {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;body of <i>"
                              + op->name() + "</i> unchanged<br>");
            }

            *p2 = c;
            p1 += BodyPostfixLength + 8;
        }

        delete [] s;
    }
}
Example #11
0
void UmlRelation::generate_inherit(const char *& sep, QTextStream & f,
                                   const WrapperStr & cl_stereotype,
                                   BooL & already)
{
    if ((relationKind() == aGeneralisation) || (relationKind() == aRealization)) {
        UmlClass * role_type = roleType();
        WrapperStr other_stereotype = role_type->idl_stereotype();

        if (other_stereotype == "ignored")
            return;

        if ((cl_stereotype == "union") || (cl_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                          + cl_stereotype + "</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }

        if ((other_stereotype == "union") ||
                (other_stereotype == "struct") ||
                (other_stereotype == "enum") ||
                (other_stereotype == "typedef")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot inherits an <i>")
                          + other_stereotype + "</i></b></font><br>");
            incr_warning();
            return;
        }

        if (cl_stereotype == "valuetype") {
            if (other_stereotype == "valuetype") {
                if (isIdlTruncatableInheritance())
                    f << sep << "truncatable ";
                else
                    f << sep;
            }
            else {
                // other_stereotype == "interface"
                if (!already) {
                    already = TRUE;
                    f << " supports ";
                }
                else
                    f << sep;
            }
        }
        else
            f << sep;

        const char * p = idlDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else
                f << *p++;
        }

        sep = ", ";
    }
}
Example #12
0
void UmlRelation::generate_enum_pattern_item(QTextStream &, int &,
					     const Q3CString &, Q3CString) {
  write_trace_header();
  UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum_pattern</i> cannot have relation</b></font><br>");
  incr_warning();
}
Example #13
0
void UmlClass::generate_enum_pattern_item(QTextOStream &, int &,
					  const QCString &, QCString) {
  write_trace_header();
  UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum pattern</i> cannot have sub-class</b></font><br>");
  incr_warning();
}
Example #14
0
void UmlArtifact::generate()
{
    if (! managed) {
        managed = TRUE;

        if (stereotype() == "text") {
            generate_text();
            return;
        }
        else if (stereotype() != "source")
            return;

        package_of_generated_artifact = package();

        const WrapperStr hdef = cppHeader();
        QLOG_INFO() << "Read header as: " + hdef.operator QString();
        const WrapperStr srcdef = cppSource();

        if (hdef.isEmpty() && srcdef.isEmpty()) {
            if (verbose())
                UmlCom::trace(WrapperStr("<hr><font face=helvetica>artifact <i>")
                              + name() + "</i> has an empty C++ definition</font><br>");

            return;
        }

        const WrapperStr & name = UmlArtifact::name();
        UmlPackage * pack = package();
        WrapperStr h_path = pack->header_path(name);
        WrapperStr src_path = pack->source_path(name);
        WrapperStr nasp_start;
        WrapperStr nasp_end;
        const char * cnasp = pack->cppNamespace();
        WrapperStr nasp = ((cnasp[0] == ':') && (cnasp[1] == ':'))
                         ? cnasp + 2 : cnasp;

        if (!nasp.isEmpty()) {
            int index = 0;
            int index2;
            WrapperStr closed = "\n} // namespace ";

            while ((index2 = nasp.find(':', index)) != -1) {
                WrapperStr na = nasp.mid(index, index2 - index);

                nasp_start += WrapperStr("namespace ") + na + " {\n\n";
                closed += na;
                nasp_end = closed + "\n" + nasp_end;
                closed += "::";
                nasp.replace(index2, 2, "_");
                index = index2 + 1;
            }

            nasp_start += WrapperStr("namespace ") + nasp.mid(index) + " {\n\n";
            closed += nasp.mid(index);
            nasp_end = closed + "\n" + nasp_end;
        }
        else {
            WrapperStr s;

            if (!hdef.isEmpty())
                s = " in <i> " + h_path + "</i>";

            if (!srcdef.isEmpty()) {
                if (!hdef.isEmpty())
                    s += " and <i> " + src_path + "</i>";
                else
                    s = " in <i> " + src_path + "</i>";
            }

            UmlCom::message(name);

            if (verbose())
                UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ")
                              + name + "</i>" + s + "</font><br>");
            else
                set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ")
                                 + name + "</i>" + s + "</font><br>");
        }

        // get bodies if preserve
        const Q3PtrVector<UmlClass> & cls = associatedClasses();

        if (preserve())
            UmlOperation::read_bodies(h_path, src_path);

        // compute dependencies

        bool all_in_h = (hdef.find("${all_includes}") != -1);
        Q3PtrList<CppRefType> dependencies;
        unsigned n = cls.count();
        unsigned index;

        for (index = 0; index != n; index += 1)
            cls[index]->compute_dependencies(dependencies, all_in_h);

        // generate header file

        WrapperStr h_incl;
        WrapperStr src_incl;
        WrapperStr decl;
        bool incl_computed = FALSE;

        if (!hdef.isEmpty()) {


            //headerFile->append("Test DAta");

            QLOG_INFO() << "openign file for writing: ";
            //QTextStream f_h(file.data()); //[lgfreitas] Now QTextStream receives a pointer to a byte array...
            QSharedPointer<QByteArray> headerFile(new QByteArray());
            QTextStream f_h(headerFile.data(), QFile::WriteOnly);
            f_h.setCodec(QTextCodec::codecForLocale());
            //QTextStream f_h(headerFile.data(), QIODevice::WriteOnly);
            //QString h_copy = QString(hdef.operator QString());
            const char * p = hdef;
            const char * pp = 0;

            for (;;)
            {
                QLOG_INFO() << "At this point P is: " << QString(p);
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;
                }


                if (*p == '@')
                    manage_alias(p, f_h);
                else if (*p != '$')
                {
                    QTextCodec* codec = QTextCodec::codecForLocale();
                    //f_h << codec->fromUnicode(*p,1);
                    //p++;
                    f_h << toLocale(p);
                }
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f_h << name;
                }
                else if (!strncmp(p, "${Name}", 7)) {
                    p += 7;
                    //QLOG_INFO() << "Outputting name: " << name;
                    f_h << capitalize(name);
                }
                else if (!strncmp(p, "${NAME}", 7)) {
                    p += 7;
                    f_h << name.upper();
                }
                else if (!strncmp(p, "${nAME}", 7)) {
                    p += 7;
                    f_h << name.lower();
                }
                else if (!strncmp(p, "${namespace}", 12)) {
                    p += 12;
                    f_h << nasp;
                }
                else if (!strncmp(p, "${NAMESPACE}", 12)) {
                    p += 12;
                    f_h << nasp.upper();
                }
                else if (!strncmp(p, "${includes}", 11)
                         || !strncmp(p, "${all_includes}", 15))
                {
                    QLOG_INFO() << "REaDING INCLUDES";
                    p += (p[2] == 'a') ? 15 : 11;
                    QLOG_INFO() << "Modified p 1 to be" << QString(p);
                    if (!incl_computed)
                    {
                        incl_computed = TRUE;
                        CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this);
                        QLOG_INFO() << "Modified hdef to be: " << hdef.operator QString();

                    }
                    QLOG_INFO() << "Modified p 2 to be" << QString(p);
                    if (!h_incl.isEmpty())
                    {
                        f_h << h_incl;

                        if (*p != '\n')
                            f_h << '\n';
                    }
                    else if (*p == '\n')
                        p += 1;
                    QLOG_INFO() << "FINISHED INCLUDES";
                }
                else if (!strncmp(p, "${declarations}", 15))
                {
                    p += 15;

                    if (!incl_computed)
                    {
                        incl_computed = TRUE;
                        CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this);
                    }
                    QLOG_INFO() << "DECLS IS: " << decl.operator QString();
                    if (!decl.isEmpty())
                    {
                        f_h << decl;

                        if (*p != '\n')
                            f_h << '\n';
                    }
                    else if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_start}", 18)) {
                    p += 18;

                    if (!nasp_start.isEmpty())
                        f_h << nasp_start;

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_end}", 16)) {
                    p += 16;

                    if (!nasp_end.isEmpty())
                        f_h << nasp_end;

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${definition}", 13)) {
                    p += 13;

                    for (index = 0; index != n; index += 1)
                        cls[index]->generate_decl(f_h, current_indent(p, hdef.operator QString()));

                    if (*p == '\n')
                        p += 1;
                }
                else
                    // strange
                    f_h << toLocale(p);
            }

            f_h << '\000';
            f_h.flush();

            if (must_be_saved(h_path, headerFile->data())) {
                QLOG_INFO() << "this is essentially what goes to the header file: " << headerFile->size();
                write_trace_header();

                //FILE * fp_h;
                 QFile file(h_path);
                if (!file.open(QFile::WriteOnly))
                {
                    UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                                  + name + "</i> : cannot open <i> "
                                  + h_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                                  + pack->name() + "</i> C++ directory specification</b></font><br>");
                    incr_error();
                }
                else {
                    QLOG_INFO() << "this is essentially what goes to the file: " << headerFile->constData();

                    QTextCodec* codec = QTextCodec::codecForLocale();
                    QTextStream out(&file);
                    out.setCodec(QTextCodec::codecForLocale());
                    QString temp(*headerFile.data());
                    out << codec->toUnicode(temp);
                    //out << *headerFile.data();
                    out.flush();
                }
            }
            else {
                WrapperStr th = get_trace_header();

                if (th.isEmpty())
                    UmlCom::trace(WrapperStr("<br><font face=helvetica><i> ")
                                  + h_path + "</i> not modified</font><br>");
                else
                    set_trace_header(th + "<font face=helvetica><i> "
                                     + h_path + "</i> not modified</font><br>");
            }
        }

        // generate source file

        if (!srcdef.isEmpty()) {
            QSharedPointer<QByteArray> file(new QByteArray());
            QTextStream f_src(file.data(), QIODevice::WriteOnly);
            const char * p = srcdef;
            const char * pp = 0;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;
                }

                if (*p == '@')
                    manage_alias(p, f_src);
                else if (*p != '$')
                    f_src << toLocale(p);
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${name}", 7)) {
                    // for file header
                    p += 7;
                    f_src << name;
                }
                else if (!strncmp(p, "${includes}", 11)) {
                    p += 11;

                    if (!incl_computed) {
                        incl_computed = TRUE;
                        CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this);
                    }

                    if (!src_incl.isEmpty()) {
                        f_src << src_incl;

                        if (*p != '\n')
                            f_src << '\n';
                    }
                    else if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${members}", 10)) {
                    p += 10;

                    for (index = 0; index != n; index += 1)
                        cls[index]->generate_def(f_src, current_indent(p, srcdef), FALSE);

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_start}", 18)) {
                    p += 18;

                    if (!nasp_start.isEmpty())
                        f_src << nasp_start;

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_end}", 16)) {
                    p += 16;

                    if (!nasp_end.isEmpty())
                        f_src << nasp_end;

                    if (*p == '\n')
                        p += 1;
                }
                else
                    // strange
                    f_src << toLocale(p);
            }

            f_src << '\000';
            f_src.flush();

            if (must_be_saved(src_path, file->data())) {
                write_trace_header();

                FILE * fp_src;

                if ((fp_src = fopen((const char *) src_path, "wb")) == 0) {
                    write_trace_header();
                    UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                                  + name + " : </i> cannot open <i> "
                                  + src_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                                  + pack->name() + "</i> C++ directory specification</b></font><br>");
                    incr_error();
                }
                else {
                    fputs((const char *) file->data(), fp_src);
                    fclose(fp_src);
                }
            }
            else if (get_trace_header().isEmpty())
                UmlCom::trace(WrapperStr("<font face=helvetica><i> ")
                              + src_path + "</i> not modified</font><br>");
        }
    }
}
Example #15
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;
        }
    }
}
Example #16
0
void UmlOperation::generate_decl(QTextStream & f,
                                 const WrapperStr & cl_stereotype,
                                 WrapperStr indent, bool)
{
    if (!idlDecl().isEmpty()) {
        if ((cl_stereotype != "interface") &&
                (cl_stereotype != "valuetype")) {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot have operation</b></font><br>");
            incr_warning();
            return;
        }

        const char * p = idlDecl();
        const char * pp = 0;
        const QList<UmlParameter> & params = this->params();
        const QList<UmlTypeSpec> & exceptions = this->exceptions();
        unsigned rank;

        while ((*p == ' ') || (*p == '\t'))
            indent += *p++;

        if (*p != '#')
            f << indent;

        for (;;) {
            if (*p == 0) {
                if (pp == 0)
                    break;

                // comment management done
                p = pp;
                pp = 0;

                if (*p == 0)
                    break;

                if (*p != '#')
                    f << indent;
            }

            if (*p == '\n') {
                f << *p++;

                if (*p && (*p != '#'))
                    f << indent;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else if (*p != '$')
                f << *p++;
            else if (!strncmp(p, "${comment}", 10))
                manage_comment(p, pp);
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${oneway}", 9)) {
                p += 9;

                if (isIdlOneway())
                    f << "oneway ";
            }
            else if (!strncmp(p, "${type}", 7)) {
                p += 7;
                UmlClass::write(f, returnType());
            }
            else if (!strncmp(p, "${name}", 7)) {
                p += 7;
                f << compute_name();
            }
            else if (!strncmp(p, "${(}", 4)) {
                p += 4;
                f << '(';
            }
            else if (!strncmp(p, "${)}", 4)) {
                p += 4;
                f << ')';
            }
            else if (sscanf(p, "${d%u}", &rank) == 1) {
                if (!generate_dir(params, rank, f))
                    param_error(parent()->name(), name(), rank, "declaration");

                p = strchr(p, '}') + 1;
            }
            else if (sscanf(p, "${t%u}", &rank) == 1) {
                if (!generate_type(params, rank, f))
                    param_error(parent()->name(), name(), rank, "declaration");

                p = strchr(p, '}') + 1;
            }
            else if (sscanf(p, "${p%u}", &rank) == 1) {
                if (!generate_var(params, rank, f))
                    param_error(parent()->name(), name(), rank, "declaration");

                p = strchr(p, '}') + 1;
            }
            else if (!strncmp(p, "${stereotype}", 13)) {
                p += 13;
                f << IdlSettings::relationAttributeStereotype(stereotype());
            }
            else if (!strncmp(p, "${raisesnl}", 11)) {
                if (exceptions.count() != 0) {
                    f << '\n' << indent << "  ";
                }

                p += 11;
            }
            else if (!strncmp(p, "${raises}", 9)) {
                p += 9;

                if (! exceptions.isEmpty()) {
                    const char * sep;
                    QList<UmlTypeSpec>::ConstIterator it;

                    for (it = exceptions.begin(), sep = " raises (";
                            it != exceptions.end();
                            ++it, sep = " ")
                        f << sep << IdlSettings::type((*it).toString());

                    f << ')';
                }
            }
            else if (!strncmp(p, "${association}", 14)) {
                p += 14;

                UmlClassMember * m;

                if (((m = getOf()) != 0) && (m->kind() == aRelation))
                    f << IdlSettings::type(((UmlRelation *) m)->association().toString());
                else if (((m = setOf()) != 0) && (m->kind() == aRelation))
                    f << IdlSettings::type(((UmlRelation *) m)->association().toString());
            }
            else
                // strange
                f << *p++;
        }

        f << '\n';
    }
}
Example #17
0
void UmlAttribute::generate_decl(aVisibility & current_visibility, QTextOStream & f_h,
				 const Q3CString & cl_stereotype, Q3CString indent,
				 BooL & first, bool last) {
  if (cl_stereotype == "typedef") {
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot have attribute</b></font><br>");
    incr_warning();
    return;
  }
  const char * p = cppDecl();
  const char * pp = 0;
  bool in_enum = (cl_stereotype == "enum");
  
  if (!in_enum)
    generate_visibility(current_visibility, f_h, first, indent);
  
  first = FALSE;
  
  while ((*p == ' ') || (*p == '\t'))
    indent += *p++;
  
  if (*p != '#')
    f_h << indent;
  
  for (;;) {
    if (*p == 0) {
      if (pp == 0)
	break;
      
      // comment management done
      p = pp;
      pp = 0;
      if (*p == 0)
	break;
      if (*p != '#')
	f_h << indent;
    }

    if (*p == '\n') {
      f_h << *p++;
      if (*p && (*p != '#'))
	f_h << indent;
    }
    else if (*p == '@')
      manage_alias(p, f_h);
    else if (*p != '$')
      f_h << *p++;
    else if (!strncmp(p, "${comment}", 10))
      manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
    else if (!strncmp(p, "${description}", 14))
      manage_description(p, pp);
    else if (!strncmp(p, "${name}", 7)) {
      p += 7;
      f_h << name();
    }
    else if (!strncmp(p, "${multiplicity}", 15)) {
      p += 15;
      
      const Q3CString & m = multiplicity();
      
      if (!m.isEmpty() && (*((const char *) m) == '['))
	f_h << m;
      else
	f_h << '[' << m << ']';
    }
    else if (!strncmp(p, "${stereotype}", 13)) {
      p += 13;
      f_h << CppSettings::relationAttributeStereotype(stereotype());
    }
    else if (!strncmp(p, "${value}", 8) || !strncmp(p, "${h_value}", 10)) {
      const char * pb = p;

      p += (p[2] == 'h') ? 10 : 8;
      if (in_enum) {
	if (!defaultValue().isEmpty()) {
	  if (need_equal(pb, defaultValue()))
	    f_h << " = ";
          f_h << defaultValue();
	}
	if (last) {
	  if (*p == ',')
	    p += 1;
	}
	else if (*p != ',')
	  f_h << ',';
      }
      else if ((p[-8] == 'h') && isClassMember() && !defaultValue().isEmpty()) {
	if (need_equal(pb, defaultValue()))
	  f_h << " = ";
	f_h << defaultValue();
      }
    }
    else if (in_enum)
      // strange
      f_h << *p++;
    else if (!strncmp(p, "${static}", 9)) {
      p += 9;
      if (isClassMember())
	f_h << "static ";
    }
    else if (!strncmp(p, "${const}", 8)) {
      p += 8;
      if (isReadOnly())
	f_h << "const ";
    }
    else if (!strncmp(p, "${volatile}", 11)) {
      p += 11;
      if (isVolatile())
	f_h << "volatile ";
    }
    else if (!strncmp(p, "${mutable}", 10)) {
      p += 10;
      if (isCppMutable())
	f_h << "mutable ";
    }
    else if (!strncmp(p, "${type}", 7)) {
      p += 7;
      UmlClass::write(f_h, type());
      //f_h << CppSettings::Type(Type().Type());
    }
    else
      // strange
      f_h << *p++;
  }
  
  f_h << '\n';
}
Example #18
0
void UmlRelation::generate(QTextOStream & f, const Q3CString & cl_stereotype,
                           Q3CString indent) {
    switch (relationKind()) {
    case aDependency:
    case aGeneralisation:
    case aRealization:
        break;
    default:
        if (!javaDecl().isEmpty()) {
            if (cl_stereotype == "enum_pattern") {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum_pattern</i> cannot have relation</b></font><br>");
                incr_warning();
                return;
            }

            const char * p = javaDecl();
            const char * pp = 0;
            Q3CString s;

            while ((*p == ' ') || (*p == '\t'))
                indent += *p++;

            f << indent;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;
                    if (*p == 0)
                        break;
                    f << indent;
                }

                if (*p == '\n') {
                    f << *p++;
                    if (*p)
                        f << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f);
                else if (*p != '$')
                    f << *p++;
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${visibility}", 13)) {
                    p += 13;
                    generate_visibility(f, cl_stereotype);
                }
                else if (!strncmp(p, "${static}", 9)) {
                    p += 9;
                    if (isClassMember())
                        f << "static ";
                }
                else if (!strncmp(p, "${final}", 8)) {
                    p += 8;
                    if (isReadOnly())
                        f << "final ";
                }
                else if (!strncmp(p, "${transient}", 12)) {
                    p += 12;
                    if (isJavaTransient())
                        f << "transient ";
                }
                else if (!strncmp(p, "${volatile}", 11)) {
                    p += 11;
                    if (isVolatile())
                        f << "volatile ";
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f);
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f << JavaSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;
                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f << side(side(TRUE) != this)->roleName();
                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;

                    Q3CString m = multiplicity();

                    if (*m != '[')
                        f << "[]";
                    else {
                        for (unsigned index = 0; index != m.length(); index += 1) {
                            switch (m.at(index)) {
                            case '[':
                                f << '[';
                                break;
                            case ']':
                                f << ']';
                            default:
                                break;
                            }
                        }
                    }
                }
                else if (!strncmp(p, "${value}", 8)) {
                    if (!defaultValue().isEmpty()) {
                        if (need_equal(p, defaultValue()))
                            f << " = ";
                        f << defaultValue();
                    }
                    p += 8;
                }
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    UmlClass::write(f, association());
                }
                else if (!strncmp(p, "${@}", 4)) {
                    p += 4;
                    if (pp != 0)
                        f << "${@}";
                    else if (! javaAnnotations().isEmpty()) {
                        pp =p;
                        p = javaAnnotations();
                    }
                }
                else
                    // strange
                    f << *p++;
            }

            f << '\n';
        }
    }
}
Example #19
0
void UmlClass::compute_dependency(Q3PtrList<CppRefType> & dependencies,
				  const Q3CString &, bool all_in_h) {
  Q3PtrVector<UmlItem> ch = children();
  const Q3CString stereotype = cpp_stereotype();
  bool a_typedef = (stereotype == "typedef");
  bool an_enum = (stereotype == "enum");
  const Q3ValueList<UmlFormalParameter> formals = this->formals();
  const Q3ValueList<UmlActualParameter> actuals = this->actuals();  
  
  if (!formals.isEmpty())
    // template class, force depend in h
    all_in_h = TRUE;
  
  for (unsigned index = 0; index != ch.size(); index += 1) {
    if (ch[index]->kind() != aNcRelation) {
      UmlClassItem * it = (UmlClassItem *) ch[index];
      
      if (! it->cppDecl().isEmpty())
	it->compute_dependency(dependencies, stereotype, all_in_h);
    }
  }
  
  if (an_enum && (!formals.isEmpty() || !actuals.isEmpty())) {
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b><i>template enum</i></b></font><br>");
    incr_warning();
  }
  else if (a_typedef && !formals.isEmpty()) {
    write_trace_header();
    UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b><i>template typedef</i></b></font><br>");
    incr_warning();
  }
  else {
    Q3ValueList<UmlFormalParameter>::ConstIterator itf;
    
    for (itf = formals.begin(); itf != formals.end(); ++itf)
      CppRefType::remove((*itf).name(), dependencies);
  
    Q3ValueList<UmlActualParameter>::ConstIterator ita;
    
    for (ita = actuals.begin(); ita != actuals.end(); ++ita)
      UmlClassMember::compute_dependency(dependencies, "${type}",
					 (*ita).value(), all_in_h);
    
    if (a_typedef) {
      Q3CString decl = cppDecl();
      int index;
      
      remove_comments(decl);
      if ((index = decl.find("${name}")) != -1)
	decl.remove((unsigned) index, 7);
      replace_alias(decl);

      UmlClassMember::compute_dependency(dependencies, decl,
					 baseType(), all_in_h);
    }
  }
  
  if ((associatedArtifact() == 0) ||
      (associatedArtifact()->associatedClasses().count() == 1))
    CppRefType::remove(this, dependencies);
  else
    CppRefType::force_ref(this, dependencies);
}
Example #20
0
// p point to ${body}
const char * UmlOperation::generate_body(QTextStream & f,
        WrapperStr indent,
        BooL & indent_needed,
        const char * p)
{
    if(isAbstract())
        return p + 7;

    const char * body = 0;
    WrapperStr modeler_body;
    WrapperStr body_indent;
    char s_id[9];

    if (preserve() && !isBodyGenerationForced()) {
        unsigned id = get_id();

        sprintf(s_id, "%08X", id);
        body = bodies.value((long) id);
    }

    if (body == 0) {
        modeler_body = pythonBody();	// to not free the string
        body = modeler_body;

        if (pythonContextualBodyIndent())
            body_indent = indent;
    }

    if (name() == "__init__") {
        const QList<UmlParameter> & params = this->params();

        if (params.count() != 0)
            ((UmlClass *) parent())->generate_instance_att_rel(f, indent, indent_needed,
                    params[0].name + ".");
        else {
            WrapperStr err = "&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b><i>" +
                            parent()->name() + ".__init__()</i> doesn't have parameter, instance variables not generated </b></font><br>";

            write_trace_header();
            UmlCom::trace(err);
            incr_warning();
        }
    }

    if (preserve() && !isBodyGenerationForced()) {
        if (indent_needed)
            f << indent;

        f << BodyPrefix << s_id << '\n' << body_indent;
    }
    else if (indent_needed)
        f << body_indent;

    if ((body != 0) && (*body != 0)) {
        // output body
        while (*body) {
            f << *body;

            if (*body++ == '\n') {
                if (*body == 0)
                    break;

                f << body_indent;
            }
        }

        if (body[-1] != '\n')
            f << '\n';
    }
    else
        f << "pass\n";

    if (preserve() && !isBodyGenerationForced())
        f << indent << BodyPostfix << s_id << '\n';

    indent_needed = TRUE;

    return p + 7;
}
Example #21
0
void UmlRelation::generate_inherit(const char *& sep, QTextStream & f_h,
                                   const Q3ValueList<UmlActualParameter> & actuals,
                                   const WrapperStr & cl_stereotype)
{
    switch (relationKind()) {
    default:
        break;

    case aGeneralisation:
    case aRealization:
        if ((cl_stereotype == "union") || (cl_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>")
                          + cl_stereotype + "</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }
        else if (cl_stereotype == "typedef") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot inherits</b></font><br>");
            incr_warning();
            return;
        }

        UmlClass * role_type = roleType();
        const WrapperStr & other_stereotype = role_type->stereotype();

        if ((other_stereotype == "union") ||
            (other_stereotype == "enum")) {
            write_trace_header();
            UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>cannot inherits an <i>")
                          + other_stereotype + "</i></b></font><br>");
            incr_warning();
            return;
        }

        f_h << sep;
        sep = ", ";

        if (cppVirtualInheritance())
            f_h << "virtual ";

        aVisibility visibility = (cppVisibility() == DefaultVisibility)
                                 ? this->visibility() : cppVisibility();

        switch (visibility) {
        case PublicVisibility:
        case PackageVisibility:
            f_h << "public ";
            break;

        case ProtectedVisibility:
            f_h << "protected ";
            break;

        default:
            f_h  << "private ";
        }

        const char * p = cppDecl();

        while (*p) {
            if (!strncmp(p, "${type}", 7)) {
                role_type->write(f_h, FALSE, 0, actuals);
                p += 7;
            }
            else if (*p == '@')
                manage_alias(p, f_h);
            else
                f_h << toLocale(p);
        }
    }
}
Example #22
0
void UmlRelation::generate_decl(aVisibility & current_visibility, QTextStream & f_h,
                                const WrapperStr & cl_stereotype, WrapperStr indent,
                                BooL & first, bool)
{
    switch (relationKind()) {
    case aDependency:
        if (stereotype() == "friend") {
            Q3ValueList<UmlFormalParameter> formals = roleType()->formals();

            if (! formals.isEmpty()) {
                const char * sep = "  template <";
                Q3ValueList<UmlFormalParameter>::ConstIterator it;

                for (it = formals.begin(); it != formals.end(); ++it) {
                    f_h << sep << (*it).type() << ' ' << (*it).name();
                    sep = ", ";
                }

                f_h << "> ";
            }
            else
                f_h << "  ";

            f_h << "friend " << roleType()->cpp_stereotype() << " ";
            roleType()->write(f_h, FALSE);
            f_h << ";\n";
            first = FALSE;
        }

        break;

    case aGeneralisation:
    case aRealization:
        break;

    default:
        if (!cppDecl().isEmpty()) {
            if (cl_stereotype == "enum") {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum</i> cannot have relation</b></font><br>");
                incr_warning();
                return;
            }

            if (cl_stereotype == "typedef") {
                write_trace_header();
                UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot have relation</b></font><br>");
                incr_warning();
                return;
            }

            generate_visibility(current_visibility, f_h, first, indent);
            first = FALSE;

            const char * p = cppDecl();
            const char * pp = 0;
            WrapperStr s;

            while ((*p == ' ') || (*p == '\t'))
                indent += toLocale(p);

            if (*p != '#')
                f_h << indent;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;

                    if (*p != '#')
                        f_h << indent;
                }

                if (*p == '\n') {
                    f_h << toLocale(p);

                    if (*p && (*p != '#'))
                        f_h << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f_h);
                else if (*p != '$')
                    f_h << toLocale(p);
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${static}", 9)) {
                    p += 9;

                    if (isClassMember())
                        f_h << "static ";
                }
                else if (!strncmp(p, "${const}", 8)) {
                    p += 8;

                    if (isReadOnly())
                        f_h << "const ";
                }
                else if (!strncmp(p, "${volatile}", 11)) {
                    p += 11;

                    if (isVolatile())
                        f_h << "volatile ";
                }
                else if (!strncmp(p, "${mutable}", 10)) {
                    p += 10;

                    if (isCppMutable())
                        f_h << "mutable ";
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f_h);
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f_h << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;

                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f_h << side(side(TRUE) != this)->roleName();

                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;

                    const WrapperStr & m = multiplicity();

                    if (!m.isEmpty() && (*((const char *) m) == '['))
                        f_h << m;
                    else
                        f_h << '[' << m << ']';
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f_h << CppSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${value}", 8))
                    p += 8;
                else if (!strncmp(p, "${h_value}", 10)) {
                    if (!defaultValue().isEmpty() && isClassMember()) {
                        if (need_equal(p, defaultValue()))
                            f_h << " = ";

                        f_h << defaultValue();
                    }

                    p += 10;
                }
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    UmlClass::write(f_h, association());
                }
                else
                    // strange
                    f_h << toLocale(p);
            }

            f_h << '\n';
        }
    }
}
Example #23
0
void UmlRelation::generate_decl(QTextStream & f,
                                const WrapperStr & cl_stereotype,
                                WrapperStr indent, bool)
{
    if ((relationKind() != aGeneralisation) &&
            (relationKind() != aRealization) &&
            (relationKind() != aDependency)) {
        if (cl_stereotype == "enum") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>an <i>enum</i> cannot have relation</b></font><br>");
            incr_warning();
            return;
        }

        if (cl_stereotype == "typedef") {
            write_trace_header();
            UmlCom::trace("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>a <i>typedef</i> cannot have relation</b></font><br>");
            incr_warning();
            return;
        }

        if (!idlDecl().isEmpty()) {
            const char * p = idlDecl();
            const char * pp = 0;
            WrapperStr s;

            while ((*p == ' ') || (*p == '\t'))
                indent += *p++;

            if (*p != '#')
                f << indent;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;

                    if (*p != '#')
                        f << indent;
                }

                if (*p == '\n') {
                    f << *p++;

                    if (*p && (*p != '#'))
                        f << indent;
                }
                else if (*p == '@')
                    manage_alias(p, f);
                else if (*p != '$')
                    f << *p++;
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp);
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${readonly}", 11)) {
                    p += 11;

                    if (isReadOnly())
                        f << "readonly ";
                }
                else if (!strncmp(p, "${attribut}", 11)) {
                    // old version
                    p += 11;

                    if (cl_stereotype == "interface")
                        f << "attribute ";
                }
                else if (!strncmp(p, "${attribute}", 12)) {
                    p += 12;

                    if (cl_stereotype == "interface")
                        f << "attribute ";
                }
                else if (!strncmp(p, "${visibility}", 13)) {
                    p += 13;

                    if (cl_stereotype == "valuetype") {
                        switch (visibility()) {
                        case PublicVisibility:
                        case PackageVisibility:
                            f << "public ";
                            break;

                        default:
                            f << "private ";
                        }
                    }
                }
                else if (!strncmp(p, "${case}", 7)) {
                    p += 7;

                    WrapperStr idl_case = idlCase();

                    if (idl_case.isEmpty()) {
                        write_trace_header();
                        UmlCom::trace(WrapperStr("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\"><b>unspecified <i>case</i> for <i>")
                                      + name() + "</b></font><br>");
                        incr_error();
                    }
                    else
                        f << idlCase();
                }
                else if (!strncmp(p, "${type}", 7)) {
                    p += 7;
                    roleType()->write(f);
                }
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f << roleName();
                }
                else if (!strncmp(p, "${inverse_name}", 15)) {
                    p += 15;

                    switch (relationKind()) {
                    case anAssociation:
                    case anAggregation:
                    case anAggregationByValue:
                        f << side(side(TRUE) != this)->roleName();

                    default:
                        break;
                    }
                }
                else if (!strncmp(p, "${stereotype}", 13)) {
                    p += 13;
                    f << IdlSettings::relationAttributeStereotype(stereotype());
                }
                else if (!strncmp(p, "${multiplicity}", 15)) {
                    p += 15;
                    f << multiplicity();
                }
                else if (!strncmp(p, "${association}", 14)) {
                    p += 14;
                    f << IdlSettings::type(association().toString());
                }
                else
                    // strange
                    f << *p++;
            }

            f << '\n';
        }
    }
}
Example #24
0
void UmlArtifact::generate() {
  if (! managed) {
    managed = TRUE;
    
    if (stereotype() == "text") {
      generate_text();
      return;
    }
    else if (stereotype() != "source")
      return;
    
    package_of_generated_artifact = package();
    
    const Q3CString def = idlSource();
    
    if (def.isEmpty())
      return;
    
    const Q3CString & name = this->name();    
    UmlPackage * pack = package();
    Q3CString path = pack->path(name);
    Q3CString mod_start;
    Q3CString mod_end;
    Q3CString mod = pack->idlModule();
    
    if (! mod.isEmpty()) {
      int index = 0;
      int index2;
      Q3CString closed = "\n}; // module ";
      
      while ((index2 = mod.find(':', index)) != -1) {
	Q3CString mo = mod.mid(index, index2 - index);
	
	mod_start += Q3CString("module ") + mo + " {\n\n";
	closed += mo;
	mod_end = closed + "\n" + mod_end;
	closed += "::";
	mod.replace(index2, 2, "_");
	index = index2 + 1;
      }
      
      mod_start += Q3CString("module ") + mod.mid(index) + " {\n\n";
      closed += mod.mid(index);
      mod_end = closed + "\n" + mod_end;
    }
    
    UmlCom::message(name);
    if (verbose())
      UmlCom::trace(Q3CString("<hr><font face=helvetica>Generate code for <i> ")
		    + name + "</i> in <i>" + path + "</i></font><br>");
    else
      set_trace_header(Q3CString("<font face=helvetica>Generate code for <i> ")
		       + name + "</i> in <i>" + path + "</i></font><br>");
    
#if 0
    // compute dependencies
    
    Q3PtrList<CppRefType> dependencies;
#endif
    const Q3PtrVector<UmlClass> & cls = associatedClasses();
    unsigned n = cls.count();
    unsigned index;
    
#if 0
    for (index = 0; index != n; index += 1)
      cls[index]->compute_dependencies(dependencies);
#endif
    
    // generate source file
    
    QByteArray file;
    QTextOStream f(&file);
    const char * p = def;
    const char * pp = 0;
    
    for (;;) {
      if (*p == 0) {
	if (pp == 0)
	  break;
	
	// comment management done
	p = pp;
	pp = 0;
	if (*p == 0)
	  break;
      }
      
      if (*p == '@')
	manage_alias(p, f);
      else if (*p != '$')
	f << *p++;
      else if (!strncmp(p, "${comment}", 10))
	manage_comment(p, pp);
      else if (!strncmp(p, "${description}", 14))
	manage_description(p, pp);
      else if (!strncmp(p, "${name}", 7)) {
	p += 7;
	f << name;
      }
      else if (!strncmp(p, "${Name}", 7)) {
	p += 7;
	f << capitalize(name);
      }
      else if (!strncmp(p, "${NAME}", 7)) {
	p += 7;
	f << name.upper();
      }
      else if (!strncmp(p, "${nAME}", 7)) {
	p += 7;
	f << name.lower();
      }
      else if (!strncmp(p, "${module}", 9)) {
	p += 9;
	f << mod;
      }
      else if (!strncmp(p, "${MODULE}", 9)) {
	p += 9;
	f << mod.upper();
      }
      else if (!strncmp(p, "${includes}", 11)) {
	p += 11;
	/*if (!incl_computed) {
	  incl_computed = TRUE;
	  CppRefType::compute(dependencies, hdef, srcdef, h_incl, decl, incl, this);
	}
	if (!incl.isEmpty()) {
	  f << incl;
	  if (*p != '\n')
	    f << '\n';
	}
	else*/ if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${definition}", 13)) {
	p += 13;
	for (index = 0; index != n; index += 1)
	  cls[index]->generate(f);
	if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${module_start}", 15)) {
	p += 15;
	if (!mod_start.isEmpty())
	  f << mod_start;
	if (*p == '\n')
	  p += 1;
      }
      else if (!strncmp(p, "${module_end}", 13)) {
	p += 13;
	if (!mod_end.isEmpty())
	  f << mod_end;
	if (*p == '\n')
	  p += 1;
      }
      else
	// strange
	f << *p++;
    }
    
    f << '\000';
    
    if (must_be_saved(path, file)) {
      write_trace_header();
	
      FILE * fp;
      
      if ((fp = fopen((const char *) path, "wb")) == 0) {
	write_trace_header();
	UmlCom::trace(Q3CString("<font color=\"red\"><b><i> ")
		      + name + " : </i> cannot open <i> " 
		      + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
		      + pack->name() + "</i> Idl directory specification</b></font><br>");
	incr_error();
      }
      else {
	fputs((const char *) file, fp);
	fclose(fp);
      }
    }
    else if (get_trace_header().isEmpty())
      UmlCom::trace(Q3CString("<font face=helvetica><i> ")
		    + path + "</i> not modified</font><br>");
  }
}
Example #25
0
void UmlArtifact::generate()
{
    if (! managed) {
        managed = TRUE;

        if (stereotype() == "text") {
            generate_text();
            return;
        }
        else if (stereotype() != "source")
            return;

        package_of_generated_artifact = package();
        current = this;

        const WrapperStr filedef = pythonSource();

        if (filedef.isEmpty())
            return;

        const WrapperStr & name = this->name();
        WrapperStr path = package_of_generated_artifact->file_path(name);

        UmlCom::message(name);

        if (verbose())
            UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ")
                          + name + "</i> in " + path + "</i></font><br>");
        else
            set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ")
                             + name + "</i> in " + path + "</i></font><br>");

        // get bodies if preserve
        const QVector<UmlClass*> & cls = associatedClasses();

        if (preserve())
            UmlOperation::read_bodies(path);

        // generate file

        WrapperStr indent;
        BooL indent_needed;
        unsigned n = cls.count();
        unsigned index;
        QByteArray file;
        // note : QTextStream(FILE *) does not work under windows
        QTextStream f(&file);
        const char * p = filedef;
        const char * pp = 0;

        for (;;) {
            if (*p == 0) {
                if (pp == 0)
                    break;

                // comment management done
                p = pp;
                pp = 0;

                if (*p == 0)
                    break;
            }

            if (*p == '@') {
                indent_needed = FALSE;
                manage_alias(p, f, indent, indent_needed);
            }
            else if (*p != '$')
                f << *p++;
            else if (!strncmp(p, "${comment}", 10))
                manage_comment(p, pp);
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${name}", 7)) {
                p += 7;
                f << name;
            }
            else if (!strncmp(p, "${Name}", 7)) {
                p += 7;
                f << capitalize(name);
            }
            else if (!strncmp(p, "${NAME}", 7)) {
                p += 7;
                f << name.upper();
            }
            else if (!strncmp(p, "${nAME}", 7)) {
                p += 7;
                f << name.lower();
            }
            else if (!strncmp(p, "${definition}", 13)) {
                indent_needed = TRUE;

                for (index = 0; index != n; index += 1)
                    cls[index]->generate(f, indent, indent_needed);

                p += 13;

                if (*p == '\n')
                    p += 1;
            }
            else if (!strncmp(p, "${import}", 9)) {
                imports = "";
                generate_imports(f, imports);

                for (index = 0; index != n; index += 1)
                    cls[index]->generate_imports(f, imports);

                p += 9;
            }
            else
                f << *p++;
        }

        f << '\000';

        if (must_be_saved(path, file)) {
            write_trace_header();

            FILE * fp;

            if ((fp = fopen((const char *) path, "wb")) == 0) {
                write_trace_header();
                UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                              + name + "</i> : cannot open <i> "
                              + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                              + package_of_generated_artifact->name()
                              + "</i> Python directory specification</b></font><br>");
                incr_error();
            }
            else {
                fputs((const char *) file, fp);
                fclose(fp);
            }
        }
        else if (get_trace_header().isEmpty())
            UmlCom::trace(WrapperStr("<font face=helvetica><i> ")
                          + path + "</i> not modified</font><br>");
    }
}