void TypeManager::defineBuiltInTypes() { Namespace* rootNS = _rootNS.get(); // register all basic types in the root namespace: for( uint8 k = 0; k < TK_COUNT; ++k ) { TypeComponent* type = static_cast<TypeComponent*>( BASIC_TYPES[k].get() ); if( !type ) continue; type->setNamespace( rootNS ); rootNS->addType( type ); } // pre-load the 'co.IService' type and all its dependencies Namespace* coNS = static_cast<Namespace*>( rootNS->defineChildNamespace( "co" ) ); assert( coNS ); RefPtr<Interface> serviceType = new Interface; serviceType->setType( TK_INTERFACE, "IService", coNS ); coNS->addType( serviceType.get() ); loadTypeOrThrow( "co.IService" ); }
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(); }