Interaction::CommandResult* CCreateField::create(Visualization::Item* /*source*/, Visualization::Item* target,
	const QString& name, const QStringList& attributes)
{
	auto cl = dynamic_cast<OOModel::Class*> (target->node());
	Q_ASSERT(cl);

	auto f = new OOModel::Field();
	f->setTypeExpression(new OOModel::EmptyExpression());
	if (!name.isEmpty()) f->setName(name);

	// Set visibility
	if (attributes.first() == "private" ) f->setVisibility(OOModel::Visibility::PRIVATE);
	else if (attributes.first() == "protected" ) f->setVisibility(OOModel::Visibility::PROTECTED);
	else if (attributes.first() == "public" ) f->setVisibility(OOModel::Visibility::PUBLIC);
	else f->setVisibility(OOModel::Visibility::DEFAULT);

	// Set scope
	if (attributes.last() == "static") f->setStorageSpecifier(OOModel::StorageSpecifier::CLASS_VARIABLE);
	else f->setStorageSpecifier(OOModel::StorageSpecifier::INSTANCE_VARIABLE);

	cl->fields()->beginModification("create field");
	cl->fields()->append(f);
	cl->fields()->endModification();

	target->setUpdateNeeded(Visualization::Item::StandardUpdate);
	target->scene()->addPostEventAction(new Interaction::SetCursorEvent(target,
			(name.isEmpty() ? static_cast<Model::Node*>(f->nameNode()) : f->typeExpression()),
			Interaction::SetCursorEvent::CursorDefault, false));

	return new Interaction::CommandResult();
}
Exemple #2
0
 CatchClause* Parser::catchClause()
 {
     eat (T_LeftParen);
     Str* catchvar_name = identifier();
     Type* catchvar_type_name = NULL;
     if (match(T_Colon))
         catchvar_type_name = typeExpression();
     eat (T_RightParen);
     Seq<Stmt*>* catchblock = statementBlock();
     return ALLOC(CatchClause, (catchvar_name, catchvar_type_name, catchblock));
 }
Exemple #3
0
        Expr* Parser::varBindings(uint32_t* pos, NameComponent* ns, bool is_const, bool is_static, int flags, uint32_t* numbindings, Expr** firstName)
        {
            AvmAssert( !is_const || firstName == NULL );

            Expr* inits = NULL;
            eat(is_const ? T_Const : T_Var);
            *pos = position();
            if (numbindings)
                *numbindings = 0;
            if (firstName)
                *firstName = NULL;
            for (;;) {
                Str* name = identifier();
                Type* type_name = NULL;
                if (match(T_Colon))
                    type_name = typeExpression();
                if (numbindings)
                    *numbindings += 1;
                if (!is_const)
                    addVarBinding(ns, name, type_name, is_static ? topRib->next : topRib);
                /*
                if (is_const && hd() != T_Assign)
                    compiler->syntaxError(*pos, SYNTAXERR_CONST_INIT_REQD);
                */
                if (match(T_Assign)) {
                    Expr* init = assignmentExpression(flags);
                    Expr* lhs = ALLOC(QualifiedName, (ns, ALLOC(SimpleName, (name)), false, *pos));
                    if (is_const)
                        addConstBinding(ns, name, type_name, is_static ? topRib->next : topRib);
                    Expr* assign = ALLOC(AssignExpr, (is_const ? OPR_init : OPR_assign, lhs, init));
                    if (firstName && *firstName == NULL)
                        *firstName = lhs;
                    if (inits == NULL)
                        inits = assign;
                    else
                        inits = ALLOC(BinaryExpr, (OPR_comma, inits, assign));
                }
                else if (firstName && *firstName == NULL) {
                    *firstName = ALLOC(QualifiedName, (ns, ALLOC(SimpleName, (name)), false, *pos));
                }

                if (!match(T_Comma))
                    break;
            }
            return inits ? inits : ALLOC(LiteralUndefined, (*pos));
        }
Type* ClassTypeExpression::type()
{
	return new ClassType( dynamic_cast<Class*> (typeExpression()->target()), false);
}
Type* ArrayTypeExpression::type()
{
	return new ArrayType(typeExpression()->type(), false);
}