void UmlClassMember::remove_comments(WrapperStr & s) { int index1 = 0; if ((index1 = s.find("${comment}")) != -1) s.remove((unsigned) index1, 10); else if ((index1 = s.find("${description}")) != -1) s.remove((unsigned) index1, 14); while ((index1 = s.find('/', index1)) != -1) { int index2; switch (((const char *) s)[index1 + 1]) { case '/': if ((index2 = s.find('\n', index1 + 2)) != -1) s.remove(index1, index2 - index1 + 1); else s.truncate(index1); break; case '*': if ((index2 = s.find("*/", index1 + 2)) != -1) s.replace(index1, index2 - index1 + 1, " "); else s.truncate(index1); break; default: index1 += 1; } } }
void UmlItem::replace_alias(WrapperStr & s) { int index = 0; while ((index = s.find("@{", index)) != -1) { int index2 = s.find('}', index + 2); if (index2 == -1) return; UmlBaseItem * obj = this; WrapperStr key = s.mid(index + 2, index2 - index - 2); WrapperStr value; for (;;) { if (obj->propertyValue(key, value)) { s.replace(index, index2 - index + 1, value); index += value.length(); break; } else if ((obj = obj->parent()) == 0) { index = index2 + 1; break; } } } }
static void create_directory(WrapperStr s) { int index = 0; QChar sep = QDir::separator(); //[lgfreitas] QChar does not if (sep != '/') { while ((index = s.find(sep, index)) != -1) s.replace(index++, 1, "/"); } s = QDir::cleanPath(s) + "/"; index = s.find("/"); int index2; while ((index2 = s.find("/", index + 1)) != -1) { WrapperStr s2 = s.left(index2); QDir sd(s2); if (!sd.exists()) { if (!sd.mkdir(s2)) { UmlCom::trace(WrapperStr("<font color=\"red\"><b> cannot create directory <i>") + s2 + "</i></b></font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("UmlPackage::file_path"); } } index = index2; } }
void UmlClassMember::remove_arrays(WrapperStr & s) { int index1 = 0; while ((index1 = s.find('[', index1)) != -1) { int index2 = index1 = s.find(']', index1 + 1); if (index2 == -1) { s.truncate(index1); return; } else s.replace(index1, index2 - index1 + 1, " "); } }
void UmlClass::manage_generic(WrapperStr & form, UmlTypeSpec & typespec, WrapperStr str_actuals, const char * k) { if (typespec.type != 0) { int index; if (!typespec.explicit_type.isEmpty()) { if ((index = form.find(k)) != -1) form.replace(index, strlen(k), typespec.explicit_type); } else if (! str_actuals.isEmpty()) { if ((index = form.find(k)) != -1) form.insert(index + strlen(k), (const char *)str_actuals); } } }
WrapperStr UmlItem::legalName(WrapperStr s) { unsigned index; unsigned n = s.length(); for (index = 0; index != n; index += 1) { char c = s.operator QString().toLocal8Bit()[index]; if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_'))) s.replace(index, 1, "_"); } return s; }
WrapperStr UmlItem::legalName(WrapperStr s) { unsigned index; unsigned n = s.length(); for (index = 0; index != n; index += 1) { char c = s.at(index); if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_'))) s.replace(index, 1, "_"); } return s; }
bool UmlAttribute::new_one(Class * container, const WrapperStr & name, UmlTypeSpec typespec, aVisibility visibility, bool staticp, bool finalp, bool transientp, bool volatilep, const WrapperStr & array, const WrapperStr & value, WrapperStr comment, WrapperStr description, WrapperStr annotation #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { #ifdef TRACE QLOG_INFO() << "ATTRIBUTE '" << name << "'\n"; #endif if ( #ifdef REVERSE container->from_libp() && ( #endif visibility == PrivateVisibility #ifdef REVERSE ) #endif ) { Lex::finish_line(); Lex::clear_comments(); return TRUE; } UmlClass * cl = container->get_uml(); UmlAttribute * at; #ifdef ROUNDTRIP bool created; if (!roundtrip || ((at = search_attr(container, name)) == 0)) { #endif at = UmlBaseAttribute::create(cl, name); if (at == 0) { JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add attribute <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); return FALSE; } #ifdef REVERSE # ifndef ROUNDTRIP Statistic::one_attribute_more(); # else if (roundtrip) container->set_updated(); created = TRUE; } else created = FALSE; # endif #endif Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); WrapperStr decl = JavaSettings::attributeDecl(""); int index = decl.find("${type}"); if ((index == -1) || (decl.find("${name}") == -1)) { decl = " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type} ${name}${value};"; index = decl.find("${type}"); } #ifdef ROUNDTRIP if (roundtrip && !created) { if (decl.find("${description}") != -1) { if (nequal(at->description(), description)) { at->set_Description(description); container->set_updated(); } } else if (nequal(at->description(), Lex::simplify_comment(comment))) { at->set_Description(comment); // comment was set container->set_updated(); } if (at->isReadOnly() != finalp) { at->set_isReadOnly(finalp); container->set_updated(); } if (at->isJavaTransient() != transientp) { at->set_isJavaTransient(transientp); container->set_updated(); } if (at->isVolatile() != volatilep) { at->set_isVolatile(volatilep); container->set_updated(); } if (at->isClassMember() != staticp) { at->set_isClassMember(staticp); container->set_updated(); } if (!array.isEmpty()) decl.insert(index + 7, "${multiplicity}"); if (neq(at->multiplicity(), array)) { at->set_Multiplicity(array); container->set_updated(); } WrapperStr v = at->defaultValue(); if (!v.isEmpty() && (((const char *) v)[0] == '=')) v = v.mid(1); if (nequal(v, value)) { at->set_DefaultValue(value); container->set_updated(); } if (nequal(at->javaAnnotations(), annotation)) { at->set_JavaAnnotations(annotation); container->set_updated(); } WrapperStr stereotype; bool force_ste = FALSE; if (cl->stereotype() == "enum") { stereotype = "attribute"; force_ste = TRUE; } else if (typespec.type == 0) { WrapperStr t = typespec.explicit_type; int index2; if (!t.isEmpty() && (t.at(t.length() - 1) == ">") && ((index2 = t.find('<')) > 0)) { stereotype = t.left(index2); typespec.explicit_type = // may be a,b ... t.mid(index2 + 1, t.length() - 2 - index2); decl.replace(index, 7, "${stereotype}<${type}>"); force_ste = TRUE; } } if (at->visibility() != visibility) { at->set_Visibility(visibility); container->set_updated(); } if (neq(at->stereotype(), stereotype)) { WrapperStr jst; if (! at->stereotype().isEmpty()) jst = JavaSettings::relationAttributeStereotype(at->stereotype()); if ((force_ste) ? (jst != stereotype) : (jst == "attribute")) { at->set_Stereotype(stereotype); container->set_updated(); } } if (neq(at->javaDecl(), decl)) { at->set_JavaDecl(decl); container->set_updated(); } if (!at->type().equal(typespec)) { at->set_Type(typespec); container->set_updated(); } at->set_usefull(); expected_order.append(at); } else { #endif if (!comment.isEmpty()) at->set_Description((decl.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); if (finalp) at->set_isReadOnly(TRUE); if (transientp) at->set_isJavaTransient(TRUE); if (volatilep) at->set_isVolatile(TRUE); if (staticp) at->set_isClassMember(TRUE); if (!array.isEmpty()) { decl.insert(index + 7, "${multiplicity}"); at->set_Multiplicity(array); } if (! value.isEmpty()) at->set_DefaultValue(value); if (! annotation.isEmpty()) at->set_JavaAnnotations(annotation); if ((typespec.type == 0) && (cl->stereotype() != "enum")) { WrapperStr t = typespec.explicit_type; int index2 = 0; if (!t.isEmpty() && (t.at(t.length() - 1) == ">") && ((index2 = t.find('<')) > 0)) { at->set_Stereotype(t.left(index2)); typespec.explicit_type = // may be a,b ... t.mid(index2 + 1, t.length() - 2 - index2); decl.replace(index, 7, "${stereotype}<${type}>"); } } at->set_Visibility(visibility); if (cl->stereotype() == "enum") { at->set_JavaDecl(decl); at->set_Stereotype("attribute"); } else if (decl != JavaSettings::attributeDecl("")) at->set_JavaDecl(decl); at->set_Type(typespec); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(at); } #endif return TRUE; }
bool UmlAttribute::manage_enum_item(WrapperStr name, UmlClass * cl #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { WrapperStr comment = Lex::get_comments(); WrapperStr description = Lex::get_description(); UmlAttribute * item = 0; // initialize to avoid warning #ifdef ROUNDTRIP Class * container = 0; // initialize to avoid warning bool created = FALSE; // initialize to avoid warning #endif if (!Package::scanning()) { #ifdef ROUNDTRIP container = cl->get_class(); if (!roundtrip || ((item = search_attr(container, name)) == 0)) { #endif if ((item = UmlBaseAttribute::create(cl, name)) == 0) { JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add enum item <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); return FALSE; } item->set_Visibility(PublicVisibility); #ifdef ROUNDTRIP if (roundtrip) container->set_updated(); created = TRUE; } #endif } Lex::mark(); WrapperStr aux; WrapperStr s; if ((s = Lex::read_word()).isEmpty()) { if (! Package::scanning()) Lex::premature_eof(); return FALSE; } else if ((s == ";") || (s == "}")) { aux = Lex::region(); Lex::unread_word(s); } else if (s == ",") { aux = Lex::region(); Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); } else if ((s == "(") || (s == "{")) { char c = UmlOperation::skip_expr(1); // goes after opt init and body if (c == 0) { if (! Package::scanning()) Lex::premature_eof(); return FALSE; } // c is ',' or ';' if (c == ';') Lex::unread_word(";"); aux = Lex::region(); } else { if (! Package::scanning()) Lex::error_near(s); return FALSE; } if (!Package::scanning()) { // here aux = opt init and body + final character , ; or } WrapperStr decl = JavaSettings::enumItemDecl(); int index; if ((decl.find("${name}") == -1) || ((index = decl.find("${value}")) == -1)) { decl = " ${name}${value},${comment}"; index = decl.find("${value}"); } //aux.resize(aux.length()); // remove , ; or }, warning resize count \000 //warn_WrapperStr if (!aux.stripWhiteSpace().isEmpty()) decl.replace(index, 8, aux); #ifdef ROUNDTRIP if (roundtrip && !created) { if (decl.find("${description}") != -1) { if (nequal(item->description(), description)) { item->set_Description(description); container->set_updated(); } } else if (nequal(item->description(), Lex::simplify_comment(comment))) { item->set_Description(comment); // comment was changed container->set_updated(); } if (neq(item->javaDecl(), decl)) { item->set_JavaDecl(decl); container->set_updated(); } item->set_usefull(); expected_order.append(item); } else { #endif if (!comment.isEmpty()) item->set_Description((decl.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); item->set_JavaDecl(decl); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(item); } #endif } return TRUE; }
bool Class::manage_member(WrapperStr s) { WrapperStr comment = Lex::get_comments(); WrapperStr description = Lex::get_description(); int index; WrapperStr access = value_of(description, "@access", index); aVisibility visibility; if (access == "public") visibility = PublicVisibility; else if (access == "protected") visibility = ProtectedVisibility; else if (access == "private") visibility = PrivateVisibility; else visibility = PackageVisibility; if (visibility != PackageVisibility) { description.replace(index, access.length(), "${visibility}"); access = value_of(comment, "@access", index); comment.replace(index, access.length(), "${visibility}"); } bool m_staticp = FALSE; bool m_constp = FALSE; bool m_abstractp = FALSE; bool m_finalp = FALSE; #ifdef TRACE QLOG_INFO() << "Class::manage_member(" << s << ")\n"; #endif for (;;) { if (s == "public") visibility = PublicVisibility; else if (s == "protected") visibility = ProtectedVisibility; else if (s == "private") visibility = PrivateVisibility; else if (s == "static") m_staticp = TRUE; else if (s == "const") m_constp = TRUE; else if (s == "final") m_finalp = TRUE; else if (s == "abstract") m_abstractp = TRUE; else if (s != "var") break; s = Lex::read_word(); } if (s == "function") { // an operation return UmlOperation::new_one(this, visibility, m_finalp, m_abstractp, m_staticp, comment, description); } for (;;) { WrapperStr name = s; WrapperStr value; s = Lex::read_word(); #ifdef TRACE QLOG_INFO() << "define var '" << ((const char *) name) << "' followed by '" << ((const char *) s) << "'\n"; #endif if (s == "=") { // initialized variable, by pass value Lex::mark(); UmlOperation::skip_expr(0); value = Lex::region(); #ifdef TRACE QLOG_INFO() << "value form is '" << ((const char *) value) << "'\n"; #endif char c = ((const char *) value)[value.length() - 1]; if ((c == ';') || (c == ',')) { value.truncate(value.length() - 1); // remove ';' or ',' s = (c == ';') ? ";" : ","; } else s = Lex::read_word(); } if ((s != ";") && (s != ",")) { Lex::error_near(s); return FALSE; } if (!UmlAttribute::new_one(this, name, visibility, m_constp, m_staticp, value, comment, description)) return FALSE; if (s == ";") return TRUE; // var1, var2 ...; s = Lex::read_word(); if (s.isEmpty()) { if (! Package::scanning()) Lex::premature_eof(); return FALSE; } } }
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(" <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(" <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; } } }
// from a form 'generic<...C...> var' where C is a class bool UmlRelation::new_one(Class * container, const WrapperStr & name, UmlClass * type, WrapperStr type_def, WrapperStr genericname, aVisibility visibility, bool staticp, bool constp, bool transientp, bool volatilep, const WrapperStr & array, const WrapperStr & value, WrapperStr comment, WrapperStr description, WrapperStr annotation #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { #ifdef TRACE QLOG_INFO() << "RELATION '" << name << "' from '" << cl->Name() << "' to '" << type->Name() << "' array '" << array << "'\n"; #endif if ( #ifdef REVERSE container->from_libp() && #endif (visibility == PrivateVisibility)) { Lex::finish_line(); Lex::clear_comments(); return TRUE; } WrapperStr st = JavaSettings::umlType(genericname); if (st.isEmpty()) st = genericname; UmlClass * cl = container->get_uml(); UmlRelation * rel; #ifdef ROUNDTRIP bool created; if (!roundtrip || ((rel = search_rel(container, name, type, st)) == 0)) { #endif rel = UmlBaseRelation::create(aDirectionalAssociation, cl, type); if (rel == 0) { JavaCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add relation <i>") + name + "</i> in <i>" + cl->name() + "</i> to <i>" + type->name() + "</i></b></font><br>"); return FALSE; } #ifdef REVERSE # ifndef ROUNDTRIP Statistic::one_relation_more(); # else if (roundtrip) container->set_updated(); created = TRUE; } else created = FALSE; # endif #endif Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); WrapperStr decl = JavaSettings::relationDecl(array); type_def.replace(0, genericname.length(), "${stereotype}"); decl.replace(decl.find("${type}"), 7, type_def); #ifdef ROUNDTRIP if (roundtrip && !created) { if (rel->visibility() != visibility) { rel->set_Visibility(visibility); container->set_updated(); } if (decl.find("${description}") != -1) { if (nequal(rel->description(), description)) { rel->set_Description(description); container->set_updated(); } } else if (nequal(rel->description(), Lex::simplify_comment(comment))) { rel->set_Description(comment); // comment was set container->set_updated(); } if (rel->isReadOnly() != constp) { rel->set_isReadOnly(constp); container->set_updated(); } if (rel->isJavaTransient() != transientp) { rel->set_isJavaTransient(transientp); container->set_updated(); } if (rel->isVolatile() != volatilep) { rel->set_isVolatile(volatilep); container->set_updated(); } if (rel->isClassMember() != staticp) { rel->set_isClassMember(staticp); container->set_updated(); } if (neq(rel->multiplicity(), array)) { rel->set_Multiplicity(array); container->set_updated(); } if (neq(rel->defaultValue(), value)) { rel->set_DefaultValue(value); container->set_updated(); } if (nequal(rel->javaAnnotations(), annotation)) { rel->set_JavaAnnotations(annotation); container->set_updated(); } if (neq(rel->stereotype(), st) && (rel->stereotype().isEmpty() || (JavaSettings::relationAttributeStereotype(rel->stereotype()) != st))) { rel->set_Stereotype(st); container->set_updated(); } if (neq(rel->javaDecl(), decl)) { rel->set_JavaDecl(decl); container->set_updated(); } // role name is the right one rel->set_usefull(); expected_order.append(rel); } else { #endif rel->set_Visibility(visibility); if (!comment.isEmpty()) rel->set_Description((decl.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); if (constp) rel->set_isReadOnly(TRUE); if (transientp) rel->set_isJavaTransient(TRUE); if (volatilep) rel->set_isVolatile(TRUE); if (staticp) rel->set_isClassMember(TRUE); if (!array.isEmpty()) rel->set_Multiplicity(array); if (! value.isEmpty()) rel->set_DefaultValue(value); if (! annotation.isEmpty()) rel->set_JavaAnnotations(annotation); rel->set_Stereotype(st); rel->set_JavaDecl(decl); rel->set_RoleName(name); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(rel); } #endif return TRUE; }
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>"); } } }
bool UmlAttribute::new_one(Class * container, WrapperStr name, aVisibility visibility, bool constp, bool staticp, const WrapperStr & value, WrapperStr comment, WrapperStr description) { #ifdef TRACE QLOG_INFO() << "ATTRIBUTE '" << name << "'\n"; #endif #ifndef REVERSE if (visibility == PrivateVisibility) return TRUE; #endif if (((const char *) name)[0] == '$') name = name.mid(1); UmlClass * cl = container->get_uml(); UmlAttribute * at = UmlBaseAttribute::create(cl, name); if (at == 0) { PhpCatWindow::trace(WrapperStr("<font face=helvetica><b>cannot add attribute <i>") + name + "</i> in <i>" + cl->name() + "</i></b></font><br>"); return FALSE; } #ifdef REVERSE Statistic::one_attribute_more(); #endif if (!comment.isEmpty()) { WrapperStr s = (at->phpDecl().find("${description}") != -1) ? description : comment; UmlTypeSpec t; int index; if (!(t.explicit_type = value_of(s, "@var", index)).isEmpty()) { at->set_Type(t); s.replace(index, t.explicit_type.length(), "${type}"); } at->set_Description(s); } if (constp) at->set_isReadOnly(TRUE); if (staticp) at->set_isClassMember(TRUE); if (! value.isEmpty()) at->set_DefaultValue(value); at->set_Visibility(visibility); return TRUE; }
UmlClassView * UmlPackage::get_classview(const WrapperStr & nmsp) { UmlPackage * pack; if (nmsp != phpNamespace()) { if (namespace_fixedp) { if ((pack = findPhpNamespace(nmsp)) == 0) { WrapperStr s = nmsp; if (s.isEmpty()) s = name(); else { int index = 0; while ((index = s.find("::", index)) != -1) s.replace(index++, 2, " "); } if (((pack = UmlBasePackage::create(this, s)) == 0) && ((pack = UmlBasePackage::create(this, s += "_")) == 0) && ((pack = UmlBasePackage::create(this, s += "_")) == 0) && ((pack = UmlBasePackage::create(this, s += "_")) == 0) && ((pack = UmlBasePackage::create(this, s += "_")) == 0)) { #ifdef REVERSE UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create package <i>") + s + "</i> under package <i>" + name() + "</b></font><br>"); UmlCom::message(""); throw 0; #else QMessageBox::critical(0, "Fatal Error", WrapperStr("<font face=helvetica><b>cannot create package <i>") + s + "</i> under package <i>" + Name() + "</b></font><br>"); QApplication::exit(1); #endif } pack->set_PhpNamespace(nmsp); pack->set_PhpDir(phpDir()); pack->namespace_fixedp = TRUE; } } else { pack = this; pack->set_PhpNamespace(nmsp); pack->namespace_fixedp = TRUE; } } else pack = this; if (pack->classview == 0) { Q3PtrVector<UmlItem> ch = pack->children(); for (unsigned index = 0; index != ch.size(); index += 1) // return the first class view find if (ch[index]->kind() == aClassView) return pack->classview = (UmlClassView *) ch[index]; if ((pack->classview = UmlBaseClassView::create(pack, name())) == 0) { #ifdef REVERSE UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create class view <i>") + name() + "</i> under package <i>" + pack->name() + "</b></font><br>"); UmlCom::message(""); throw 0; #else QMessageBox::critical(0, "Fatal Error", WrapperStr("<font face=helvetica><b>cannot create class view <i>") + name() + "</i> under package <i>" + pack->name() + "</b></font><br>"); QApplication::exit(1); #endif } } return pack->classview; }
void UmlRelation::compute_dependency(Q3PtrList<CppRefType> & dependencies, const WrapperStr & cl_stereotype, bool all_in_h) { if (cl_stereotype == "enum") return; switch (relationKind()) { case aDependency: if (stereotype() == "friend") break; CppRefType::add(roleType(), dependencies, cppDecl() != "#include in source", roleType()->isCppExternal()); break; case aGeneralisation: case aRealization: CppRefType::add(roleType(), dependencies, TRUE); break; default: WrapperStr 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("${name}")) != -1) decl.remove((unsigned) index, 7); if ((index = decl.find("${inverse_name}")) != -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("${stereotype}")) != -1) decl.replace((unsigned) index, 13, CppSettings::relationAttributeStereotype(stereotype())); if ((index = decl.find("${association}")) != -1) { decl.replace((unsigned) index, 14, association().toString()); } replace_alias(decl); UmlTypeSpec type; type.type = roleType(); UmlClassMember::compute_dependency(dependencies, decl, type, all_in_h); } }
void UmlClass::write(QTextStream & f, bool with_formals, BooL * is_template, const QList<UmlActualParameter> & actuals) { if (! context.contains(this)) { if (parent()->kind() == aClass) { if (! context.contains((UmlClass *) parent())) { // parent cannot have formals, but may have actuals ((UmlClass *) parent())->write(f, FALSE, 0, actuals); f << "::"; } } else { UmlArtifact * cp = associatedArtifact(); WrapperStr nasp = ((UmlPackage *) ((cp != 0) ? (UmlItem *) cp : (UmlItem *) this)->package()) ->cppNamespace(); if (CppSettings::isForceNamespacePrefixGeneration() || (nasp != UmlArtifact::generation_package()->cppNamespace())) f << nasp << "::"; } } WrapperStr s; if (isCppExternal()) { s = cppDecl(); int index = s.find('\n'); s = (index == -1) ? s.stripWhiteSpace() : s.left(index).stripWhiteSpace(); if ((index = s.find("${name}")) != -1) s.replace(index, 7, name()); else if ((index = s.find("${Name}")) != -1) s.replace(index, 7, capitalize(name())); else if ((index = s.find("${NAME}")) != -1) s.replace(index, 7, name().upper().toLatin1().constData()); else if ((index = s.find("${nAME}")) != -1) s.replace(index, 7, name().lower().toLatin1().constData()); } else s = name(); // true_name if (! s.isEmpty()) { f << s; if (is_template != 0) *is_template = (s.at(s.length() - 1) == QString('>')); } else if (is_template != 0) *is_template = FALSE; if (with_formals) { QList<UmlFormalParameter> formals = this->formals(); if (! formals.isEmpty()) { const char * sep = "<"; QList<UmlFormalParameter>::ConstIterator it; for (it = formals.begin(); it != formals.end(); ++it) { f << sep << (*it).name(); sep = ", "; } f << '>'; if (is_template != 0) *is_template = TRUE; } } else if (!actuals.isEmpty()) { QList<UmlActualParameter>::ConstIterator ita; BooL need_space = FALSE; bool used = FALSE; for (ita = actuals.begin(); ita != actuals.end(); ++ita) { if ((*ita).superClass() == this) { used = TRUE; (*ita).generate(f, need_space); } } if (used) { if (need_space) f << " >"; else f << '>'; if (is_template != 0) *is_template = TRUE; } } }
WrapperStr UmlPackage::file_path(const WrapperStr & f) { if (!dir.read) { dir.file = pythonDir(); if (! RootDirRead) { RootDirRead = TRUE; RootDir = PythonSettings::rootDir(); if (!RootDir.isEmpty() && // empty -> error QDir::isRelativePath(RootDir)) { QFileInfo f(getProject()->supportFile()); QDir d(f.path()); RootDir = d.filePath(RootDir); } } QDir d_root(RootDir); if (dir.file.isEmpty()) dir.file = RootDir; else if (QDir::isRelativePath(dir.file)) dir.file = d_root.filePath(dir.file); if (dir.file.isEmpty()) { UmlCom::trace(WrapperStr("<font color=\"red\"><b><b> The generation directory " "must be specified for the package<i> ") + name() + "</i>, edit the <i> generation settings</i> (tab 'directory') " "or edit the package (tab 'Python')</b></font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("UmlPackage::file_path"); } dir.read = TRUE; } QDir d(dir.file); if (! d.exists()) { // create directory including the intermediates WrapperStr s = dir.file; int index = 0; QChar sep = QDir::separator(); if (sep != '/') { while ((index = s.find(sep, index)) != -1) s.replace(index++, 1, "/"); } s = QDir::cleanPath(s) + "/"; index = s.find("/"); int index2; while ((index2 = s.find("/", index + 1)) != -1) { WrapperStr s2 = s.left(index2); QDir sd(s2); if (!sd.exists()) { if (!sd.mkdir(s2)) { UmlCom::trace(WrapperStr("<font color=\"red\"><b> cannot create directory <i>") + s2 + "</i></b></font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("UmlPackage::file_path"); } } index = index2; } } return WrapperStr(d.filePath(f).toLatin1().constData()) + WrapperStr(".") + PythonSettings::sourceExtension(); }
bool UmlAttribute::new_one(Class * container, const WrapperStr & name, const WrapperStr & type, const WrapperStr & modifier, const WrapperStr & pretype, const WrapperStr & array, aVisibility visibility, bool staticp, bool constp, bool typenamep, bool mutablep, bool volatilep, const WrapperStr & bitfield, const WrapperStr & value, WrapperStr comment, WrapperStr description #ifdef ROUNDTRIP , bool roundtrip, QList<UmlItem *> & expected_order #endif ) { #ifdef DEBUG_DOUML QLOG_INFO() << "ATTRIBUTE '" << name << "' type '" << type << "' modifier '" << modifier << "' array '" << array << "'\n"; #endif if ( #ifdef REVERSE container->from_libp() && #endif (visibility == PrivateVisibility)) { Lex::finish_line(); Lex::clear_comments(); return TRUE; } UmlClass * cl = container->get_uml(); UmlAttribute * at; #ifdef ROUNDTRIP bool created; if (!roundtrip || ((at = search_attr(cl, name)) == 0)) { #endif at = UmlBaseAttribute::create(cl, name); if (at == 0) { UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot add attribute <i>") + name + "</i> in <i>" + WrapperStr(cl->name()) + "</i></b></font><br><hr>"); return FALSE; } #ifdef REVERSE # ifndef ROUNDTRIP Statistic::one_attribute_more(); # else if (roundtrip) container->set_updated(); created = TRUE; } else created = FALSE; # endif #endif Lex::finish_line(); comment = Lex::get_comments(comment); description = Lex::get_description(description); bool pfunc = (type.find('$') != -1); UmlTypeSpec typespec; WrapperStr typeform; WrapperStr stereotype; if (! pfunc) { typeform = (pretype.isEmpty()) ? WrapperStr("${type}") : pretype + " ${type}"; container->compute_type(type, typespec, typeform); } else { typespec.explicit_type = type.simplifyWhiteSpace(); int index = typespec.explicit_type.find("${name}"); if (index != -1) typespec.explicit_type.remove(index, 7); } WrapperStr decl = CppSettings::attributeDecl(""); int index = decl.find("${type}"); if ((index == -1) || (decl.find("${const}") == -1) || (decl.find("${name}") == -1) || (decl.find("${mutable}") == -1) || (decl.find("${volatile}") == -1) || (decl.find(';') == -1)) { decl = " ${comment}${static}${mutable}${volatile}${const}${type} ${name}${value};"; index = decl.find("${type}"); } if (pfunc) decl.replace(index, decl.find("${name}") + 7 - index, type); else { if (!modifier.isEmpty()) decl.insert(index + 7, (const char *)(WrapperStr(" ") + modifier)); if (typeform != "${type}") decl.replace(index, 7, typeform); else if (typespec.type == 0) { WrapperStr t = typespec.explicit_type; int index2 = 0; if (!t.isEmpty() && (t.at(t.length() - 1) == ">") && ((index2 = t.find('<')) > 0)) { stereotype = t.left(index2); typespec.explicit_type = // may be a,b ... t.mid(index2 + 1, t.length() - 2 - index2); decl.replace(index, 7, "${stereotype}<${type}>"); } } if (!array.isEmpty()) decl.insert(decl.find("${name}") + 7, "${multiplicity}"); if (!bitfield.isEmpty()) decl.insert(decl.find(';'), (const char *)(WrapperStr(" : ") + bitfield)); } if (typenamep) { int index = decl.find("${const}") + 8; // find cannot return -1 int index2 = decl.find("${mutable}") + 10; // find cannot return -1 int index3 = decl.find("${volatile}") + 11; // find cannot return -1 if (index2 > index) index = index2; if (index3 > index) index = index3; decl.insert(index, "typename "); } if (!value.isEmpty() && ((index = decl.find("${value}")) != -1)) decl.insert(index + 2, "h_"); #ifdef ROUNDTRIP if (roundtrip && !created) { if (decl.find("${description}") != -1) { if (nequal(at->description(), description)) { at->set_Description(description); container->set_updated(); } } else if (nequal(at->description(), Lex::simplify_comment(comment))) { at->set_Description(comment); // comment was set container->set_updated(); } if (at->isReadOnly() != constp) { at->set_isReadOnly(constp); container->set_updated(); } if (at->isCppMutable() != mutablep) { at->set_isCppMutable(mutablep); container->set_updated(); } if (at->isVolatile() != volatilep) { at->set_isVolatile(volatilep); container->set_updated(); } if (at->isClassMember() != staticp) { at->set_isClassMember(staticp); container->set_updated(); } if (neq(at->multiplicity(), array)) { at->set_Multiplicity(array); container->set_updated(); } if (!staticp) { WrapperStr v = at->defaultValue(); if (!v.isEmpty() && (((const char *) v)[0] == '=')) v = v.mid(1); if (nequal(v, value)) { at->set_DefaultValue(value); container->set_updated(); } } if (at->visibility() != visibility) { at->set_Visibility(visibility); container->set_updated(); } if (!stereotype.isEmpty()) { WrapperStr cppst; if (!at->stereotype().isEmpty()) cppst = CppSettings::relationAttributeStereotype(at->stereotype()); if (cppst != stereotype) { at->set_Stereotype(stereotype); container->set_updated(); } } if (!at->type().equal(typespec)) { at->set_Type(typespec); container->set_updated(); } if (neq(at->cppDecl(), decl)) { at->set_CppDecl(decl); container->set_updated(); } at->set_usefull(); expected_order.append(at); } else { #endif if (!comment.isEmpty()) at->set_Description((decl.find("${description}") != -1) ? description : Lex::simplify_comment(comment)); if (constp) at->set_isReadOnly(TRUE); if (mutablep) at->set_isCppMutable(TRUE); if (volatilep) at->set_isVolatile(TRUE); if (staticp) at->set_isClassMember(TRUE); if (!array.isEmpty()) at->set_Multiplicity(array); if (! value.isEmpty()) at->set_DefaultValue(value); at->set_Visibility(visibility); if (! stereotype.isEmpty()) at->set_Stereotype(stereotype); at->set_Type(typespec); at->set_CppDecl(decl); #ifdef ROUNDTRIP if (roundtrip) expected_order.append(at); } #endif return TRUE; }