コード例 #1
0
ファイル: UmlClass.cpp プロジェクト: SciBoy/douml
void UmlClass::java(Q3Dict<Q3CString> & prop) {
  if (!scanning) {
    Q3CString d = (stereotype() == "interface") 
      ? JavaSettings::interfaceDecl()
      : JavaSettings::classDecl();
    
    Q3CString * v;
    
    if ((v = prop.find("Java/Final")) != 0) {
      if (*v == "TRUE")
	set_isJavaFinal(TRUE);
      prop.remove("Java/Final");
    }
    
    if ((v = prop.find("Java/Strictfp")) != 0) {
      if (*v == "TRUE") {
	int index;
	
	if ((index = d.find("${public}")) != -1)
	  d.insert((unsigned) index + 9, "strictfp ");
	else if ((index = d.find("${visibility}")) != -1)
	  d.insert((unsigned) index + 13, "strictfp ");
      }
      prop.remove("Java/Strictfp");
    }
    
    set_JavaDecl(d);
  }
}
コード例 #2
0
ファイル: UmlClass.cpp プロジェクト: 02JanDal/douml
void UmlClass::addAssign(bool cte)
{
    TRACE_FUNCTION;
    UmlOperation * op = UmlOperation::create(this, "operator=");

    if (op == 0)
        UmlCom::trace("can't add assignment contructor");
    else {
        // add 'source' parameter

        UmlParameter param;

        param.name = "source";
        param.dir = (cte) ? InputDirection : InputOutputDirection;
        param.type.type = this;

        op->addParameter(0, param);

        // set return type, add the parameter profile

        UmlTypeSpec t;

        t.type = this;

        op->set_ReturnType(t);

        Q3CString p = (cte) ? "const ${t0} & ${p0}" : "${t0} & ${p0}";
        Q3CString s;
        int index;

        s = op->cppDecl();

        if (s.isEmpty())
            s = CppSettings::operationDecl();

        if ((index = s.find("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because Q3CString

        if ((index = s.find("${type}")) != -1)
            s.insert(index + 7, " &");

        op->set_CppDecl(s);

        s = op->cppDef();

        if (s.isEmpty())
            s = CppSettings::operationDef();

        if ((index = s.find("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because Q3CString

        if ((index = s.find("${type}")) != -1)
            s.insert(index + 7, " &");

        op->set_CppDef(s);
    }
}
コード例 #3
0
ファイル: UmlClass.cpp プロジェクト: 02JanDal/douml
void UmlClass::addCopy(bool cte)
{
    TRACE_FUNCTION;
    UmlOperation * op = UmlOperation::create(this, name());

    if (op == 0)
        UmlCom::trace("can't add copy contructor");
    else {
        // to see that it is a copy constructor
        op->set_Stereotype("copy");

        // add 'source' parameter

        UmlParameter param;

        param.name = "source";
        param.dir = (cte) ? InputDirection : InputOutputDirection;
        param.type.type = this;

        op->addParameter(0, param);

        // add the parameter profile, and
        // remove the useless "${type} " mainly to remove the space

        Q3CString p = (cte) ? "const ${t0} & ${p0}" : "${t0} & ${p0}";
        Q3CString s;
        int index;

        s = op->cppDecl();

        if (s.isEmpty())
            s = CppSettings::operationDecl();

        if ((index = s.find("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because Q3CString

        if ((index = s.find("${type} ")) != -1)
            s.remove(index, 8);

        op->set_CppDecl(s);

        s = op->cppDef();

        if (s.isEmpty())
            s = CppSettings::operationDef();

        if ((index = s.find("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because Q3CString

        if ((index = s.find("${type} ")) != -1)
            s.remove(index, 8);

        op->set_CppDef(s);
    }
}
コード例 #4
0
void UmlArtifact::add_includes(const char * i, bool h) {
  if (h) {
    Q3CString s = cppHeader();
    
    s.insert(s.find("${includes}"), i);
    set_CppHeader(s);
  }
  else {
    Q3CString s = cppSource();
    
    s.insert(s.find("${includes}"), i);
    set_CppSource(s);
  }
}
コード例 #5
0
ファイル: UmlItem.cpp プロジェクト: SciBoy/douml
void UmlItem::manage_docstring(const char *& p, const char *& pp, BooL & indent_needed,
			       Q3CString & indent, Q3CString & saved_indent)
{
  static Q3CString the_comment;
  
  p += 12;
  
  the_comment = description();
  
  if ((pp != 0) || // comment contains ${description} !
      the_comment.isEmpty())
    return;
    
  int index = 0;
  
  while ((index = the_comment.find("\"\"\"", index)) != -1) {
    the_comment.insert(index, "\\");
    index += 2;
  }
  
  if (!indent.isEmpty()) {
    int len = indent.length() + 1;
    
    index = 0;
    
    while ((index = the_comment.find('\n', index)) != -1) {
      the_comment.insert(index + 1, (const char*)indent);
      index += len;
    }
  }
  
  the_comment = "\"\"\"" + the_comment + "\"\"\"\n";
  
  if (indent_needed) {
    indent_needed = FALSE;
    the_comment = indent + the_comment;
  }

  pp = p;
  p = the_comment;
  saved_indent =  indent;
  indent = "";
}
コード例 #6
0
ファイル: tst_q3cstring.cpp プロジェクト: mpvader/qt
void tst_Q3CString::insert()
{
    Q3CString a;
    a = "Ys";
    QCOMPARE(a.insert(1,'e'),(Q3CString)"Yes");
    QCOMPARE(a.insert(3,'!'),(Q3CString)"Yes!");
    QCOMPARE(a.insert(5,'?'),(Q3CString)"Yes! ?");

    a="ABC";
    QCOMPARE(a.insert(5,"DEF"),(Q3CString)"ABC  DEF");
    a="ABC";
    QCOMPARE(a.insert(0,"ABC"),(Q3CString)"ABCABC");
    QCOMPARE(a,(Q3CString)"ABCABC");

    // ######### Q3CString::insert is not safe against self insertion...
//     Q3CString res = "ABCABCABCABC";
//     QCOMPARE(a.insert(0,a),res);
    a += "ABCABC";
    Q3CString res = "ABCABCABCABC";
    QCOMPARE(a, res);
    res = "<ABCABCABCABC";
    QCOMPARE(a.insert(0,'<'),res );
    res = "<>ABCABCABCABC";
    QCOMPARE(a.insert(1,'>'),res );
}
コード例 #7
0
ファイル: UmlClass.cpp プロジェクト: SciBoy/douml
void UmlClass::uml2java(bool rec) {
  if (isJavaExternal())
    set_JavaDecl(JavaSettings::externalClassDecl());
  else {
    Q3CString st = JavaSettings::classStereotype(stereotype());
    UmlItem * pack = parent()->parent();
    
    while (pack->kind() != aPackage)
      pack = pack->parent();
    
    if ((st == "stereotype") ||
	(st == "metaclass") ||
	(pack->stereotype() == "profile")) {
      set_CppDecl("");
      return;
    }
    
    if (st == "enum_pattern")
      set_JavaDecl(JavaSettings::enumPatternDecl());
    else if (st == "enum")
      set_JavaDecl(JavaSettings::enumDecl());
    else if (st == "interface")
      set_JavaDecl(JavaSettings::interfaceDecl());
    else if (st == "@interface") {
      Q3CString s = JavaSettings::interfaceDecl();
      int index = s.find("interface");
      
      if (index != -1)
	s.insert(index, '@');
      set_JavaDecl(s);
    }
    else if (st == "ignored") {
      set_JavaDecl("");
      return;
    }
    else
      set_JavaDecl(JavaSettings::classDecl());
    
    if (rec) {
      const Q3PtrVector<UmlItem> ch = children();
      unsigned n = ch.size();
      
      for (unsigned i = 0; i != n; i += 1)
	ch[i]->uml2java(rec);
    }
    
    if (parent()->kind() == aClassView)
      // not nested
      artifact()->set_JavaSource(JavaSettings::sourceContent());
  }
}
コード例 #8
0
ファイル: UmlPackage.cpp プロジェクト: SciBoy/douml
void UmlPackage::reverse_main(const Q3CString & type, Q3CString comment) {
  // do not lost main !
  Lex::mark();
  UmlOperation::skip_body();
  
  UmlArtifact * cp;
  
#ifdef ROUNDTRIP
  bool roundtrip = FALSE;
  
  if ((cp = UmlArtifact::get_main()) != 0) {
    roundtrip = TRUE;
    cp->set_usefull();
  }
  else
#endif
  if ((cp = UmlBaseArtifact::create(get_deploymentview(0), "main")) == 0) {
    UmlCom::trace("<font face=helvetica><b>cannot create <i>artifact main</i></b></font><br><hr>");
    return;
  }
  
  if (! comment.isEmpty()) {
    unsigned start = 0;
    
    do {
      comment.insert(start, "//");
      start = comment.find('\n', start + 2) + 1;
    } while (start != 0);
    comment.append("\n\n");
  }
  
  comment.append(type);
  comment.append(" main(");
  comment.append(Lex::region());
  comment.append("\n");
  
#ifdef ROUNDTRIP
  if (roundtrip) {
    if (cp->cppSource() != comment)
      cp->set_CppSource(comment);
    return;
  }
#endif
  
  cp->set_Stereotype("source");
  cp->set_CppSource(comment);
  cp->set_CppHeader(0);
}
コード例 #9
0
ファイル: UmlClass.cpp プロジェクト: 02JanDal/douml
void UmlClass::addContructor(bool expl)
{
    TRACE_FUNCTION;
    QLOG_INFO() << "1.1.1";
    UmlOperation * op = UmlOperation::create(this, name());
    QLOG_INFO() << "1.1.2";
    if (op == 0)
        UmlCom::trace("can't add contructor");
    else {
        QLOG_INFO() << "1.1.3";
        Q3CString s;
        int index;

        // remove the useless "${type} " mainly to remove the space

        s = op->cppDecl();
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.4";
        if (s.isEmpty())
            s = CppSettings::operationDecl();
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.5";
        if ((index = s.find("${type} ")) != -1)
            s.remove(index, 8);
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.6";
        if (expl && ((index = s.find("${name}")) != -1))
            s.insert(index, "explicit ");
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.7";
        op->set_CppDecl(s);
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.8";
        s = op->cppDef();
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.81";
        if (s.isEmpty())
            s = CppSettings::operationDef();
        QLOG_INFO() << "1.1.9";
        if ((index = s.find("${type} ")) != -1)
            s.remove(index, 8);
        QLOG_INFO() << "1.1.10";
        op->set_CppDef(s);
    }
}
コード例 #10
0
bool UmlOperation::new_one(Class * container, const Q3CString & name,
                           const Q3ValueList<FormalParameterList> & tmplts,
                           const Q3CString & oper_templ,
                           UmlTypeSpec & type, Q3CString str_actuals,
                           UmlClass * first_actual_class, Q3CString type_def,
                           aVisibility visibility,
                           bool finalp, bool abstractp, bool staticp,
                           bool nativep, bool strictfp, bool synchronizedp,
                           const Q3CString & array, Q3CString comment,
                           Q3CString description, Q3CString annotation
#ifdef ROUNDTRIP
                           , bool roundtrip, Q3PtrList<UmlItem> & expected_order
#endif
                          )
{
    // the "(" was read

#ifdef TRACE
    QLOG_INFO() <<"OPERATION '" << name << "'\n";
#endif

    UmlClass * cl = container->get_uml();
    UmlOperation * op;
#ifdef ROUNDTRIP
    bool may_roundtrip = roundtrip &&
                         (!container->from_libp() ||	(visibility != PrivateVisibility));
    UmlTypeSpec return_type;
    Q3ValueList<UmlParameter> params;
    Q3ValueList<UmlTypeSpec> exceptions;
    Q3CString body;

    if (may_roundtrip)
#else
    if (
# ifdef REVERSE
        container->from_libp() &&
# endif
        (visibility == PrivateVisibility))
#endif
        op = 0;
    else {
        op = UmlBaseOperation::create(cl, name);

        if (op == 0) {
            JavaCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add operation <i>")
                                 + name + "</i> in <i>" + cl->name()
                                 + "</i></b></font><br>");
            return FALSE;
        }

#ifndef ROUNDTRIP
# if defined(REVERSE)
        Statistic::one_operation_more();
# endif
#endif
    }

    Q3CString def;

#ifdef ROUNDTRIP
    if (may_roundtrip || (op != 0)) {
#else
    if (op != 0) {
        op->set_Visibility(visibility);
        if (staticp) op->set_isClassMember(TRUE);
        if (abstractp) op->set_isAbstract(TRUE);
        if (finalp) op->set_isJavaFinal(TRUE);
        if (synchronizedp) op->set_isJavaSynchronized(TRUE);
        if (! annotation.isEmpty()) op->set_JavaAnnotations(annotation);
#endif

        def = JavaSettings::operationDef();

        int index;

        if (((index = def.find("${(}")) == -1) ||
                ((index = def.find("${)}", index + 4)) == -1) ||
                ((index = def.find("${throws}", index + 4)) == -1) ||
                (def.find("${body}", index + 9) == -1) ||
                ((index = def.find("${type}")) == -1)) {
            // use a definition where ${body] is not indented
            def = "  ${comment}${@}${visibility}${final}${static}${abstract}${synchronized}${type} ${name}${(}${)}${throws}${staticnl}{\n${body}}\n";
            index = def.find("${type}");
        }

        if (!array.isEmpty())
            def.insert(index + 7, (const char *)array);

        if (nativep) {
            def.insert(index, "native ");
            index += 7;

            // no body
            int index2 = def.find("${throws}", index+7);

            if (index2 != -1) {
                def.resize(index2 + 12);
                def[index2 + 9] = ';';
                def[index2 + 10] = '\n';
            }
        }

        if (strictfp) {
            def.insert(index, "strictfp ");
            index += 9;
        }

        if (! oper_templ.isEmpty())
            def.insert(index, (const char *)(oper_templ + " "));

        if (name == cl->name()) {
            // constructor, remove useless ${}
            if ((index = def.find("${static}")) != -1)
                def.remove(index, 9);
            if ((index = def.find("${type}")) != -1)
                def.remove(index, (((const char *) def)[index + 7] == ' ') ? 8 : 7);
            if ((index = def.find("${final}")) != -1)
                def.remove(index, 8);
            if ((index = def.find("${abstract}")) != -1)
                def.remove(index, 11);
        }

        if (type.type != 0) {
            UmlClass::manage_generic(def, type, str_actuals, "${type}");
#ifdef ROUNDTRIP
            return_type = type;
#else
            op->set_ReturnType(type);
#endif
        }
        else if (first_actual_class != 0) {
#ifndef ROUNDTRIP
            UmlTypeSpec return_type;
#endif

            return_type.type = first_actual_class;
            def.replace(def.find("${type}"), 7, type_def);
#ifndef ROUNDTRIP
            op->set_ReturnType(return_type);
#endif
        }
        else if (!type.explicit_type.isEmpty()) {
            // not a contructor
#ifdef ROUNDTRIP
            return_type = type;
#else
            op->set_ReturnType(type);
#endif
        }
    }

    // parameters

    unsigned rank = 0;
    UmlParameter param;

#ifdef ROUNDTRIP
    if (may_roundtrip)
        while (read_param(container, rank++, tmplts, param, def, FALSE))
            params.append(param);
    else
#endif
        while (read_param(container, rank, tmplts, param, def, op == 0)) {
            if ((op != 0) && ! op->addParameter(rank, param)) {
                JavaCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add param <i>")
                                     + name + "</i> in <i>" + cl->name()
                                     + "</i></b></font><br>");
# ifdef TRACE
                QLOG_INFO() <<"ERROR cannot add param '" << param.name << "' type '" << param.type.Type() << '\n';
# endif
                return FALSE;
            }
            rank += 1;
        }

    Q3CString s = Lex::read_word();

    if (!s.isEmpty() && (*((const char *) s) == '[')) {
#ifdef ROUNDTRIP
        if (may_roundtrip)
#else
        if (op != 0)
#endif
            // do not place it at the same place
            def.insert(def.find("${type}") + 7, (const char *)s);
        s = Lex::read_word();
    }

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

    if (s == "throws") {

        // throws

        rank = 0;

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

#ifdef ROUNDTRIP
            if (may_roundtrip) {
                UmlTypeSpec typespec;

                container->compute_type(s, typespec, tmplts);
                exceptions.append(typespec);
            }
            else
#endif
                if (op != 0) {
                    UmlTypeSpec typespec;

                    container->compute_type(s, typespec, tmplts);
                    if (! op->addException(rank++, typespec)) {
# ifdef TRACE
                        QLOG_INFO() <<"cannot add exception " << s << '\n';
# endif
                        return FALSE;
                    }
                }

            if (((s = Lex::read_word()) == "{") || (s == ";"))
                break;

            if (s != ",") {
                Lex::error_near(s, " ',' expected");
                return FALSE;
            }
        }
    }

    // definition

    if (abstractp || nativep ||
            (cl->stereotype() == "interface") ||
            (cl->stereotype() == "@interface")) {
        if ((s == "default") && (cl->stereotype() == "@interface")) {
            int index = def.find("${)}");

            Lex::mark();
            s = Lex::read_word();
            if (s == "{") {
                int level = 1;
                char c;

                for (;;) {
                    if ((c = Lex::read_word_bis()) == 0)
                        return FALSE;
                    else if (c == '{')
                        level += 1;
                    else if ((c == '}') && (--level == 0))
                        break;
                }
                s = Lex::region();
            }

            def.insert(index + 4, (const char *)(" default" + s));
            s = Lex::read_word();
        }
        if (s != ";") {
            Lex::error_near(s, " ';' expected");
            return FALSE;
        }
#ifdef REVERSE
# ifndef ROUNDTRIP
        if ((op != 0) && !container->from_libp())
            op->set_JavaBody(0);
# endif
#endif
    }
    else if (s != "{") {
        Lex::error_near(s, " '{' expected");
        return FALSE;
    }
    else {
        Lex::mark();

        // goto the end of the body

#ifndef ROUNDTRIP
        Q3CString body;
#endif
        int level = 1;	// '{' already read
        char c;

        for (;;) {
            if ((c = Lex::read_word_bis()) == 0)
                return FALSE;
            else if (c == '{')
                level += 1;
            else if ((c == '}') && (--level == 0))
                break;
        }

#ifdef REVERSE
        if (
# ifdef ROUNDTRIP
            may_roundtrip || (op != 0)
# else
            (op != 0) && !container->from_libp()
# endif
        ) {
            body = Lex::region();
            body.truncate(body.length() - 1);	// remove }

            // remove fist \n
            if (*((const char *) body) == '\n')
                body.remove(0, 1);

            // remove last spaces and tabs
            int ln = body.length();

            while (ln && ((body[ln - 1] == ' ') || (body[ln - 1] == '\t')))
                ln -= 1;
            body.truncate(ln);
            if (!body.isEmpty() && (body[ln - 1] != '\n'))
                body += "\n";

# ifndef ROUNDTRIP
            op->set_JavaBody(body);
            op->set_JavaContextualBodyIndent(FALSE);
# endif
        }
#endif
    }

#ifdef ROUNDTRIP
    if (may_roundtrip) {
        if (((op = already_exist_from_id(container, body)) != 0) ||
                ((op = already_exist(container, name, params)) != 0)) {
            // update already existing operation
            op->set_usefull();

            {
                // remove \r in case of preserve body
                Q3CString current_body = op->javaBody();
                int index = 0;

                while ((index = current_body.find('\r', index)) != -1)
                    current_body.remove(index, 1);

                if (nequal(current_body, body)) {
                    container->set_updated();
                    op->set_JavaBody(body);
                    op->set_JavaContextualBodyIndent(FALSE);
                }
            }
            if (op->visibility() != visibility) {
                container->set_updated();
                op->set_Visibility(visibility);
            }
            if (op->isClassMember() != staticp) {
                container->set_updated();
                op->set_isClassMember(staticp);
            }
            if (op->isAbstract() != abstractp) {
                container->set_updated();
                op->set_isAbstract(abstractp);
            }
            if (op->isJavaFinal() != finalp) {
                container->set_updated();
                op->set_isJavaFinal(finalp);
            }
            if (op->isJavaSynchronized() != synchronizedp) {
                container->set_updated();
                op->set_isJavaSynchronized(synchronizedp);
            }
            if (nequal(op->javaAnnotations(), annotation)) {
                container->set_updated();
                op->set_JavaAnnotations(annotation);
            }

            if (!op->returnType().equal(return_type)) {
                container->set_updated();
                op->set_ReturnType(return_type);
            }

            Q3ValueList<UmlParameter>::Iterator itp1;
            const Q3ValueList<UmlParameter> old_params = op->params();
            Q3ValueList<UmlParameter>::ConstIterator itp2;

            for (rank = 0, itp1 = params.begin(), itp2 = old_params.begin();
                    (itp1 != params.end()) && (itp2 != old_params.end());
                    ++itp1, ++itp2, rank += 1) {
                UmlParameter & p1 = *itp1;
                const UmlParameter & p2 = *itp2;

                if ((p1.name != p2.name) ||
                        nequal(p1.default_value, p2.default_value) ||
                        !p1.type.equal(p2.type)) {
                    if (p1.dir != InputDirection)
                        p1.dir = p2.dir;
                    op->replaceParameter(rank, p1);
                    container->set_updated();
                }
                else if ((p1.dir == InputDirection) && (p2.dir != InputDirection)) {
                    op->replaceParameter(rank, p1);
                    container->set_updated();
                }
            }

            if (itp1 != params.end()) {
                // have missing params
                container->set_updated();
                do {
                    op->addParameter(rank, *itp1);
                    itp1++;
                    rank += 1;
                } while (itp1 != params.end());
            }
            else if (itp2 != old_params.end()) {
                // have extra params
                container->set_updated();
                do {
                    op->removeParameter(rank);
                    itp2++;
                } while (itp2 != old_params.end());
            }

            Q3ValueList<UmlTypeSpec>::ConstIterator ite1;
            const Q3ValueList<UmlTypeSpec> old_exceptions = op->exceptions();
            Q3ValueList<UmlTypeSpec>::ConstIterator ite2;

            for (rank = 0, ite1 = exceptions.begin(), ite2 = old_exceptions.begin();
                    (ite1 != exceptions.end()) && (ite2 != old_exceptions.end());
                    ++ite1, ++ite2, rank += 1) {
                const UmlTypeSpec & e1 = *ite1;

                if (!e1.equal(*ite2)) {
                    op->replaceException(rank, e1);
                    container->set_updated();
                }
            }

            if (ite1 != exceptions.end()) {
                // have missing exceptions
                container->set_updated();
                do {
                    op->addException(rank, *ite1);
                    ite1++;
                    rank += 1;
                } while (ite1 != exceptions.end());
            }
            else if (ite2 != old_exceptions.end()) {
                // have extra exceptions
                container->set_updated();
                do {
                    op->removeException(rank);
                    ite2++;
                } while (ite2 != old_exceptions.end());
            }

            if (neq(def, op->javaDecl())) {
                container->set_updated();
                op->set_JavaDecl(def);
            }

            Lex::clear_comments();	// params & body comments
            Lex::finish_line();

            if (def.find("${description}") != -1) {
                if (nequal(op->description(), description)) {
                    container->set_updated();
                    op->set_Description(description);
                }
            }
            else if (nequal(op->description(), Lex::simplify_comment(comment))) {
                op->set_Description(comment); // comment was set
                container->set_updated();
            }

            expected_order.append(op);

            return TRUE;
        }

        // operation doesn't yet exist
        container->set_updated();
        op = UmlBaseOperation::create(cl, name);

        if (op == 0) {
            JavaCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add operation <i>")
                                 + name + "</i> in <i>" + cl->name()
                                 + "</i></b></font><br>");
            throw 0;
        }

        expected_order.append(op);

        Q3ValueList<UmlParameter>::ConstIterator itp;

        for (rank = 0, itp = params.begin(); itp != params.end(); ++itp)
            op->addParameter(rank++, *itp);

        Q3ValueList<UmlTypeSpec>::ConstIterator ite;

        for (rank = 0, ite = exceptions.begin(); ite != exceptions.end(); ++ite)
            op->addException(rank++, *ite);
    }

    if (op != 0) {
        op->set_JavaContextualBodyIndent(FALSE);
        op->set_Visibility(visibility);
        if (staticp) op->set_isClassMember(TRUE);
        if (abstractp) op->set_isAbstract(TRUE);
        if (finalp) op->set_isJavaFinal(TRUE);
        if (synchronizedp) op->set_isJavaSynchronized(TRUE);
        if (! annotation.isEmpty()) op->set_JavaAnnotations(annotation);
        op->set_JavaBody(body);
        op->set_ReturnType(return_type);
        if (def != JavaSettings::operationDef())
            op->set_JavaDecl(def);
    }
#else
    if ((op != 0) && (def != JavaSettings::operationDef()))
        op->set_JavaDecl(def);
#endif

    Lex::clear_comments();	// params & body comments
    Lex::finish_line();
    if (!comment.isEmpty())
        if (op != 0)
            op->set_Description((def.find("${description}") != -1)
                                ? description : Lex::simplify_comment(comment));

    return TRUE;
}

bool UmlOperation::read_param(Class * container, unsigned rank,
                              const Q3ValueList<FormalParameterList> & tmplts,
                              UmlParameter & param, Q3CString & def, bool bypass)
{
#ifdef TRACE
    QLOG_INFO() <<"UmlOperation::manage_param " << rank << "\n";
#endif

    bool finalp = FALSE;
    bool in = FALSE;
    bool ellipsis = FALSE;
    Q3CString array;
    bool type_read = FALSE;
    Q3ValueList<UmlTypeSpec> actuals;
    Q3CString str_actuals;
    Q3CString annotation;

    param.name = param.default_value = 0;

    Q3CString s = Lex::read_word();

#ifdef TRACE
    QLOG_INFO() <<"commence par " << s << '\n';
#endif

    if (s == ")")
        return FALSE;

    for (;;) {
        if (s.isEmpty()) {
            Lex::premature_eof();
            return FALSE;
        }
        else if (s == "final")
            finalp = TRUE;
        else if ((s == "void") || (s == "byte") || (s == "char") ||
                 (s == "short") || (s == "int") || (s == "long") ||
                 (s == "float") || (s == "double")) {
            if (type_read) {
                Lex::error_near(s);
                return FALSE;
            }
            param.type.type = 0;
            param.type.explicit_type = s;
            type_read = TRUE;
            in = TRUE;
        }
        else if ((s == ")") || (s == ",")) {
            if (param.name.isEmpty() && !type_read) {
                Lex::error_near(s);
                return FALSE;
            }
            if (s == ")")
                Lex::unread_word(s);

            if (! bypass) {
                param.dir = (finalp || in)
                            ? InputDirection : InputOutputDirection;

                Q3CString s;

                if (rank != 0)
                    s = ", ";
                if (! annotation.isEmpty())
                    s += annotation + " ";
                if (finalp)
                    s += "final ";
                if ((param.type.type != 0) &&
                        !param.type.explicit_type.isEmpty())
                    s += param.type.explicit_type;
                else {
                    s += "${t";
                    s += Q3CString().setNum(rank);
                    s += "}";
                    if (param.type.type != 0)
                        s += str_actuals;
                }
                s += array;
                s += (ellipsis) ? " ... ${p": " ${p";
                s += Q3CString().setNum(rank);
                s += "}";
                def.insert(def.find("${)}"), 	// cannot be -1
                           (const char *)s);
            }
            return TRUE;
        }
        else if (Lex::identifierp(s)) {
            if (!type_read) {
                while (s.at(s.length() - 1) == '.') {
                    // type on several lines, managed in this case
                    Q3CString s2 = Lex::read_word();

                    if (Lex::identifierp(s2))
                        s += s2;
                    else {
                        Lex::error_near(s, " identifier expected");
                        return FALSE;
                    }
                }
#ifdef TRACE
                QLOG_INFO() <<"type = '" << s << "...'\n";
#endif
                if (! bypass) {
                    Q3CString dummy;

                    container->read_type(param.type, 0, tmplts, 0, str_actuals, s,
                                         0, dummy, dummy);

                    if (param.type.explicit_type == "String")
                        // at least for it !
                        in = TRUE;
                }
                else
                    Lex::bypass_type(s);

                type_read = TRUE;
            }
            else if (param.name.isEmpty()) {
                if (s == "...")
                    ellipsis = TRUE;
                else {
                    param.name = s;
#ifdef TRACE
                    QLOG_INFO() <<"name = '" << param.name << "'\n";
#endif
                }
            }
            else {
                Lex::error_near(s);
#ifdef TRACE
                QLOG_INFO() <<"ERROR '" << s << "' alors qu a deja le type et le nom '" << param.name << "'\n";
#endif
                return FALSE;
            }
        }
        else if (*((const char *) s) == '@')
            annotation = s;
        else if (*((const char *) s) == '[') {
            in = FALSE;
            array = s;
        }
        else {
            Lex::error_near(s);
#ifdef TRACE
            QLOG_INFO() <<"ERROR : '" << s << "'\n";
#endif
            return FALSE;
        }

        s = Lex::read_word();
    }
}
コード例 #11
0
ファイル: UmlTransition.cpp プロジェクト: bleakxanadu/douml
void UmlTransition::generate(Q3PtrList<UmlTransition> trs, UmlClass * machine, UmlClass * anystate, UmlState * state, Q3CString & body, Q3CString indent, bool completion)
{
    UmlTransition * tr;
    bool guard = FALSE;

    for (tr = trs.first(); tr != 0; tr = trs.next()) {
        body += indent;

        if (!tr->cppGuard().isEmpty()) {
            // manage guard
            body += ((tr == trs.getFirst()) ? "if (" : "else if (")
                    + tr->cppGuard() + ") {\n";
            guard = TRUE;
        }
        else
            // no gard : it is the last transition, may be the first
            body += ((tr == trs.getFirst()) ? "{\n" : "else {\n");

        // the target state
        UmlItem * tg = tr->target();
        bool self_external = (state == tg) && tr->isExternal();

        while (tg->kind() != aState)
            tg = tg->parent();

        // the parent common to the current and the target state
        UmlState * common = state;

        if (self_external) {
            // execute exit behavior
            if (!state->cppExitBehavior().isEmpty())
                body += indent + "  _doexit(stm);\n";
        }
        else {
            bool fromExit =
                // the exit behavior is made entering in the exit point
                (tr->parent()->kind() == anExitPointPseudoState);

            // compute common parent and manage exit behavior
            if (tr->target()->kind() != aTerminatePseudoState) {
                while (!((UmlState *) tg)->inside(common)) {
                    if (!fromExit && !common->cppExitBehavior().isEmpty())
                        body += indent + "  stm" + common->path() + "._doexit(stm);\n";

                    fromExit = FALSE;

                    switch (common->parent()->kind()) {
                    case aState:
                        common = (UmlState *) common->parent();
                        break;

                    case aRegion:
                        common = (UmlState *) common->parent()->parent();
                        break;

                    default:
                        UmlCom::trace("Error : transition from '" + state->name()
                                      + "' goes outside the state machine");
                        throw 0;
                    }
                }
            }
        }

        // manage transition activity
        if (!tr->cppActivity().isEmpty())
            body += "#ifdef VERBOSE_STATE_MACHINE\n" + indent +
                    "  puts(\"DEBUG : execute activity of transition " + tr->name() +
                    "\");\n#endif\n" + tr->cppActivity();

        // manage entry behavior
        if (self_external) {
            if (state->needCreate())
                body += indent + "  create(stm);\n";
        }
        else if (tr->target()->kind() != aTerminatePseudoState) {
            if (tg != common) {
                Q3CString enter;
                UmlState * tg_parent;

                // the enter behavior of the target state will be managed
                // generating a call to create
                for (tg_parent = (UmlState *) tg->parent();
                     tg_parent != common;
                     tg_parent = (UmlState *) tg_parent->parent())
                    if (!tg_parent->cppEntryBehavior().isEmpty())
                        enter.insert(0,
                                     (const char *)(indent + "  stm" + tg_parent->path() + "._doentry(stm);\n")); //[rageek] ambiguous

                if (!enter.isEmpty())
                    body += enter;
            }

            // set the current state if needed
            if (tg != state)
                body += indent + "  stm._set_currentState(stm"
                        + ((UmlState *) tg)->path() + ");\n#ifdef VERBOSE_STATE_MACHINE\n" +
                        indent + "  puts(\"DEBUG : current state is now " + ((UmlState *) tg)->prettyPath() +
                        "\");\n#endif\n";
        }

        // do the transition
        if (tr->target()->kind() == aState) {
            if ((tg != state) && ((UmlState *) tg)->needCreate())
                body += indent + "  stm"
                        + ((UmlState *) tg)->path() + ".create(stm);\n";
        }
        else
            tr->target()->generate(machine, anystate, ((UmlState *) tg), body, indent + "  ");

        if (completion)
            body += indent + "  return (bool) 1;\n";

        body += indent + "}\n";
    }

    if (completion && guard)
        body += indent + "return (bool) 0;\n";
}
コード例 #12
0
ファイル: UmlAttribute.cpp プロジェクト: SciBoy/douml
bool UmlAttribute::new_one(Class * container, const Q3CString & name,
			   const Q3CString & type, const Q3CString & modifier,
			   const Q3CString & pretype, const Q3CString & array,
			   aVisibility visibility, bool staticp, bool constp,
			   bool typenamep, bool mutablep, bool volatilep,
			   const Q3CString & bitfield, const Q3CString & value,
			   Q3CString comment, Q3CString description
#ifdef ROUNDTRIP
			   , bool roundtrip, Q3PtrList<UmlItem> & expected_order
#endif
			   )
{
#ifdef DEBUG_BOUML
  cout << "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(Q3CString("<font face=helvetica><b>cannot add attribute <i>")
		    + name + "</i> in <i>" + Q3CString(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;
  Q3CString typeform;
  Q3CString stereotype;
  
  if (! pfunc) {
    typeform = (pretype.isEmpty())
      ? Q3CString("${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);
  }
  
  Q3CString 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*)(Q3CString(" ") + modifier));
        
    if (typeform != "${type}")
      decl.replace(index, 7, typeform);
    else if (typespec.type == 0) {
      Q3CString 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}>");
      }
    }
    
    if (!array.isEmpty())
      decl.insert(decl.find("${name}") + 7, "${multiplicity}");
    
    if (!bitfield.isEmpty())
      decl.insert(decl.find(';'), (const char *)(Q3CString(" : ") + 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) {
      Q3CString 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()) {
      Q3CString 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;
}
コード例 #13
0
ファイル: UmlRelation.cpp プロジェクト: SciBoy/douml
bool UmlRelation::new_one(Class * container, const Q3CString & name,
			  UmlClass * dest, const Q3CString & modifier, 
			  const Q3CString & pretype, const Q3CString & array, 
			  const Q3CString & typeform, aVisibility visibility,
			  bool staticp, bool constp, bool mutablep, bool volatilep, 
			  const Q3CString & value, Q3CString comment,
			  Q3CString description
#ifdef ROUNDTRIP
			  , bool roundtrip, Q3PtrList<UmlItem> & expected_order
#endif
			  )
{
#ifdef DEBUG_BOUML
  cout << "RELATION '" << name << "' from '" << cl->name() << "' to '" << dest->name()
    << "' modifier '" << modifier << "' array '" << array
      << "' typeform '" << typeform << "'\n";
#endif
  
  if (
#ifdef REVERSE
      container->from_libp() &&
#endif
      (visibility == PrivateVisibility)) {
    Lex::finish_line();
    Lex::clear_comments();
    return TRUE;
  }
  
  UmlClass * cl = container->get_uml();
  UmlRelation * rel;
  
#ifdef ROUNDTRIP
  if (roundtrip &&
      ((rel = search_rel(container, name, dest, "")) != 0)) {
    rel->set_usefull();
    expected_order.append(rel);
  }
  else {
#endif  
    rel = UmlBaseRelation::create((modifier.isEmpty() &&
				   ((typeform == "${type}") ||
				    (typeform[typeform.find("${type}") + 7] != '*')))
				  ? aDirectionalAggregationByValue
				  : aDirectionalAssociation,
				  cl, dest);
  
    if (rel == 0) {
      UmlCom::trace(Q3CString("<font face=helvetica><b>cannot add relation <i>")
		    + name + "</i> in <i>" + cl->name() + "</i> to <i>"
		    + dest->name() + "</i></b></font><br><hr>");  
      return FALSE;
    }
    
#ifdef REVERSE
# ifndef ROUNDTRIP
    Statistic::one_relation_more();
# else
    if (roundtrip) {
      expected_order.append(rel);
      container->set_updated();
      roundtrip = FALSE;
    }
  }
# endif
#endif
  
  Lex::finish_line();
  
  comment = Lex::get_comments(comment);
  description = Lex::get_description(description);
  
#ifdef ROUNDTRIP
  if (roundtrip) {
    if (rel->visibility() != visibility) {
      rel->set_Visibility(visibility);
      container->set_updated();
    }
  
    if (rel->isReadOnly() != constp) {
      rel->set_isReadOnly(constp);
      container->set_updated();
    }
    
    if (rel->isClassMember() != staticp) {
      rel->set_isClassMember(staticp);
      container->set_updated();
    }
    
    if (rel->isCppMutable() != mutablep) {
      rel->set_isCppMutable(mutablep);
      container->set_updated();
    }
    
    if (rel->isVolatile() != volatilep) {
      rel->set_isVolatile(volatilep);
      container->set_updated();
    }
  }
  else {
#endif
    rel->set_Visibility(visibility);
    if (constp) rel->set_isReadOnly(TRUE);
    if (staticp) rel->set_isClassMember(TRUE);
    if (mutablep) rel->set_isCppMutable(TRUE);
    if (volatilep) rel->set_isVolatile(TRUE);
    
#ifdef ROUNDTRIP
  }
#endif
  
  Q3CString decl;
  
  if (typeform != "${type}") {
    // array & modified are empty, pretype is empty ?
    decl = CppSettings::relationDecl(TRUE, "*");
    
    int index = typeform.find("<");	// cannot be -1
    Q3CString st = typeform.left(index);
    Q3CString st_uml = CppSettings::umlType(st);

#ifdef ROUNDTRIP
    if (roundtrip) {
      if (st_uml.isEmpty()) 
	st_uml = st;
      
      if (neq(rel->stereotype(), st_uml)) {
	rel->set_Stereotype(st_uml);
	container->set_updated();
      }
    }
    else
#endif
      rel->set_Stereotype((st_uml.isEmpty()) ? st : st_uml);
    
    int index2;
    
    if ((index2 = decl.find("<${type}>")) == -1) {
      decl = "    ${comment}${static}${mutable}${volatile}${const}${stereotype}<${type}> ${name}${value};";
      index2 = decl.find("<${type}>");
    }
    decl.replace(index2, 9, typeform.mid(index));
  }
  else {
    if (!array.isEmpty()) {
#ifdef ROUNDTRIP
    if (roundtrip) {
      if (neq(rel->multiplicity(), array)) {
	rel->set_Multiplicity(array);
	container->set_updated();
      }
    }
    else
#endif
      rel->set_Multiplicity(array);
    }
    decl = CppSettings::relationDecl(modifier != "*", array);
    
    int index;
    
    if (!pretype.isEmpty() &&
	((index = decl.find("${type}")) != 0))
      decl.insert(index,(const char*)( pretype + " "));
    
    if ((modifier == "&") && ((index = decl.find("${type}")) != 0))
      decl.insert(index + 7, " &");
  }
  
  if (! value.isEmpty()) {
    int index = decl.find("${value}");
    
    if (index != -1)
      decl.insert(index + 2,  "h_");
    
#ifdef ROUNDTRIP
    if (roundtrip) {
      if (!staticp) {
	Q3CString v = rel->defaultValue();
	
	if (!v.isEmpty() && (((const char *) v)[0] == '='))
	  v = v.mid(1);
	
	if (nequal(v, value)) {
	  rel->set_DefaultValue(value);
	  container->set_updated();
	}
      }
    }
    else
#endif
      rel->set_DefaultValue(value);
  }
  
#ifdef ROUNDTRIP
  if (roundtrip) {
    if (neq(rel->cppDecl(), decl)) {
      rel->set_CppDecl(decl);
      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();
    }
    
    // role name is the right one
    return TRUE;
  }
#endif

  rel->set_CppDecl(decl);
  
  if (!comment.isEmpty())
    rel->set_Description((decl.find("${description") != -1)
			 ? description : Lex::simplify_comment(comment));
  
  return rel->set_RoleName(name);
}
コード例 #14
0
void UmlArtifact::add_import(const char * i) {
  Q3CString s = javaSource();
  
  s.insert(s.find("${definition}"), i);
  set_JavaSource(s);
}
コード例 #15
0
bool UmlOperation::new_one(Class * container, aVisibility visibility,
			   bool finalp, bool abstractp, bool staticp,
			   Q3CString comment, Q3CString description)
{
  // 'function' was read, it is followed by :
  // ['&'] name'(' {'array' | <classname>] ['&'] '$'<varname> ['=' <value>]}* ')' '{' ... '}'
  Q3CString s = Lex::read_word();
  bool refp;
  
  if (s == "&") {
    refp = TRUE;
    s = Lex::read_word();
  }
  else
    refp = FALSE;
  
  if (s.isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
    
  Q3CString name = s;
  
#ifdef TRACE
  QLOG_INFO() <<"OPERATION '" << name << "'\n";
#endif
  
  s = Lex::read_word();
  if (s != "(") {
    Lex::syntax_error("'(' expected rather than '" + s + "'");
    return FALSE;
  }
  
  UmlClass * cl = container->get_uml();
  UmlOperation * op;
  
#ifndef REVERSE
  if (visibility == PrivateVisibility)
    op = 0;
  else
#endif
  {
    op = UmlBaseOperation::create(cl, name);
    
    if (op == 0) {
      PhpCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add operation <i>")
			   + name + "</i> in <i>" + cl->name() 
			   + "</i></b></font><br>");  
      return FALSE;
    }
    
#ifdef REVERSE
    Statistic::one_operation_more();
#endif
  }
    
  Q3CString def;
    
  if (op != 0) {
    op->set_Visibility(visibility);
    if (staticp) op->set_isClassMember(TRUE);
    if (finalp) op->set_isPhpFinal(TRUE);
  
    def = PhpSettings::operationDef();
  
    int index;
    
    if (((index = def.find("${(}")) == -1) ||
	(def.find("${)}", index + 4) == -1) ||
	((index = def.find("${name}")) == -1) ||
	(def.find("${body}") == -1)) {
      // use a definition where ${body] is not indented
      def = "  ${comment}${final}${visibility}${abstract}${static}function ${name}${(}${)}\n{\n  ${body}}\n";
      index = def.find("${name}");
    }
    
    if (refp)
      def.insert(index, "&");
    
    if ((name == cl->name()) || (name == "__construct")) {
      // constructor, remove useless ${}
      if ((index = def.find("${static}")) != -1)
	def.remove(index, 9);
      if ((index = def.find("${final}")) != -1)
	def.remove(index, 8);
      if ((index = def.find("${abstract}")) != -1)
	def.remove(index, 11);
    }
    
    if (abstractp) {
      op->set_isAbstract(TRUE);
      
      def = def.left(def.find("${)}") + 4) + ";";
    }
  }
  
  // parameters
  
  unsigned rank = 0;
  UmlParameter param;
  
  while (read_param(container, rank, param, def, op == 0)) {
    if ((op != 0) && ! op->addParameter(rank++, param)) {
      PhpCatWindow::trace(Q3CString("<font face=helvetica><b>cannot add param <i>")
			   + name + "</i> in <i>" + cl->name() 
			   + "</i></b></font><br>");  
#ifdef TRACE
      QLOG_INFO() <<"ERROR cannot add param '" << param.name << '\n';
#endif
      return FALSE;
    }
  }
  
  s = Lex::read_word();
  
  if (s.isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
    
  // definition
  
  if (abstractp || (cl->stereotype() == "interface")) {
    if (s != ";") {
      Lex::error_near(s);
      return FALSE;
    }
#ifdef REVERSE
    if (op != 0)
      op->set_PhpBody(0);
#endif
  }
  else if (s != "{") {
    Lex::error_near(s);
    return FALSE;
  }
  else {
    Lex::mark();
    
    // goto the end of the body
    
    char c;
    int level = 1;	// '{' already read
    
    for (;;) {
      if ((c = Lex::read_word_bis()) == 0)
	return FALSE;
      else if (c == '{')
	level += 1;
      else if ((c == '}') && (--level == 0))
	break;
    }
    
#ifdef REVERSE
    if (op != 0) {
      Q3CString e = Lex::region();
      
      e.truncate(e.length() - 1);	// remove }

      // remove fist \n
      if (*((const char *) e) == '\n')
	e.remove(0, 1);
      
      // remove last spaces and tabs
      int ln = e.length();
      
      while (ln && ((e[ln - 1] == ' ') || (e[ln - 1] == '\t')))
	ln -= 1;
      e.truncate(ln);
      
      op->set_PhpBody(e);
      op->set_PhpContextualBodyIndent(FALSE);
    }
#endif
  }
  
  if ((op != 0) && (def != op->phpDecl()))
    op->set_PhpDecl(def);
  
  Lex::clear_comments();	// params & body comments
  Lex::finish_line();
  
  if ((op != 0) && !comment.isEmpty()) {
    s = (def.find("${description}") != -1) ? description : comment;
    
    UmlTypeSpec t;
    int index1;
    
    if (! (t.explicit_type = value_of(s, "@return", index1)).isEmpty()) {
      op->set_ReturnType(t);
      s.replace(index1, t.explicit_type.length(), "${type}");
    }
    
    Q3ValueList<UmlParameter> l = op->params();
    unsigned nparams = l.count();

    if (nparams != 0) {
      Q3CString varname;
      int index2;
      char xn[16];

      index1 = 0;
      rank = 0;
      
      while (!((t.explicit_type = value_of(s, "@param", index1, varname, index2))
	       .isEmpty())) {
	if (varname.isEmpty() || (varname[0] != '$')) {
	  if (rank < nparams) {
	    UmlParameter & p = l[rank];
	    
	    p.type = t;
	    op->replaceParameter(rank, p);
	  }
	}
	else {
	  varname = varname.mid(1);
	  
	  Q3ValueList<UmlParameter>::Iterator it;
	  
	  for (it = l.begin(), rank = 0; it != l.end(); ++it, rank += 1) {
	    if ((*it).name == varname) {
	      (*it).type = t;
	      op->replaceParameter(rank, *it);
	      sprintf(xn, "${p%d}", rank);
	      s.replace(index2, varname.length() + 1, xn);
	      break;
	    }
	  }
	}
	sprintf(xn, "${t%d}", rank++);
	s.replace(index1, t.explicit_type.length(), xn);
      }
    }
    op->set_Description(s);
  }
  
  return TRUE;
}
コード例 #16
0
bool UmlOperation::read_param(Class * container, unsigned rank,
			      UmlParameter & param, Q3CString & def, bool bypass)
{
#ifdef TRACE
  QLOG_INFO() <<"UmlOperation::manage_param " << rank << "\n";
#endif
  
  Q3CString s = Lex::read_word();
  
  if (s.isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
  else if (s == ")")
    return FALSE;
  
#ifdef TRACE
  QLOG_INFO() <<"commence par " << s << '\n';
#endif

  param.type.type = 0;
  param.type.explicit_type = 0;
  param.dir = InputOutputDirection;

  bool arrayp = FALSE;
  
  if (s == "array") {
    arrayp = TRUE;
    s = Lex::read_word();
    if (s.isEmpty()) {
      Lex::premature_eof();
      return FALSE;
    }
  }
  else if ((((const char *) s)[0] != '&') &&
	   (((const char *) s)[0] != '$')) {
    // a type
    container->compute_type(s, param.type, 0);
    
    s = Lex::read_word();
    if (s.isEmpty()) {
      Lex::premature_eof();
      return FALSE;
    }
  }
  
  bool refp;
  
  if (s == "&") {
    refp = TRUE;
    s = Lex::read_word();
    if (s.isEmpty()) {
      Lex::premature_eof();
      return FALSE;
    }
  }
  else
    refp = FALSE;
  
  if (((const char *) s)[0] != '$') {
    Lex::syntax_error("invalid parameter name : " + s);
    return FALSE;
  }
  
  if (! bypass) {
    Q3CString n_close = Q3CString().setNum(rank) + "}";
    
    param.name = s.mid(1);
	
    s = (rank == 0) ? "" : ", ";
    
    if (arrayp)
      s += "array ";
    else if ((param.type.type != 0) || !param.type.explicit_type.isEmpty()) {
      s += "${t" + n_close + " ";
    }
    
    if (refp)
      s += "& ";

    s += "${p" + n_close + "${v" + n_close;
    
    def.insert(def.find("${)}"), 	// cannot be -1
	       (const char *)s);
  }
  
  s = Lex::read_word();
  
  if (s == "=") {
    Lex::mark();
    s = skip_expr(0);
    param.default_value = Lex::region();
    param.default_value.truncate(param.default_value.length() - s.length());
    if (*((const char *) param.default_value) == ' ')
      param.default_value = param.default_value.mid(1);
  }    
  else if (s.isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
  else
    param.default_value = 0;
  
  if (s == ")")
    Lex::unread_word(s);
  
  return TRUE;
}