Esempio n. 1
0
Function* JavaLLVMCompiler::parseFunction(JavaMethod* meth, Class* customizeFor) {
  assert(!isAbstract(meth->access));
  LLVMMethodInfo* LMI = getMethodInfo(meth);
  Function* func = LMI->getMethod(customizeFor);
  
  // We are jitting. Take the lock.
  vmkit::VmkitModule::protectIR();
  if (func->getLinkage() == GlobalValue::ExternalWeakLinkage) {
    JavaJIT jit(this, meth, func, LMI->isCustomizable ? customizeFor : NULL);
    if (isNative(meth->access)) {
      jit.nativeCompile();
      vmkit::VmkitModule::runPasses(func, JavaNativeFunctionPasses);
      vmkit::VmkitModule::runPasses(func, J3FunctionPasses);
    } else {
      jit.javaCompile();
      vmkit::VmkitModule::runPasses(func, JavaFunctionPasses);
      vmkit::VmkitModule::runPasses(func, J3FunctionPasses);
    }
    func->setLinkage(GlobalValue::ExternalLinkage);
    if (!LMI->isCustomizable && jit.isCustomizable) {
      // It's the first time we parsed the method and we just found
      // out it can be customized.
      // TODO(geoffray): return a customized version to this caller.
      meth->isCustomizable = true;
      LMI->isCustomizable = true;
    }
  }
  vmkit::VmkitModule::unprotectIR();

  return func;
}
Esempio n. 2
0
void UmlClass::write_actor(FileOut & out)
{
    out.indent();
    out << "<UML:Actor name=\"" << name() << '"';
    out.id(this);
    out << " visibility=\"public\" isAbstract=\""
        << ((isAbstract()) ? "true" : "false")
        << "\" isActive=\"false\" >\n";
    out.indent(+1);

    if (stereotype() != "actor")
        write_stereotype(out);

    write_description_properties(out);
    out.indent(-1);
    out.indent();
    out << "</UML:Actor>\n";

    const QVector<UmlItem*> ch = children();
    unsigned n = ch.size();

    for (unsigned i = 0; i != n; i += 1)
        if (ch[i]->kind() == aRelation)
            ch[i]->write_if_needed(out);
}
Esempio n. 3
0
static int
repCandidate(ClassRegister * cReg, char *cn)
{
  ReadCtl         ctl = stdRead;
  CMPIConstClass *cl = getClass(cReg, cn, &ctl);
  if (isAbstract(cl))
    return 0;
  ProviderInfo   *info;

  _SFCB_ENTER(TRACE_PROVIDERS, "repCandidate");

  if (strcasecmp(cn, "cim_indicationfilter") == 0 ||
      strcasecmp(cn, "cim_indicationsubscription") == 0)
    _SFCB_RETURN(0);

  while (cn != NULL) {
    info = pReg->ft->getProvider(pReg, cn, INSTANCE_PROVIDER);
    if (info)
      _SFCB_RETURN(0);
    cn = (char *) cl->ft->getCharSuperClassName(cl);
    if (cn == NULL)
      break;
    cl = getClass(cReg, cn, &ctl);
  }
  _SFCB_RETURN(1);
}
Component* ComponentFactory::createComponent(const std::string& typeName) {
    auto typeInfo = getTypeInfo(typeName);
    if (typeInfo->isAbstract()) {
        throw std::runtime_error("Cannot create instance of abstract component type '" + typeName + "'");
    }

    return typeInfo->createComponent();
}
Esempio n. 5
0
Variant MethodStatement::evalBody(VariableEnvironment &env) const {
  if (isAbstract()) {
    raise_error("Cannot call abstract method %s()", m_fullName->data());
  }
  if (m_ref) {
    return strongBind(FunctionStatement::evalBody(env));
  } else {
    return FunctionStatement::evalBody(env);
  }
}
Esempio n. 6
0
void* Class::createInstance(Allocator* allocator)
{
	if (isAbstract())
	{
		LogAssert("Could not create instance of abstract class '%s'", name);
		return nullptr;
	}
	
	void* object = create_fn(allocator);
	return object;
}
Esempio n. 7
0
void UmlOperation::defaultDef()
{
    if (cppDecl().isEmpty())
        set_CppDecl(CppSettings::operationDecl());

    if (isAbstract())
        set_CppDef("");
    else if (cppDef().isEmpty())
        set_CppDef(CppSettings::operationDef());

    setUsed();
}
Esempio n. 8
0
/*!
    Returns a deep-copied clone of the QUmlAssociationClass.
*/
QModelingElement *QUmlAssociationClass::clone() const
{
    QUmlAssociationClass *c = new QUmlAssociationClass;
    c->asQModelingObject()->setObjectName(this->asQModelingObject()->objectName());
    c->asQModelingObject()->setProperty("role", this->asQModelingObject()->property("role"));
    foreach (QUmlComment *element, ownedComments())
        c->addOwnedComment(dynamic_cast<QUmlComment *>(element->clone()));
    c->setName(name());
    if (nameExpression())
        c->setNameExpression(dynamic_cast<QUmlStringExpression *>(nameExpression()->clone()));
    foreach (QUmlElementImport *element, elementImports())
        c->addElementImport(dynamic_cast<QUmlElementImport *>(element->clone()));
    foreach (QUmlConstraint *element, ownedRules())
        c->addOwnedRule(dynamic_cast<QUmlConstraint *>(element->clone()));
    foreach (QUmlPackageImport *element, packageImports())
        c->addPackageImport(dynamic_cast<QUmlPackageImport *>(element->clone()));
    c->setVisibility(visibility());
    c->setLeaf(isLeaf());
    foreach (QUmlTemplateBinding *element, templateBindings())
        c->addTemplateBinding(dynamic_cast<QUmlTemplateBinding *>(element->clone()));
    foreach (QUmlCollaborationUse *element, collaborationUses())
        c->addCollaborationUse(dynamic_cast<QUmlCollaborationUse *>(element->clone()));
    foreach (QUmlGeneralization *element, generalizations())
        c->addGeneralization(dynamic_cast<QUmlGeneralization *>(element->clone()));
    c->setFinalSpecialization(isFinalSpecialization());
    if (ownedTemplateSignature())
        c->setOwnedTemplateSignature(dynamic_cast<QUmlRedefinableTemplateSignature *>(ownedTemplateSignature()->clone()));
    foreach (QUmlUseCase *element, ownedUseCases())
        c->addOwnedUseCase(dynamic_cast<QUmlUseCase *>(element->clone()));
    foreach (QUmlSubstitution *element, substitutions())
        c->addSubstitution(dynamic_cast<QUmlSubstitution *>(element->clone()));
    foreach (QUmlConnector *element, ownedConnectors())
        c->addOwnedConnector(dynamic_cast<QUmlConnector *>(element->clone()));
    foreach (QUmlInterfaceRealization *element, interfaceRealizations())
        c->addInterfaceRealization(dynamic_cast<QUmlInterfaceRealization *>(element->clone()));
    foreach (QUmlBehavior *element, ownedBehaviors())
        c->addOwnedBehavior(dynamic_cast<QUmlBehavior *>(element->clone()));
    c->setAbstract(isAbstract());
    c->setActive(isActive());
    foreach (QUmlClassifier *element, nestedClassifiers())
        c->addNestedClassifier(dynamic_cast<QUmlClassifier *>(element->clone()));
    foreach (QUmlProperty *element, ownedAttributes())
        c->addOwnedAttribute(dynamic_cast<QUmlProperty *>(element->clone()));
    foreach (QUmlOperation *element, ownedOperations())
        c->addOwnedOperation(dynamic_cast<QUmlOperation *>(element->clone()));
    foreach (QUmlReception *element, ownedReceptions())
        c->addOwnedReception(dynamic_cast<QUmlReception *>(element->clone()));
    c->setDerived(isDerived());
    foreach (QUmlProperty *element, ownedEnds())
        c->addOwnedEnd(dynamic_cast<QUmlProperty *>(element->clone()));
    return c;
}
Esempio n. 9
0
void print_access(u2 flags) {
	if(isPublic(flags))
		printf("public ");
	if(isPrivate(flags))
		printf("private ");
	if(isProtected(flags))
		printf("protected ");
	if(isFinal(flags))
		printf("final ");
	if(isAbstract(flags))
		printf("abstract ");
	if(isStatic(flags))
		printf("static ");
}
FieldContainer *FieldContainerType::createAspectCopy(
    const FieldContainer *pRefAspect,
          UInt32          uiContainerId) const
{
    FieldContainer *fc = NULL;

    if(isAbstract() == false)
    {
        fc = _pPrototype->createAspectCopy(pRefAspect);       
    }

    if(fc != NULL)
        fc->setId(uiContainerId);

    return fc;
}
Esempio n. 11
0
void UmlOperation::setType(UmlClass * type, const char * s)
{
    UmlTypeSpec t;

    t.type = type;
    set_ReturnType(t);

    static const QByteArray sep = " \t\n\r";
    QByteArray d;
    int typeindex;
    int nameindex;

    d = cppDecl();

    if (((typeindex = d.indexOf("${type}")) != -1) &&
        ((nameindex = d.indexOf("${name}", typeindex + 7)) != -1)) {
        while (sep.indexOf(d[nameindex - 1]) != -1)
            nameindex -= 1;

        d.replace(typeindex, nameindex - typeindex, s);
        set_CppDecl(d);
    }

    if (! isAbstract()) {
        d = cppDef();

        if (((typeindex = d.indexOf("${type}")) != -1) &&
            ((nameindex = d.indexOf("${class}", typeindex + 7)) != -1)) {
            while (sep.indexOf(d[nameindex - 1]) != -1)
                nameindex -= 1;

            d.replace(typeindex, nameindex - typeindex, s);
            set_CppDef(d);
        }
    }
}
Esempio n. 12
0
/*
 * Generate the XML for an overload.
 */
static int xmlOverload(sipSpec *pt, classDef *scope, memberDef *md,
        overDef *od, classDef *xtnds, int stat, int sec, int indent, FILE *fp)
{
    int a, need_sec, no_res;

    xmlIndent(indent++, fp);
    fprintf(fp, "<Function name=\"");
    prScopedPythonName(fp, scope, md->pyname->text);
    fprintf(fp, "\"");

    if (isAbstract(od))
        fprintf(fp, " abstract=\"1\"");

    if (stat)
        fprintf(fp, " static=\"1\"");

    if (isSlot(od))
    {
        fprintf(fp, " slot=\"");
        xmlCppSignature(fp, od);
        fprintf(fp, "\"");
    }

    if (xtnds != NULL)
    {
        fprintf(fp, " extends=\"");
        prScopedPythonName(fp, xtnds->ecd, xtnds->pyname->text);
        fprintf(fp, "\"");
    }

    no_res = (od->pysig.result.atype == void_type && od->pysig.result.nrderefs == 0);

    /* Handle the trivial case. */
    if (no_res && od->pysig.nrArgs == 0)
    {
        fprintf(fp, "/>\n");
        return FALSE;
    }

    fprintf(fp, ">\n");

    if (!no_res)
        xmlArgument(pt, &od->pysig.result, "out", isResultTransferredBack(od),
                FALSE, indent, fp);

    need_sec = FALSE;

    for (a = 0; a < od->pysig.nrArgs; ++a)
    {
        argDef *ad = &od->pysig.args[a];

        /* Ignore the first argument of number slots. */
        if (isNumberSlot(md) && a == 0 && od->pysig.nrArgs == 2)
            continue;

        xmlArgument(pt, ad, dirAttribute(ad), FALSE, sec, indent, fp);

        if (ad->atype == rxcon_type || ad->atype == rxdis_type)
            need_sec = TRUE;
    }

    xmlIndent(--indent, fp);
    fprintf(fp, "</Function>\n");

    return need_sec;
}
Esempio n. 13
0
// p0 is the beginning of the operation's def
// p point to ${body}
// indent is the one of the operation
const char * UmlOperation::generate_body(QTextStream & f,
        WrapperStr indent,
        const char * p)
{
    if(isAbstract())
        return p + 7;

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

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

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

    if (body == 0) {
        no_indent = !javaContextualBodyIndent();
        modeler_body = javaBody();	// to not free the string
        body = modeler_body;
    }
    else
        // body from file, respect its indent
        no_indent = TRUE;

    // get keyword indent
    WrapperStr bindent = indent;

    while (*p != '$')
        bindent += *p++;

    if (preserve() && !isBodyGenerationForced())
        f << bindent << BodyPrefix << s_id << '\n';

    if ((body != 0) && (*body != 0)) {
        // output body
        if (bindent.isEmpty() || no_indent) {
            f << body;
            body += strlen(body);
        }
        else {
            f << bindent;

            while (*body) {
                f << *body;

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

                    f << bindent;
                }
            }
        }

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

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

    f << indent;	// for the }

    return p + 7;
}
Esempio n. 14
0
int FuncDeclaration::cvMember(unsigned char *p)
{
    int nwritten = 0;

    //printf("FuncDeclaration::cvMember() '%s'\n", toChars());

    if (!type)                  // if not compiled in,
        return 0;               // skip it

    char *id = toChars();

    if (!p)
    {
        nwritten = 2 + 2 + cgcv.sz_idx + cv_stringbytes(id);
        nwritten = cv_align(NULL, nwritten);
        return nwritten;
    }
    else
    {
        int count = 0;
        int mlen = 2;
        {
            if (introducing)
                mlen += 4;
            mlen += cgcv.sz_idx * 2;
            count++;
        }

        // Allocate and fill it in
        debtyp_t *d = debtyp_alloc(mlen);
        unsigned char *q = d->data;
        TOWORD(q,config.fulltypes == CV8 ? LF_METHODLIST_V2 : LF_METHODLIST);
        q += 2;
//      for (s = sf; s; s = s->Sfunc->Foversym)
        {
            unsigned attribute = PROTtoATTR(prot());

            /* 0*4 vanilla method
             * 1*4 virtual method
             * 2*4 static method
             * 3*4 friend method
             * 4*4 introducing virtual method
             * 5*4 pure virtual method
             * 6*4 pure introducing virtual method
             * 7*4 reserved
             */

            if (isStatic())
                attribute |= 2*4;
            else if (isVirtual())
            {
                if (introducing)
                {
                    if (isAbstract())
                        attribute |= 6*4;
                    else
                        attribute |= 4*4;
                }
                else
                {
                    if (isAbstract())
                        attribute |= 5*4;
                    else
                        attribute |= 1*4;
                }
            }
            else
                attribute |= 0*4;

            TOIDX(q,attribute);
            q += cgcv.sz_idx;
            TOIDX(q, cv4_memfunctypidx(this));
            q += cgcv.sz_idx;
            if (introducing)
            {   TOLONG(q, vtblIndex * Target::ptrsize);
                q += 4;
            }
        }
        assert(q - d->data == mlen);

        idx_t typidx = cv_debtyp(d);
        if (typidx)
        {
            switch (config.fulltypes)
            {
                case CV8:
                    TOWORD(p,LF_METHOD_V3);
                    goto Lmethod;
                case CV4:
                    TOWORD(p,LF_METHOD);
                Lmethod:
                    TOWORD(p + 2,count);
                    nwritten = 4;
                    TOIDX(p + nwritten, typidx);
                    nwritten += cgcv.sz_idx;
                    nwritten += cv_namestring(p + nwritten, id);
                    break;

                default:
                    assert(0);
            }
        }
        nwritten = cv_align(p + nwritten, nwritten);
#ifdef DEBUG
        assert(nwritten == cvMember(NULL));
#endif
    }
    return nwritten;
}
Esempio n. 15
0
int FuncDeclaration::cvMember(unsigned char *p)
{
    char *id;
    idx_t typidx;
    unsigned attribute;
    int nwritten = 0;
    debtyp_t *d;

    //printf("FuncDeclaration::cvMember() '%s'\n", toChars());

    if (!type)			// if not compiled in,
	return 0;		// skip it

    id = toChars();

    if (!p)
    {
	nwritten = 6 + cv_stringbytes(id);
    }
    else
    {
	int count;
	int mlen;
	unsigned char *q;

	count = 0;
	mlen = 2;
	{
	    if (introducing)
		mlen += 4;
	    mlen += cgcv.sz_idx * 2;
	    count++;
	}

	// Allocate and fill it in
	d = debtyp_alloc(mlen);
	q = d->data;
	TOWORD(q,LF_METHODLIST);
	q += 2;
//	for (s = sf; s; s = s->Sfunc->Foversym)
	{
	    attribute = PROTtoATTR(prot());

	    /* 0*4 vanilla method
	     * 1*4 virtual method
	     * 2*4 static method
	     * 3*4 friend method
	     * 4*4 introducing virtual method
	     * 5*4 pure virtual method
	     * 6*4 pure introducing virtual method
	     * 7*4 reserved
	     */

	    if (isStatic())
		attribute |= 2*4;
	    else if (isVirtual())
	    {
		if (introducing)
		{
		    if (isAbstract())
			attribute |= 6*4;
		    else
			attribute |= 4*4;
		}
		else
		{
		    if (isAbstract())
			attribute |= 5*4;
		    else
			attribute |= 1*4;
		}
	    }
	    else
		attribute |= 0*4;

	    TOIDX(q,attribute);
	    q += cgcv.sz_idx;
	    TOIDX(q, cv4_memfunctypidx(this));
	    q += cgcv.sz_idx;
	    if (introducing)
	    {   TOLONG(q, vtblIndex * PTRSIZE);
		q += 4;
	    }
	}
	assert(q - d->data == mlen);

	typidx = cv_debtyp(d);
	if (typidx)
	{
	    TOWORD(p,LF_METHOD);
	    TOWORD(p + 2,count);
	    nwritten = 4;
	    TOIDX(p + nwritten, typidx);
	    nwritten += cgcv.sz_idx;
	    nwritten += cv_namestring(p + nwritten, id);
	}
    }
    return nwritten;
}
Esempio n. 16
0
void VarDeclaration::semantic(Scope *sc)
{
#if 0
    printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars());
    printf(" type = %s\n", type ? type->toChars() : "null");
    printf(" stc = x%x\n", sc->stc);
    printf(" storage_class = x%x\n", storage_class);
    printf("linkage = %d\n", sc->linkage);
    //if (strcmp(toChars(), "mul") == 0) halt();
#endif

    storage_class |= sc->stc;
    if (storage_class & STCextern && init)
        error("extern symbols cannot have initializers");

    AggregateDeclaration *ad = isThis();
    if (ad)
        storage_class |= ad->storage_class & STC_TYPECTOR;

    /* If auto type inference, do the inference
     */
    int inferred = 0;
    if (!type)
    {   inuse++;
        type = init->inferType(sc);
        inuse--;
        inferred = 1;

        /* This is a kludge to support the existing syntax for RAII
         * declarations.
         */
        storage_class &= ~STCauto;
        originalType = type;
    }
    else
    {   if (!originalType)
            originalType = type;
        type = type->semantic(loc, sc);
    }
    //printf(" semantic type = %s\n", type ? type->toChars() : "null");

    type->checkDeprecated(loc, sc);
    linkage = sc->linkage;
    this->parent = sc->parent;
    //printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars());
    protection = sc->protection;
    //printf("sc->stc = %x\n", sc->stc);
    //printf("storage_class = x%x\n", storage_class);

#if DMDV2
    if (storage_class & STCgshared && global.params.safe && !sc->module->safe)
    {
        error("__gshared not allowed in safe mode; use shared");
    }
#endif

    Dsymbol *parent = toParent();
    FuncDeclaration *fd = parent->isFuncDeclaration();

    Type *tb = type->toBasetype();
    if (tb->ty == Tvoid && !(storage_class & STClazy))
    {   error("voids have no value");
        type = Type::terror;
        tb = type;
    }
    if (tb->ty == Tfunction)
    {   error("cannot be declared to be a function");
        type = Type::terror;
        tb = type;
    }
    if (tb->ty == Tstruct)
    {   TypeStruct *ts = (TypeStruct *)tb;

        if (!ts->sym->members)
        {
            error("no definition of struct %s", ts->toChars());
        }
    }
    if ((storage_class & STCauto) && !inferred)
       error("storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?");

    if (tb->ty == Ttuple)
    {   /* Instead, declare variables for each of the tuple elements
         * and add those.
         */
        TypeTuple *tt = (TypeTuple *)tb;
        size_t nelems = Parameter::dim(tt->arguments);
        Objects *exps = new Objects();
        exps->setDim(nelems);
        Expression *ie = init ? init->toExpression() : NULL;

        for (size_t i = 0; i < nelems; i++)
        {   Parameter *arg = Parameter::getNth(tt->arguments, i);

            OutBuffer buf;
            buf.printf("_%s_field_%zu", ident->toChars(), i);
            buf.writeByte(0);
            const char *name = (const char *)buf.extractData();
            Identifier *id = Lexer::idPool(name);

            Expression *einit = ie;
            if (ie && ie->op == TOKtuple)
            {   einit = (Expression *)((TupleExp *)ie)->exps->data[i];
            }
            Initializer *ti = init;
            if (einit)
            {   ti = new ExpInitializer(einit->loc, einit);
            }

            VarDeclaration *v = new VarDeclaration(loc, arg->type, id, ti);
            //printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
            v->semantic(sc);

#if !IN_LLVM
// removed for LDC since TupleDeclaration::toObj already creates the fields;
// adding them to the scope again leads to duplicates
            if (sc->scopesym)
            {   //printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
                if (sc->scopesym->members)
                    sc->scopesym->members->push(v);
            }
#endif

            Expression *e = new DsymbolExp(loc, v);
            exps->data[i] = e;
        }
        TupleDeclaration *v2 = new TupleDeclaration(loc, ident, exps);
        v2->isexp = 1;
        aliassym = v2;
        return;
    }

    if (storage_class & STCconst && !init && !fd)
        // Initialize by constructor only
        storage_class = (storage_class & ~STCconst) | STCctorinit;

    if (isConst())
    {
    }
    else if (isStatic())
    {
    }
    else if (isSynchronized())
    {
        error("variable %s cannot be synchronized", toChars());
    }
    else if (isOverride())
    {
        error("override cannot be applied to variable");
    }
    else if (isAbstract())
    {
        error("abstract cannot be applied to variable");
    }
    else if (storage_class & STCtemplateparameter)
    {
    }
    else if (storage_class & STCctfe)
    {
    }
    else
    {
        AggregateDeclaration *aad = sc->anonAgg;
        if (!aad)
            aad = parent->isAggregateDeclaration();
        if (aad)
        {
#if DMDV2
            assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared)));

            if (storage_class & (STCconst | STCimmutable) && init)
            {
                if (!type->toBasetype()->isTypeBasic())
                    storage_class |= STCstatic;
            }
            else
#endif
                aad->addField(sc, this);
        }

        InterfaceDeclaration *id = parent->isInterfaceDeclaration();
        if (id)
        {
            error("field not allowed in interface");
        }

        /* Templates cannot add fields to aggregates
         */
        TemplateInstance *ti = parent->isTemplateInstance();
        if (ti)
        {
            // Take care of nested templates
            while (1)
            {
                TemplateInstance *ti2 = ti->tempdecl->parent->isTemplateInstance();
                if (!ti2)
                    break;
                ti = ti2;
            }

            // If it's a member template
            AggregateDeclaration *ad = ti->tempdecl->isMember();
            if (ad && storage_class != STCundefined)
            {
                error("cannot use template to add field to aggregate '%s'", ad->toChars());
            }
        }
    }

#if DMDV2
    if ((storage_class & (STCref | STCparameter | STCforeach)) == STCref &&
        ident != Id::This)
    {
        error("only parameters or foreach declarations can be ref");
    }
#endif

    if (type->isscope() && !noscope)
    {
        if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd)
        {
            error("globals, statics, fields, ref and out parameters cannot be auto");
        }

        if (!(storage_class & STCscope))
        {
            if (!(storage_class & STCparameter) && ident != Id::withSym)
                error("reference to scope class must be scope");
        }
    }

    enum TOK op = TOKconstruct;
    if (!init && !sc->inunion && !isStatic() && !isConst() && fd &&
        !(storage_class & (STCfield | STCin | STCforeach)) &&
        type->size() != 0)
    {
        // Provide a default initializer
        //printf("Providing default initializer for '%s'\n", toChars());
        if (type->ty == Tstruct &&
            ((TypeStruct *)type)->sym->zeroInit == 1)
        {   /* If a struct is all zeros, as a special case
             * set it's initializer to the integer 0.
             * In AssignExp::toElem(), we check for this and issue
             * a memset() to initialize the struct.
             * Must do same check in interpreter.
             */
            Expression *e = new IntegerExp(loc, 0, Type::tint32);
            Expression *e1;
            e1 = new VarExp(loc, this);
            e = new AssignExp(loc, e1, e);
            e->op = TOKconstruct;
            e->type = e1->type;         // don't type check this, it would fail
            init = new ExpInitializer(loc, e);
            return;
        }
        else if (type->ty == Ttypedef)
        {   TypeTypedef *td = (TypeTypedef *)type;
            if (td->sym->init)
            {   init = td->sym->init;
                ExpInitializer *ie = init->isExpInitializer();
                if (ie)
                    // Make copy so we can modify it
                    init = new ExpInitializer(ie->loc, ie->exp);
            }
            else
                init = getExpInitializer();
        }
        else
        {
            init = getExpInitializer();
        }
        // Default initializer is always a blit
        op = TOKblit;
    }

    if (init)
    {
        sc = sc->push();
        sc->stc &= ~(STC_TYPECTOR | STCpure | STCnothrow | STCref);

        ArrayInitializer *ai = init->isArrayInitializer();
        if (ai && tb->ty == Taarray)
        {
            init = ai->toAssocArrayInitializer();
        }

        StructInitializer *si = init->isStructInitializer();
        ExpInitializer *ei = init->isExpInitializer();

        // See if initializer is a NewExp that can be allocated on the stack
        if (ei && isScope() && ei->exp->op == TOKnew)
        {   NewExp *ne = (NewExp *)ei->exp;
            if (!(ne->newargs && ne->newargs->dim))
            {   ne->onstack = 1;
                onstack = 1;
                if (type->isBaseOf(ne->newtype->semantic(loc, sc), NULL))
                    onstack = 2;
            }
        }

        // If inside function, there is no semantic3() call
        if (sc->func)
        {
            // If local variable, use AssignExp to handle all the various
            // possibilities.
            if (fd && !isStatic() && !isConst() && !init->isVoidInitializer())
            {
                //printf("fd = '%s', var = '%s'\n", fd->toChars(), toChars());
                if (!ei)
                {
                    Expression *e = init->toExpression();
                    if (!e)
                    {
                        init = init->semantic(sc, type);
                        e = init->toExpression();
                        if (!e)
                        {   error("is not a static and cannot have static initializer");
                            return;
                        }
                    }
                    ei = new ExpInitializer(init->loc, e);
                    init = ei;
                }

                Expression *e1 = new VarExp(loc, this);

                Type *t = type->toBasetype();
                if (t->ty == Tsarray && !(storage_class & (STCref | STCout)))
                {
                    ei->exp = ei->exp->semantic(sc);
                    if (!ei->exp->implicitConvTo(type))
                    {
                        int dim = ((TypeSArray *)t)->dim->toInteger();
                        // If multidimensional static array, treat as one large array
                        while (1)
                        {
                            t = t->nextOf()->toBasetype();
                            if (t->ty != Tsarray)
                                break;
                            dim *= ((TypeSArray *)t)->dim->toInteger();
                            e1->type = new TypeSArray(t->nextOf(), new IntegerExp(0, dim, Type::tindex));
                        }
                    }
                    e1 = new SliceExp(loc, e1, NULL, NULL);
                }
                else if (t->ty == Tstruct)
                {
                    ei->exp = ei->exp->semantic(sc);
                    ei->exp = resolveProperties(sc, ei->exp);
                    StructDeclaration *sd = ((TypeStruct *)t)->sym;
#if DMDV2
                    /* Look to see if initializer is a call to the constructor
                     */
                    if (sd->ctor &&             // there are constructors
                        ei->exp->type->ty == Tstruct && // rvalue is the same struct
                        ((TypeStruct *)ei->exp->type)->sym == sd &&
                        ei->exp->op == TOKstar)
                    {
                        /* Look for form of constructor call which is:
                         *    *__ctmp.ctor(arguments...)
                         */
                        PtrExp *pe = (PtrExp *)ei->exp;
                        if (pe->e1->op == TOKcall)
                        {   CallExp *ce = (CallExp *)pe->e1;
                            if (ce->e1->op == TOKdotvar)
                            {   DotVarExp *dve = (DotVarExp *)ce->e1;
                                if (dve->var->isCtorDeclaration())
                                {   /* It's a constructor call, currently constructing
                                     * a temporary __ctmp.
                                     */
                                    /* Before calling the constructor, initialize
                                     * variable with a bit copy of the default
                                     * initializer
                                     */
                                    Expression *e = new AssignExp(loc, new VarExp(loc, this), t->defaultInit(loc));
                                    e->op = TOKblit;
                                    e->type = t;
                                    ei->exp = new CommaExp(loc, e, ei->exp);

                                    /* Replace __ctmp being constructed with e1
                                     */
                                    dve->e1 = e1;
                                    return;
                                }
                            }
                        }
                    }
#endif
                    if (!ei->exp->implicitConvTo(type))
                    {
                        /* Look for opCall
                         * See bugzilla 2702 for more discussion
                         */
                        Type *ti = ei->exp->type->toBasetype();
                        // Don't cast away invariant or mutability in initializer
                        if (search_function(sd, Id::call) &&
                            /* Initializing with the same type is done differently
                             */
                            !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc)))
                        {   // Rewrite as e1.call(arguments)
                            Expression * eCall = new DotIdExp(loc, e1, Id::call);
                            ei->exp = new CallExp(loc, eCall, ei->exp);
                        }
                    }
                }
                ei->exp = new AssignExp(loc, e1, ei->exp);
                ei->exp->op = TOKconstruct;
                canassign++;
                ei->exp = ei->exp->semantic(sc);
                canassign--;
                ei->exp->optimize(WANTvalue);
            }
            else
            {
                init = init->semantic(sc, type);
                if (fd && isConst() && !isStatic())
                {   // Make it static
                    storage_class |= STCstatic;
                }
            }
        }
        else if (isConst() || isFinal() ||
                 parent->isAggregateDeclaration())
        {
            /* Because we may need the results of a const declaration in a
             * subsequent type, such as an array dimension, before semantic2()
             * gets ordinarily run, try to run semantic2() now.
             * Ignore failure.
             */

            if (!global.errors && !inferred)
            {
                unsigned errors = global.errors;
                global.gag++;
                //printf("+gag\n");
                Expression *e;
                Initializer *i2 = init;
                inuse++;
                if (ei)
                {
                    e = ei->exp->syntaxCopy();
                    e = e->semantic(sc);
                    e = e->implicitCastTo(sc, type);
                }
                else if (si || ai)
                {   i2 = init->syntaxCopy();
                    i2 = i2->semantic(sc, type);
                }
                inuse--;
                global.gag--;
                //printf("-gag\n");
                if (errors != global.errors)    // if errors happened
                {
                    if (global.gag == 0)
                        global.errors = errors; // act as if nothing happened
#if DMDV2
                    /* Save scope for later use, to try again
                     */
                    scope = new Scope(*sc);
                    scope->setNoFree();
#endif
                }
                else if (ei)
                {
                    if (isDataseg() || (storage_class & STCmanifest))
                        e = e->optimize(WANTvalue | WANTinterpret);
                    else
                        e = e->optimize(WANTvalue);
                    switch (e->op)
                    {
                        case TOKint64:
                        case TOKfloat64:
                        case TOKstring:
                        case TOKarrayliteral:
                        case TOKassocarrayliteral:
                        case TOKstructliteral:
                        case TOKnull:
                            ei->exp = e;            // no errors, keep result
                            break;

                        default:
#if DMDV2
                            /* Save scope for later use, to try again
                             */
                            scope = new Scope(*sc);
                            scope->setNoFree();
#endif
                            break;
                    }
                }
                else
                    init = i2;          // no errors, keep result
            }
        }
        sc = sc->pop();
    }
}
Esempio n. 17
0
bool UmlOperation::write_if_needed(FileOut & out) {
  QCString decl;

  switch (_lang) {
  case Uml:
    parent()->write(out);
    out.indent();
    out << "<UML:Operation name=\"";
    out.quote(name());
    break;
  case Cpp:
    decl = cppDecl();
    
    if (decl.isEmpty())
      return FALSE;
    remove_comments(decl);
    parent()->write(out);
    out.indent();
    out << "<UML:Operation name=\"";
    out.quote(true_name(cppDecl()));
    break;
  default: // Java
    decl = javaDecl();
    
    if (decl.isEmpty())
      return FALSE;
    remove_comments(decl);    
    parent()->write(out);
    out.indent();
    out << "<UML:Operation name=\"";
    out.quote(true_name(javaDecl()));
    break;
  }
  out << '"';
  out.id(this);
  
  switch (_lang) {
  case Uml:
    write_visibility(out);
    break;
  case Cpp:
    write_visibility(out, 
		     (cppVisibility() == DefaultVisibility)
		     ? visibility() : cppVisibility());
    break;
  default: // Java
    if (javaDecl().find("${visibility}") != -1)
      write_visibility(out, visibility());
    break;
  }
  write_scope(out);
  out << " isAbstract=\""
      << ((isAbstract()) ? "true" : "false")
      << "\">\n";
  
  out.indent(+1);

  write_stereotype(out);
  write_annotation(out);
  write_description_properties(out);
  
  out.indent();
  out << "<UML:BehavioralFeature.parameter>\n";
  out.indent(+1);

  write_return_type(out, decl);

  if (_lang == Uml)
    write_uml_params(out);
  else
    write_cpp_java_params(out, decl);

  out.indent(-1);
  out.indent();
  out << "</UML:BehavioralFeature.parameter>\n";
  
  out.indent(-1);
  out.indent();
  out << "</UML:Operation>\n";

  unload();
 
  return TRUE;
}
Esempio n. 18
0
// p point to ${body}
const char * UmlOperation::generate_body(QTextStream & f,
        WrapperStr indent,
        BooL & indent_needed,
        const char * p)
{
    if(isAbstract())
        return p + 7;

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

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

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

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

        if (pythonContextualBodyIndent())
            body_indent = indent;
    }

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

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

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

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

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

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

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

                f << body_indent;
            }
        }

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

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

    indent_needed = TRUE;

    return p + 7;
}
Esempio n. 19
0
void UmlOperation::gen_php_decl(QByteArray s, bool descr)
{
    QByteArray cl_stereotype =
        PhpSettings::classStereotype(parent()->stereotype());
    const char * p = bypass_comment(s);
    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    unsigned rank;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${final}", 8)) {
            p += 8;

            if (isPhpFinal())
                fw.write("final ");
        }
        else if (!strncmp(p, "${visibility}", 13)) {
            p += 13;
            UmlItem::write(visibility(), phpLanguage);
            fw.write(' ');
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            p += 11;

            if (isAbstract() && (cl_stereotype != "interface"))
                fw.write("abstract ");
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(phpNameSpec()));
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
        }
        else if (!strncmp(p, "${staticnl}", 11))
            break;
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa)
                write(pa[rank].type, phpLanguage);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa) {
                fw.write('$');
                writeq(pa[rank].name);
            }
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= npa)
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '\n') {
            if (descr) {
                fw.write("<br />");
                p += 1;
            }
            else {
                fw.write(' ');

                do
                    p += 1;

                while ((*p != 0) && (*p <= ' '));
            }
        }
        else if ((*p == '{') || (*p == ';')) {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
Esempio n. 20
0
void ClassDeclaration::toObjFile(int multiobj)
{
    unsigned offset;
    Symbol *sinit;
    enum_SC scclass;

    //printf("ClassDeclaration::toObjFile('%s')\n", toChars());

    if (type->ty == Terror)
    {   error("had semantic errors when compiling");
        return;
    }

    if (!members)
        return;

    if (multiobj && !hasStaticCtorOrDtor())
    {   obj_append(this);
        return;
    }

    if (global.params.symdebug)
        toDebug(this);

    assert(!scope);     // semantic() should have been run to completion

    scclass = SCglobal;
    if (isInstantiated())
        scclass = SCcomdat;

    // Put out the members
    for (size_t i = 0; i < members->dim; i++)
    {
        Dsymbol *member = (*members)[i];
        /* There might be static ctors in the members, and they cannot
         * be put in separate obj files.
         */
        member->toObjFile(multiobj);
    }

    // Generate C symbols
    toSymbol(this);
    toVtblSymbol();
    sinit = toInitializer();

    //////////////////////////////////////////////

    // Generate static initializer
    sinit->Sclass = scclass;
    sinit->Sfl = FLdata;
    ClassDeclaration_toDt(this, &sinit->Sdt);
    out_readonly(sinit);
    outdata(sinit);

    //////////////////////////////////////////////

    // Put out the TypeInfo
    type->genTypeInfo(NULL);
    //type->vtinfo->toObjFile(multiobj);

    //////////////////////////////////////////////

    // Put out the ClassInfo
    csym->Sclass = scclass;
    csym->Sfl = FLdata;

    /* The layout is:
       {
            void **vptr;
            monitor_t monitor;
            byte[] initializer;         // static initialization data
            char[] name;                // class name
            void *[] vtbl;
            Interface[] interfaces;
            ClassInfo *base;            // base class
            void *destructor;
            void *invariant;            // class invariant
            ClassFlags flags;
            void *deallocator;
            OffsetTypeInfo[] offTi;
            void *defaultConstructor;
            //const(MemberInfo[]) function(string) xgetMembers;   // module getMembers() function
            void *xgetRTInfo;
            //TypeInfo typeinfo;
       }
     */
    dt_t *dt = NULL;
    unsigned classinfo_size = global.params.isLP64 ? CLASSINFO_SIZE_64 : CLASSINFO_SIZE;    // must be ClassInfo.size
    offset = classinfo_size;
    if (Type::typeinfoclass)
    {
        if (Type::typeinfoclass->structsize != classinfo_size)
        {
#ifdef DEBUG
            printf("CLASSINFO_SIZE = x%x, Type::typeinfoclass->structsize = x%x\n", offset, Type::typeinfoclass->structsize);
#endif
            error("mismatch between dmd and object.d or object.di found. Check installation and import paths with -v compiler switch.");
            fatal();
        }
    }

    if (Type::typeinfoclass)
        dtxoff(&dt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
    else
        dtsize_t(&dt, 0);                // BUG: should be an assert()
    dtsize_t(&dt, 0);                    // monitor

    // initializer[]
    assert(structsize >= 8 || (cpp && structsize >= 4));
    dtsize_t(&dt, structsize);           // size
    dtxoff(&dt, sinit, 0, TYnptr);      // initializer

    // name[]
    const char *name = ident->toChars();
    size_t namelen = strlen(name);
    if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
    {   name = toPrettyChars();
        namelen = strlen(name);
    }
    dtsize_t(&dt, namelen);
    dtabytes(&dt, TYnptr, 0, namelen + 1, name);

    // vtbl[]
    dtsize_t(&dt, vtbl.dim);
    dtxoff(&dt, vtblsym, 0, TYnptr);

    // interfaces[]
    dtsize_t(&dt, vtblInterfaces->dim);
    if (vtblInterfaces->dim)
        dtxoff(&dt, csym, offset, TYnptr);      // (*)
    else
        dtsize_t(&dt, 0);

    // base
    if (baseClass)
        dtxoff(&dt, toSymbol(baseClass), 0, TYnptr);
    else
        dtsize_t(&dt, 0);

    // destructor
    if (dtor)
        dtxoff(&dt, toSymbol(dtor), 0, TYnptr);
    else
        dtsize_t(&dt, 0);

    // invariant
    if (inv)
        dtxoff(&dt, toSymbol(inv), 0, TYnptr);
    else
        dtsize_t(&dt, 0);

    // flags
    ClassFlags::Type flags = ClassFlags::hasOffTi;
    if (isCOMclass()) flags |= ClassFlags::isCOMclass;
    if (isCPPclass()) flags |= ClassFlags::isCPPclass;
    flags |= ClassFlags::hasGetMembers;
    flags |= ClassFlags::hasTypeInfo;
    if (ctor)
        flags |= ClassFlags::hasCtor;
    if (isabstract)
        flags |= ClassFlags::isAbstract;
    for (ClassDeclaration *cd = this; cd; cd = cd->baseClass)
    {
        if (cd->members)
        {
            for (size_t i = 0; i < cd->members->dim; i++)
            {
                Dsymbol *sm = (*cd->members)[i];
                //printf("sm = %s %s\n", sm->kind(), sm->toChars());
                if (sm->hasPointers())
                    goto L2;
            }
        }
    }
    flags |= ClassFlags::noPointers;
L2:
    dtsize_t(&dt, flags);


    // deallocator
    if (aggDelete)
        dtxoff(&dt, toSymbol(aggDelete), 0, TYnptr);
    else
        dtsize_t(&dt, 0);

    // offTi[]
    dtsize_t(&dt, 0);
    dtsize_t(&dt, 0);            // null for now, fix later

    // defaultConstructor
    if (defaultCtor)
        dtxoff(&dt, toSymbol(defaultCtor), 0, TYnptr);
    else
        dtsize_t(&dt, 0);

    // xgetRTInfo
    if (getRTInfo)
        getRTInfo->toDt(&dt);
    else if (flags & ClassFlags::noPointers)
        dtsize_t(&dt, 0);
    else
        dtsize_t(&dt, 1);

    //dtxoff(&dt, toSymbol(type->vtinfo), 0, TYnptr); // typeinfo

    //////////////////////////////////////////////

    // Put out (*vtblInterfaces)[]. Must immediately follow csym, because
    // of the fixup (*)

    offset += vtblInterfaces->dim * (4 * Target::ptrsize);
    for (size_t i = 0; i < vtblInterfaces->dim; i++)
    {   BaseClass *b = (*vtblInterfaces)[i];
        ClassDeclaration *id = b->base;

        /* The layout is:
         *  struct Interface
         *  {
         *      ClassInfo *interface;
         *      void *[] vtbl;
         *      size_t offset;
         *  }
         */

        // Fill in vtbl[]
        b->fillVtbl(this, &b->vtbl, 1);

        dtxoff(&dt, toSymbol(id), 0, TYnptr);         // ClassInfo

        // vtbl[]
        dtsize_t(&dt, id->vtbl.dim);
        dtxoff(&dt, csym, offset, TYnptr);

        dtsize_t(&dt, b->offset);                        // this offset

        offset += id->vtbl.dim * Target::ptrsize;
    }

    // Put out the (*vtblInterfaces)[].vtbl[]
    // This must be mirrored with ClassDeclaration::baseVtblOffset()
    //printf("putting out %d interface vtbl[]s for '%s'\n", vtblInterfaces->dim, toChars());
    for (size_t i = 0; i < vtblInterfaces->dim; i++)
    {   BaseClass *b = (*vtblInterfaces)[i];
        ClassDeclaration *id = b->base;

        //printf("    interface[%d] is '%s'\n", i, id->toChars());
        size_t j = 0;
        if (id->vtblOffset())
        {
            // First entry is ClassInfo reference
            //dtxoff(&dt, toSymbol(id), 0, TYnptr);

            // First entry is struct Interface reference
            dtxoff(&dt, csym, classinfo_size + i * (4 * Target::ptrsize), TYnptr);
            j = 1;
        }
        assert(id->vtbl.dim == b->vtbl.dim);
        for (; j < id->vtbl.dim; j++)
        {
            assert(j < b->vtbl.dim);
#if 0
            RootObject *o = b->vtbl[j];
            if (o)
            {
                printf("o = %p\n", o);
                assert(o->dyncast() == DYNCAST_DSYMBOL);
                Dsymbol *s = (Dsymbol *)o;
                printf("s->kind() = '%s'\n", s->kind());
            }
#endif
            FuncDeclaration *fd = b->vtbl[j];
            if (fd)
                dtxoff(&dt, fd->toThunkSymbol(b->offset), 0, TYnptr);
            else
                dtsize_t(&dt, 0);
        }
    }

    // Put out the overriding interface vtbl[]s.
    // This must be mirrored with ClassDeclaration::baseVtblOffset()
    //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
    ClassDeclaration *cd;
    FuncDeclarations bvtbl;

    for (cd = this->baseClass; cd; cd = cd->baseClass)
    {
        for (size_t k = 0; k < cd->vtblInterfaces->dim; k++)
        {   BaseClass *bs = (*cd->vtblInterfaces)[k];

            if (bs->fillVtbl(this, &bvtbl, 0))
            {
                //printf("\toverriding vtbl[] for %s\n", bs->base->toChars());
                ClassDeclaration *id = bs->base;

                size_t j = 0;
                if (id->vtblOffset())
                {
                    // First entry is ClassInfo reference
                    //dtxoff(&dt, toSymbol(id), 0, TYnptr);

                    // First entry is struct Interface reference
                    dtxoff(&dt, toSymbol(cd), classinfo_size + k * (4 * Target::ptrsize), TYnptr);
                    j = 1;
                }

                for (; j < id->vtbl.dim; j++)
                {
                    FuncDeclaration *fd;

                    assert(j < bvtbl.dim);
                    fd = bvtbl[j];
                    if (fd)
                        dtxoff(&dt, fd->toThunkSymbol(bs->offset), 0, TYnptr);
                    else
                        dtsize_t(&dt, 0);
                }
            }
        }
    }

    csym->Sdt = dt;
    // ClassInfo cannot be const data, because we use the monitor on it
    outdata(csym);
    if (isExport())
        objmod->export_symbol(csym,0);

    //////////////////////////////////////////////

    // Put out the vtbl[]
    //printf("putting out %s.vtbl[]\n", toChars());
    dt = NULL;
    if (vtblOffset())
        dtxoff(&dt, csym, 0, TYnptr);           // first entry is ClassInfo reference
    for (size_t i = vtblOffset(); i < vtbl.dim; i++)
    {
        FuncDeclaration *fd = vtbl[i]->isFuncDeclaration();

        //printf("\tvtbl[%d] = %p\n", i, fd);
        if (fd && (fd->fbody || !isAbstract()))
        {
            // Ensure function has a return value (Bugzilla 4869)
            fd->functionSemantic();

            Symbol *s = toSymbol(fd);

            if (isFuncHidden(fd))
            {   /* fd is hidden from the view of this class.
                 * If fd overlaps with any function in the vtbl[], then
                 * issue 'hidden' error.
                 */
                for (size_t j = 1; j < vtbl.dim; j++)
                {   if (j == i)
                        continue;
                    FuncDeclaration *fd2 = vtbl[j]->isFuncDeclaration();
                    if (!fd2->ident->equals(fd->ident))
                        continue;
                    if (fd->leastAsSpecialized(fd2) || fd2->leastAsSpecialized(fd))
                    {
                        TypeFunction *tf = (TypeFunction *)fd->type;
                        if (tf->ty == Tfunction)
                            deprecation("use of %s%s hidden by %s is deprecated. Use 'alias %s.%s %s;' to introduce base class overload set.", fd->toPrettyChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs), toChars(), fd->parent->toChars(), fd->toChars(), fd->toChars());
                        else
                            deprecation("use of %s hidden by %s is deprecated", fd->toPrettyChars(), toChars());
                        s = rtlsym[RTLSYM_DHIDDENFUNC];
                        break;
                    }
                }
            }

            dtxoff(&dt, s, 0, TYnptr);
        }
        else
            dtsize_t(&dt, 0);
    }
    vtblsym->Sdt = dt;
    vtblsym->Sclass = scclass;
    vtblsym->Sfl = FLdata;
    out_readonly(vtblsym);
    outdata(vtblsym);
    if (isExport())
        objmod->export_symbol(vtblsym,0);
}
Esempio n. 21
0
/**
 * Indicate if this is an abstract method
 *
 * @return .true if the method is abstract.  .false otherwise.
 */
RexxObject *MethodClass::isAbstractRexx( )
{
    return booleanObject(isAbstract());
}
Esempio n. 22
0
void UmlOperation::gen_uml_decl()
{
    if (isAbstract())
        fw.write("abstract, ");

    if (isClassMember())
        fw.write("static, ");

    write(visibility());
    writeq(name());

    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    unsigned rank;
    const char * sep = "(";

    for (rank = 0; rank != npa; rank += 1) {
        const UmlParameter & p = pa[rank];

        fw.write(sep);
        sep = ", ";

        switch (p.dir) {
        case InputOutputDirection:
            fw.write("inout ");
            break;

        case InputDirection:
            fw.write("in ");
            break;

        default:
            // OutputDirection
            fw.write("out ");
        }

        writeq(p.name);
        fw.write(" : ");
        write(p.type);

        QByteArray s = p.default_value;

        if (!s.isEmpty()) {
            if (s[0] != '=')
                fw.write(" = ");

            writeq(s);
        }
    }

    fw.write((rank == 0) ? "() : " : ") : ");
    write(returnType());

    sep = ",  exceptions : ";

    const QList<UmlTypeSpec> e = exceptions();
    unsigned n = e.count();

    for (unsigned index2 = 0; index2 != n; index2 += 1) {
        fw.write(sep);
        sep = ", ";
        write(e[index2]);
    }
}
Esempio n. 23
0
void UmlOperation::gen_cpp_decl(QByteArray s, bool descr)
{
    const char * p = bypass_comment(s);

    if (! descr) {
        write((cppVisibility() == DefaultVisibility)
              ? visibility() : cppVisibility(),
              cppLanguage);
        fw.write(": ");
        p = bypass_comment(s);
    }
    else
        p = s;

    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    unsigned rank;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${friend}", 9)) {
            p += 9;

            if (isCppFriend())
                fw.write("friend ");
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${inline}", 9)) {
            p += 9;

            if (isCppInline())
                fw.write("inline ");
        }
        else if (!strncmp(p, "${virtual}", 10)) {
            p += 10;

            if (isCppVirtual())
                fw.write("virtual ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            write(returnType(), cppLanguage);
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(cppNameSpec()));
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
        }
        else if (!strncmp(p, "${const}", 8)) {
            p += 8;

            if (isCppConst())
                fw.write(" const");
        }
        else if (!strncmp(p, "${volatile}", 11)) {
            p += 11;

            if (isVolatile())
                fw.write(" volatile");
        }
        else if (!strncmp(p, "${throw}", 8)) {
            p += 8;

            const char * sep = " throw (";
            QList<UmlTypeSpec> e = exceptions();
            unsigned n = e.count();
            unsigned index2;

            for (index2 = 0; index2 != n; index2 += 1) {
                fw.write(sep);
                sep = ", ";
                write(e[index2], cppLanguage);
            }

            if (index2 != 0)
                fw.write(')');
            else if (CppSettings::operationForceThrow())
                fw.write(" throw ()");
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa)
                write(pa[rank].type, cppLanguage);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < pa.count())
                writeq(pa[rank].name);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= pa.count())
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            if (isAbstract())
                fw.write("= 0 ");

            break;
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if ((m != 0) || ((m = setOf()) != 0))
                writeq(CppSettings::relationAttributeStereotype(m->stereotype()));
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if (((m != 0) || ((m = setOf()) != 0)) &&
                (m->kind() == aRelation))
                write(((UmlRelation *) m)->association(), cppLanguage);
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '\n') {
            if (descr) {
                fw.write("<br />");
                p += 1;
            }
            else {
                fw.write(' ');

                do
                    p += 1;

                while ((*p != 0) && (*p <= ' '));
            }
        }
        else if ((*p == '{') || (*p == ';')) {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
Esempio n. 24
0
void UmlOperation::gen_python_decl(QByteArray s, bool descr)
{
    QByteArray cl_stereotype =
        PythonSettings::classStereotype(parent()->stereotype());
    const char * p = bypass_comment(s);
    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    bool in_params = FALSE;
    unsigned rank;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${docstring}", 12))
            p += 12;
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("@staticmethod<br />");
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            p += 11;

            if (isAbstract())
                fw.write("@abstractmethod<br />");
        }
        else if (!strncmp(p, "${@}", 4)) {
            p += 4;
            writeq(pythonDecorators());
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(pythonNameSpec()));
        }
        else if (!strncmp(p, "${class}", 8)) {
            p += 8;
            parent()->write();
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
            in_params = TRUE;
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
            in_params = FALSE;
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa) {
                const UmlTypeSpec & t = pa[rank].type;

                if (! t.toString().isEmpty()) {
                    if (in_params)
                        fw.write(": ");

                    write(t, pythonLanguage);
                }
            }
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa) {
                fw.write('$');
                writeq(pa[rank].name);
            }
            else
                fw.write("???");
        }
        else if (sscanf(p, "${v%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank >= npa)
                fw.write("???");
            else if (! pa[rank].default_value.isEmpty()) {
                fw.write(" = ");
                writeq(pa[rank].default_value);
            }
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;

            const UmlTypeSpec & t = returnType();

            if (! t.toString().isEmpty()) {
                fw.write(" -> ");
                write(t, pythonLanguage);
            }
        }
        else if (*p == ':') {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '\r')
            p += 1;
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
Esempio n. 25
0
void UmlOperation::generate(QTextStream & f, const WrapperStr & cl_stereotype,
                            WrapperStr indent)
{
    if (!javaDecl().isEmpty()) {
        const char * p = javaDecl();
        const char * pp = 0;
        const char * afterparam = 0;
        const Q3ValueList<UmlParameter> & params = this->params();
        unsigned rank;
        const char * body_indent = strstr(p, "${body}");

        if (body_indent != 0) {
            while ((body_indent != p) &&
                   ((body_indent[-1] == ' ') || (body_indent[-1] == '\t')))
                body_indent -= 1;
        }

        // manage old style indent
        while ((*p == ' ') || (*p == '\t'))
            indent += *p++;

        f << indent;

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

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

                if (*p == 0)
                    break;

                f << indent;
            }

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

                if (p == body_indent)
                    p = generate_body(f, indent, p);
                else if (*p)
                    f << indent;
            }
            else if (*p == '{') {
                if (afterparam != 0) {
                    if (cl_stereotype == "@interface") {
                        if (strstr(afterparam, "default") != 0)
                            afterparam = 0;
                        else {
                            f << ";";
                            p = bypass_body(p);
                            continue;
                        }
                    }
                    else if (isAbstract() || (cl_stereotype == "interface")) {
                        f << ";";
                        p = bypass_body(p);
                        continue;
                    }
                }

                f << '{';
                p += 1;
            }
            else if (*p == '@')
                manage_alias(p, f);
            else if (*p != '$') {
                if (p == body_indent)
                    p = generate_body(f, indent, p);
                else
                    f << *p++;
            }
            else if (!strncmp(p, "${comment}", 10))
                manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment());
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${visibility}", 13)) {
                p += 13;
                generate_visibility(f, cl_stereotype);
            }
            else if (!strncmp(p, "${final}", 8)) {
                p += 8;

                if (isJavaFinal())
                    f << "final ";
            }
            else if (!strncmp(p, "${static}", 9)) {
                p += 9;

                if (isClassMember())
                    f << "static ";
            }
            else if (!strncmp(p, "${abstract}", 11)) {
                p += 11;

                if (isAbstract() &&
                    (cl_stereotype != "interface") &&
                    (cl_stereotype != "@interface"))
                    f << "abstract ";
            }
            else if (!strncmp(p, "${synchronized}", 15)) {
                p += 15;

                if (isJavaSynchronized())
                    f << "synchronized ";
            }
            else if (!strncmp(p, "${type}", 7)) {
                p += 7;
                UmlClass::write(f, returnType());
            }
            else if (!strncmp(p, "${stereotype}", 13)) {
                p += 13;
                // get/set relation with multiplicity > 1
                f << JavaSettings::relationAttributeStereotype(stereotype());
            }
            else if (!strncmp(p, "${name}", 7)) {
                p += 7;
                f << compute_name();
            }
            else if (!strncmp(p, "${(}", 4)) {
                p += 4;
                f << '(';
            }
            else if (!strncmp(p, "${)}", 4)) {
                p += 4;
                f << ')';
                afterparam = p;
            }
            else if (sscanf(p, "${t%u}", &rank) == 1) {
                if (!generate_type(params, rank, f))
                    param_error(parent()->name(), name(), rank);

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

                p = strchr(p, '}') + 1;
            }
            else if (!strncmp(p, "${throws}", 9)) {
                p += 9;
                const char * sep;
                const Q3ValueList<UmlTypeSpec> & exceptions = this->exceptions();
                Q3ValueList<UmlTypeSpec>::ConstIterator it;

                for (it = exceptions.begin(), sep = " throws ";
                     it != exceptions.end();
                     ++it, sep = ", ") {
                    f << sep;
                    UmlClass::write(f, *it);
                }
            }
            else if (!strncmp(p, "${staticnl}", 11)) {
                p += 11;

                if (isClassMember()) {
                    f << '\n';

                    if (*p)
                        f << indent;
                }
                else
                    f << ' ';
            }
            else if (!strncmp(p, "${body}", 7) &&
                     (pp == 0))	// not in comment
                p = generate_body(f, indent, p);
            else if (!strncmp(p, "${association}", 14)) {
                p += 14;

                UmlClassMember * m;

                if (((m = getOf()) != 0) && (m->kind() == aRelation))
                    UmlClass::write(f, ((UmlRelation *) m)->association());
                else if (((m = setOf()) != 0) && (m->kind() == aRelation))
                    UmlClass::write(f, ((UmlRelation *) m)->association());
            }
            else if (!strncmp(p, "${@}", 4)) {
                p += 4;

                if (pp != 0)
                    f << "${@}";
                else if (! javaAnnotations().isEmpty()) {
                    pp = p;
                    p = javaAnnotations();
                }
            }
            else
                f << *p++;
        }

        f << '\n';
    }
}
Esempio n. 26
0
void UmlOperation::generate(QTextStream & f, const WrapperStr &,
                            WrapperStr indent, BooL & indent_needed,
                            int &, const WrapperStr &)
{
    const char * p = pythonDecl();

    if ((p == 0) || (*p == 0))
        return;

    const char * pp = 0;
    WrapperStr saved_indent = indent;
    WrapperStr indent_step = PythonSettings::indentStep();
    const char * afterparam = 0;
    const QList<UmlParameter> & params = this->params();
    unsigned rank;
    bool isinline = TRUE;
    bool in_params = FALSE;

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

            // comment management done
            p = pp;

            if (*p == 0)
                break;

            pp = 0;
            indent = saved_indent;
        }

        if (*p == '@')
            manage_alias(p, f, indent, indent_needed);
        else if (*p != '$') {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            switch (*p) {
            case ':':
                if (pp == 0) {
                    indent += indent_step;
                    saved_indent = indent;
                    indent_step = "";
                }

                break;

            case '\n':
                indent_needed = TRUE;
                break;
            }

            f << *p++;
        }
        else if (!strncmp(p, "${comment}", 10))
            manage_comment(p, pp);
        else if (!strncmp(p, "${description}", 14))
            manage_description(p, pp);
        else if (!strncmp(p, "${docstring}", 12))
            manage_docstring(p, pp, indent_needed, indent, saved_indent);
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember()) {
                if (indent_needed)
                    f << indent;
                else
                    indent_needed = TRUE;

                f << "@staticmethod\n";
            }
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            p += 11;

            if (isAbstract()) {
                if (indent_needed)
                    f << indent;
                else
                    indent_needed = TRUE;

                f << "@abstractmethod\n";
            }
        }
        else if (!strncmp(p, "${@}", 4)) {
            p += 4;
            manage_decorators(f, pythonDecorators(), indent, indent_needed);
        }
        else if (!strncmp(p, "${name}", 7)) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            p += 7;
            f << compute_name();
        }
        else if (!strncmp(p, "${class}", 8)) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            p += 8;
            f << parent()->name();
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            f << '(';
            in_params = TRUE;
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            f << ')';
            afterparam = p;
            in_params = FALSE;
        }
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            if (!generate_type(params, rank, f, in_params))
                param_error(parent()->name(), name(), rank);

            p = strchr(p, '}') + 1;
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            if (!generate_var(params, rank, f))
                param_error(parent()->name(), name(), rank);

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

            p = strchr(p, '}') + 1;
        }
        else if (!strncmp(p, "${body}", 7) &&
                 (pp == 0))	{// not in comment
            isinline = FALSE;
            p = generate_body(f, indent, indent_needed, p);
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;

            UmlClassMember * m;

            if ((((m = getOf()) != 0) || ((m = setOf()) != 0)) &&
                (m->kind() == aRelation)) {
                if (indent_needed) {
                    indent_needed = FALSE;
                    f << indent;
                }

                UmlClass::write(f, ((UmlRelation *) m)->association());
            }
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;

            const UmlTypeSpec & t = returnType();

            if ((t.type != 0) || !t.explicit_type.isEmpty()) {
                f << " -> ";

                UmlClass::write(f, t);
            }
        }
        else {
            // strange
            if (indent_needed) {
                indent_needed = FALSE;
                f << indent;
            }

            f << *p++;
        }
    }

    if (isinline) {
        if (indent_needed)
            f << indent << '\n';
        else
            f << '\n';

        indent_needed = TRUE;
    }
}
Esempio n. 27
0
void UmlClass::generate(QTextOStream & f, QCString indent) {
  QVector<UmlItem> ch = children();
  const QValueList<UmlActualParameter> actuals = this->actuals();
  const unsigned sup = ch.size();
  const QCString & stereotype = java_stereotype();
  bool an_enum_pattern = (stereotype == "enum_pattern");
  bool an_enum = (stereotype == "enum");
  unsigned index;
  const char * p = javaDecl();
  const char * pp = 0;
  const char * sep;
  
  while ((*p == ' ') || (*p == '\t'))
    indent += *p++;
  
  f << indent;
    
  for (;;) {
    if (*p == 0) {
      if (pp == 0)
	break;
      
      // comment management done
      p = pp;
      pp = 0;
      if (*p == 0)
	break;
      f << indent;
    }

    if (*p == '\n') {
      f << *p++;
      if (*p &&
	  strncmp(p, "${members}", 10) &&
	  strncmp(p, "${items}", 8) &&
	  strncmp(p, "${cases}", 8))
	f << indent;
    }
    else if (*p == '@')
      manage_alias(p, f);
    else if (*p != '$')
      f << *p++;
    else if (!strncmp(p, "${comment}", 10))
      manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment());
    else if (!strncmp(p, "${description}", 14))
      manage_description(p, pp);
    else if (!strncmp(p, "${public}", 9)) {
      p += 9;
      if (visibility() == PublicVisibility)
	f << "public ";
    }
    else if (!strncmp(p, "${visibility}", 13)) {
      p += 13;
      generate_visibility(f, "");
    }
    else if (!strncmp(p, "${final}", 8)) {
      p += 8;
      if (isJavaFinal())
	f << "final ";
    }
    else if (!strncmp(p, "${abstract}", 11)) {
      p += 11;
      if (isAbstract())
	f << "abstract ";
    }
    else if (! strncmp(p, "${name}", 7)) {
      p += 7;
      f << name();
      generate_formals(f);
    }
    else if (!strncmp(p, "${@}", 4)) {
      p += 4;
      if (pp != 0)
	f << "${@}";
      else if (! javaAnnotations().isEmpty()) {
	pp = p;
	p = javaAnnotations();
      }
    }
    else if (an_enum_pattern) {
      if (!strncmp(p, "${members}", 10)) {
	p += 10;
	
	int current_value = 0;
	QCString name = this->name();
	
	for (index = 0; index != sup; index += 1)
	  if ((ch[index]->kind() != aNcRelation) &&
	      !((UmlClassItem *) ch[index])->javaDecl().isEmpty())
	    ((UmlClassItem *) ch[index])->
	      generate_enum_pattern_item(f, current_value, name, indent);
      
	if (*p == '}')
	  f << indent;
      }
      else if (!strncmp(p, "${cases}", 8)) {
	p += 8;
	
	for (index = 0; index != sup; index += 1)
	  if ((ch[index]->kind() != aNcRelation) &&
	      !((UmlClassItem *) ch[index])->javaDecl().isEmpty())
	    ((UmlClassItem *) ch[index])->generate_enum_pattern_case(f, indent);
      }
      else
	// strange
	f << *p++;
    }
    else if (! strncmp(p, "${extends}", 10)) {
      p += 10;

      // extends
	
      sep = " extends ";
      
      for (index = 0; index != sup; index += 1) {
	UmlItem * x = ch[index];
	
	if (x->kind() == aRelation)
	  ((UmlRelation *) x)->generate_extends(sep, f, actuals, stereotype);
      }
    }
    else if (! strncmp(p, "${implements}", 13)) {
      p += 13;

      if (stereotype != "interface") {
	
	// implements
	
	sep = " implements ";
	
	for (index = 0; index != sup; index += 1) {
	  UmlItem * x = ch[index];
	  
	  if (x->kind() == aRelation)
	    ((UmlRelation *) x)->generate_implements(sep, f, actuals, stereotype);
	}
      }
    }
    else if (! strncmp(p, "${members}", 10)) {
      p += 10;
  
      // members
      
      if (an_enum) {
	for (index = 0; index != sup; index += 1) {
	  if (ch[index]->kind() != aNcRelation) {
	    UmlClassItem * it = (UmlClassItem *)ch[index];
	    
	    if (! it->javaDecl().isEmpty())
	      it->generate_enum_member(f, indent);
	  }
	}
      }
      else {
	for (index = 0; index != sup; index += 1) {
	  UmlItem * it = ch[index];
	  
	  if (it->kind() == aClass) {
	    if (! ((UmlClass *) it)->javaDecl().isEmpty()) {
	      ((UmlClass *) it)->generate(f, indent + "  ");
	      f << '\n';
	    }
	  }
	  else if ((it->kind() != aNcRelation) &&
		   !((UmlClassItem *) it)->javaDecl().isEmpty())
	    ((UmlClassItem *) it)->generate(f, stereotype, indent);
	}
      }
      
      if (*p == '}')
	f << indent;
    }
    else if (an_enum && ! strncmp(p, "${items}", 8)) {
      p += 8;
  
      // enums items
      
      BooL first = TRUE;
      
      for (index = 0; index != sup; index += 1) {
	if (ch[index]->kind() != aNcRelation) {
	  UmlClassItem * it = (UmlClassItem *)ch[index];
	  
	  if (! it->javaDecl().isEmpty())
	    it->generate_enum_item(f, indent, first);
	}
      }
      
      if (*p == '}')
	f << indent;
    }
    else
      // strange
      f << *p++;
  }
}
Esempio n. 28
0
void UmlOperation::gen_java_decl(QByteArray s, bool descr)
{
    const char * p = bypass_comment(s);
    const QList<UmlParameter> & pa = params();
    unsigned npa = pa.count();
    unsigned rank;

    while (*p) {
        if (!strncmp(p, "${comment}", 10))
            p += 10;
        else if (!strncmp(p, "${description}", 14))
            p += 14;
        else if (!strncmp(p, "${final}", 8)) {
            p += 8;

            if (isJavaFinal())
                fw.write("final ");
        }
        else if (!strncmp(p, "${visibility}", 13)) {
            p += 13;
            UmlItem::write(visibility(), javaLanguage);
            fw.write(' ');
        }
        else if (!strncmp(p, "${static}", 9)) {
            p += 9;

            if (isClassMember())
                fw.write("static ");
        }
        else if (!strncmp(p, "${abstract}", 11)) {
            p += 11;

            if (isAbstract())
                fw.write("abstract ");
        }
        else if (!strncmp(p, "${synchronized}", 15)) {
            p += 15;

            if (isJavaSynchronized())
                fw.write("synchronized ");
        }
        else if (!strncmp(p, "${type}", 7)) {
            p += 7;
            write(returnType(), javaLanguage);
        }
        else if (!strncmp(p, "${name}", 7)) {
            p += 7;
            writeq(compute_name(javaNameSpec()));
        }
        else if (!strncmp(p, "${(}", 4)) {
            p += 4;
            fw.write('(');
        }
        else if (!strncmp(p, "${)}", 4)) {
            p += 4;
            fw.write(')');
        }
        else if (!strncmp(p, "${throws}", 9)) {
            p += 9;

            const char * sep = " throws ";
            const QList<UmlTypeSpec> e = exceptions();
            unsigned n = e.count();

            for (unsigned index2 = 0; index2 != n; index2 += 1) {
                fw.write(sep);
                sep = ", ";
                write(e[index2], javaLanguage);
            }
        }
        else if (!strncmp(p, "${staticnl}", 11))
            break;
        else if (sscanf(p, "${t%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa)
                write(pa[rank].type, javaLanguage);
            else
                fw.write("???");
        }
        else if (sscanf(p, "${p%u}", &rank) == 1) {
            p = strchr(p, '}') + 1;

            if (rank < npa)
                writeq(pa[rank].name);
            else
                fw.write("???");
        }
        else if (!strncmp(p, "${stereotype}", 13)) {
            p += 13;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if ((m != 0) || ((m = setOf()) != 0))
                writeq(JavaSettings::relationAttributeStereotype(m->stereotype()));
        }
        else if (!strncmp(p, "${association}", 14)) {
            p += 14;
            // get/set relation with multiplicity > 1
            UmlClassMember * m = getOf();

            if (((m != 0) || ((m = setOf()) != 0)) &&
                (m->kind() == aRelation))
                write(((UmlRelation *) m)->association(), javaLanguage);
        }
        else if (!strncmp(p, "${@}", 4))
            p += 4;
        else if (*p == '\r')
            p += 1;
        else if (*p == '\n') {
            if (descr) {
                fw.write("<br />");
                p += 1;
            }
            else {
                fw.write(' ');

                do
                    p += 1;

                while ((*p != 0) && (*p <= ' '));
            }
        }
        else if ((*p == '{') || (*p == ';')) {
            if (descr)
                fw.write(*p++);
            else
                break;
        }
        else if (*p == '@')
            manage_alias(p);
        else
            writeq(*p++);
    }
}
Esempio n. 29
0
void UmlClass::write(FileOut & out) {
  QCString st = stereotype();
  
  if (st == "metaclass")
    return;
  
  bool is_actor = (st == "actor");
  bool is_enum = (st == "enum");
  bool is_stereotype =
    (st == "stereotype") && 
    (parent()->parent()->kind() == aPackage) &&
    (parent()->parent()->stereotype() == "profile");
  
  if (!is_actor) {
    switch (_lang) {
    case Cpp:
      if (cppDecl().isEmpty())
	return;
      break;
    case Java:
      if (javaDecl().isEmpty())
	return;
    default:
      break;
    }
  }

  const char * k = (parent()->kind() == aClass)
    ? "nestedClassifier"
    : ((!_uml_20)
       ? "packagedElement"
       : ((is_stereotype) ? "ownedStereotype" : "ownedMember"));
  bool is_assoc_class = (_assoc != 0);
  
  out.indent();
  out << "<" << k << " xmi:type=\"uml:"
    << ((is_actor) 
	? "Actor"
	: ((is_assoc_class)
	   ? "AssociationClass"
	   : ((st == "interface")
	      ? "Interface" 
	      : ((is_enum)
		 ?"Enumeration"
		 : ((is_stereotype) ? "Stereotype" : "Class")))))
    << "\" name=\"";
  out.quote(name());
  out << '"';
  out.id(this);
  write_visibility(out);
  if (isAbstract())
    out << " isAbstract=\"true\"";
  if (isActive())
    out << " isActive=\"true\"";
  out << ">\n";
  
  if (is_assoc_class)
    _assoc->write_ends(out);
    
  out.indent(+1);
  
  write_constraint(out);
  write_annotation(out);
  write_description_properties(out);
  
  if (_gen_extension && (st == "typedef")) {
    const UmlTypeSpec & base = baseType();
    
    if ((base.type != 0) || !base.explicit_type.isEmpty()) {
      out.indent();
      out << "<xmi:Extension extender=\"Bouml\">\n";
      out.indent();
      out << "\t<typedef>\n";
      out.indent(+2);
      UmlItem::write_type(out, base, "base");
      out.indent(-2);
      out.indent();
      out << "\t</typedef>\n";
      out.indent();
      out << "</xmi:Extension>\n";
    }
  }
  
  write_formals(out);
  write_actuals(out);
  
  const QVector<UmlItem> ch = children();
  unsigned n = ch.size();
  unsigned i;
  
  for (i = 0; i != n; i += 1)
    ch[i]->write(out);
  
  if (is_stereotype) {
    QCString path;
    
    if (propertyValue("stereotypeIconPath", path) && !path.isEmpty()) {
      out.indent();
      out << "<icon xmi:type=\"uml:Image\"";
      out.id_prefix(this, "Icon_");
      out << " location=\"" << path << "\"/>\n";
    }
  }
  
  out.indent(-1);
  out.indent();
  out << "</" << k << ">\n";
  
  if (is_stereotype)
    for (i = 0; i != n; i += 1)
      if (ch[i]->kind() == aRelation)
	((UmlRelation *) ch[i])->write_extension(out);
  
  unload();
}
Esempio n. 30
0
bool UmlClass::write_if_needed(FileOut & out)
{
    // even if the class doen't have children
    parent()->write(out);

    if ((stereotype() == "actor") ||
        ((parent()->kind() != aClassView) &&
         (parent()->kind() != aClass)))
        // force it to be an actor
        write_actor(out);
    else {
        switch (_lang) {
        case Cpp:
            if (cppDecl().isEmpty())
                return FALSE;

            break;

        case Java:
            if (javaDecl().isEmpty())
                return FALSE;

        default:
            break;
        }

        bool interf = (stereotype() == "interface");

        out.indent();
        out << ((interf) ? "<UML:Interface name=\"" : "<UML:Class name=\"");
        out.quote(name());
        out << '"';
        out.id(this);
        out << " visibility=\"public\" isAbstract=\""
            << ((isAbstract()) ? "true" : "false")
            << "\" isActive=\"false\" >\n";
        out.indent(+1);

        if (! interf)
            write_stereotype(out);

        write_annotation(out);
        write_description_properties(out);

        const QVector<UmlItem*> ch = children();
        unsigned n = ch.size();
        bool used = FALSE;
        bool haveRel = FALSE;

        for (unsigned i = 0; i != n; i += 1) {
            switch (ch[i]->kind()) {
            case aNcRelation:
                break;

            case aRelation:
                haveRel = TRUE;
                break;

            default:
                used |= ch[i]->write_if_needed(out);
            }
        }

        if (used) {
            out.indent(-1);
            out.indent();
            out << "</UML:Classifier.feature>\n";
        }


        out.indent(-1);
        out.indent();
        out << ((interf) ? "</UML:Interface>\n" : "</UML:Class>\n");

        if (haveRel) {
            for (unsigned i = 0; i != n; i += 1)
                if (ch[i]->kind() == aRelation)
                    used |= ch[i]->write_if_needed(out);
        }
    }

    unload();

    return TRUE;
}