Ejemplo n.º 1
0
    ArrayObject *DomainObject::getVariables (Atom a)
    {
        ArrayObject *result = toplevel()->arrayClass->newArray(0);

        TraitsBindingsp traits = getTraits(a)->getTraitsBindings();
        int i = 0;
        while ((i = traits->next(i)) != 0) {
            Namespace *ns = traits->nsAt(i);
            Stringp name = traits->keyAt(i);
            Binding b = traits->valueAt(i);

            if (core()->isVarBinding(b) && ns->getType() == Namespace::NS_Public) {
                Atom nameAtom = core()->internString(name)->atom();
                result->push(&nameAtom, 1);
            }
        }

        return result;
    }
Ejemplo n.º 2
0
IArray* TypeManager::getArrayOf( IType* elementType )
{
	if( !elementType )
		CORAL_THROW( IllegalArgumentException, "null element type" );

	const std::string& elementTypeName = elementType->getName();

	std::string arrayName;
	arrayName.reserve( elementTypeName.length() + 2 );
	arrayName.append( elementTypeName );
	arrayName.append( "[]" );

	Namespace* ns = static_cast<Namespace*>( elementType->getNamespace() );

	// try to locate an existing array of this type
	IType* existingArrayType = ns->getType( arrayName );
	if( existingArrayType )
	{
		assert( existingArrayType->getKind() == TK_ARRAY );
		return static_cast<IArray*>( existingArrayType );
	}

	// otherwise, try to create it
	TypeKind kind = elementType->getKind();
	if( kind == TK_ARRAY )
		CORAL_THROW( IllegalArgumentException, "arrays of arrays are illegal" );

	if( !isData( kind ) )
		CORAL_THROW( IllegalArgumentException, "arrays of " << kind << "s are illegal" );

	RefPtr<ArrayType> arrayType = new ArrayType;
	arrayType->setType( TK_ARRAY, elementType->getName() + "[]", ns );
	arrayType->setElementType( elementType );

	ns->addType( arrayType.get() );

	return arrayType.get();
}