コード例 #1
0
ファイル: Desc.cpp プロジェクト: EgoIncarnate/fe-devel
 static void parseHostStrings( JSON::Entity const &entity, HostStrings &result )
 {
   if ( entity.isString() )
   {
     HostSpec hostSpec;
     hostSpec.push_back( "*" );
     result.insert( HostStrings::value_type( entity.stringToStdString(), hostSpec ) );
   }
   else if ( entity.isObject() )
   {
     JSON::ObjectDecoder objectDecoder( entity );
     JSON::Entity keyString, valueEntity;
     while ( objectDecoder.getNext( keyString, valueEntity ) )
     {
       try
       {
         HostSpec hostSpec = parseHostSpec( valueEntity );
         result.insert( HostStrings::value_type( keyString.stringToStdString(), hostSpec ) );
       }
       catch ( Exception e )
       {
         objectDecoder.rethrow( e );
       }
     }
   }
   else throw Exception( "must be a string or an object" );
 }
コード例 #2
0
 void ResourceLoadNode::jsonExecCreate(
   JSON::Entity const &arg,
   RC::Handle<Context> const &context,
   JSON::ArrayEncoder &resultArrayEncoder
   )
 {
   arg.requireString();
   Create( arg.stringToStdString(), context );
 }
コード例 #3
0
 void ValueProducerWrapper::jsonExec(
   JSON::Entity const &cmd,
   JSON::Entity const &arg,
   JSON::ArrayEncoder &resultArrayEncoder
   )
 {
   if ( cmd.stringIs( "produce", 7 ) )
     jsonExecProduce( arg, resultArrayEncoder );
   else if ( cmd.stringIs( "produceAsync", 12 ) )
     jsonExecProduceAsync( arg, resultArrayEncoder );
   else if ( cmd.stringIs( "flush", 5 ) )
     jsonExecFlush( arg, resultArrayEncoder );
   else ProducerWrapper::jsonExec( cmd, arg, resultArrayEncoder );
 }
コード例 #4
0
ファイル: Desc.cpp プロジェクト: EgoIncarnate/fe-devel
 static void parseHostStringsVector( JSON::Entity const &entity, HostStringsVector &result )
 {
   if ( entity.isArray() )
   {
     JSON::ArrayDecoder arrayDecoder( entity );
     JSON::Entity elementEntity;
     while ( !arrayDecoder.getNext( elementEntity ) )
     {
       try
       {
         HostStrings hostStrings;
         parseHostStrings( elementEntity, hostStrings );
         result.push_back( hostStrings );
       }
       catch ( Exception e )
       {
         arrayDecoder.rethrow( e );
       }
     }
   }
   else
   {
     HostStrings hostStrings;
     parseHostStrings( entity, hostStrings );
     result.push_back( hostStrings );
   }
 }
コード例 #5
0
 void SlicedArrayImpl::decodeJSON( JSON::Entity const &entity, void *data ) const
 {
   entity.requireArray();
     
   bits_t *dstBits = reinterpret_cast<bits_t *>(data);
   if ( entity.value.array.size != dstBits->size )
     throw Exception( "JSON array size must equal sliced array size" );
     
   size_t membersFound = 0;
   JSON::ArrayDecoder arrayDecoder( entity );
   JSON::Entity elementEntity;
   while ( arrayDecoder.getNext( elementEntity ) )
   {
     FABRIC_ASSERT( membersFound < entity.value.array.size );
     try
     {
       void *memberData = (void*)m_variableArrayImpl->getImmutableMemberData_NoCheck( &dstBits->rcva->varArray, dstBits->offset + membersFound );
       m_memberImpl->decodeJSON( elementEntity, memberData );
     }
     catch ( Exception e )
     {
       throw _(membersFound) + ": " + e;
     }
     ++membersFound;
   }
   
   FABRIC_ASSERT( membersFound == entity.value.array.size );
 }
コード例 #6
0
ファイル: Desc.cpp プロジェクト: EgoIncarnate/fe-devel
 void parseMethods( JSON::Entity const &methodsArray, std::vector<std::string> &methods )
 {
   JSON::ArrayDecoder methodArrayDecoder( methodsArray );
   JSON::Entity methodEntity;
   while ( methodArrayDecoder.getNext( methodEntity ) )
   {
     try
     {
       methodEntity.requireString();
       methods.push_back( methodEntity.stringToStdString() );
     }
     catch ( Exception e )
     {
       methodArrayDecoder.rethrow( e );
     }
   }
 }
コード例 #7
0
 void ProducerWrapper::jsonExec(
   JSON::Entity const &cmd,
   JSON::Entity const &arg,
   JSON::ArrayEncoder &resultArrayEncoder
   )
 {
   if ( cmd.stringIs( "toJSON", 6 ) )
     jsonExecGetJSONDesc( arg, resultArrayEncoder );
   else GC::Object::jsonExec( cmd, arg, resultArrayEncoder );
 }
コード例 #8
0
 void ValueProducerWrapper::jsonExecProduceAsync( JSON::Entity const &arg, JSON::ArrayEncoder &resultArrayEncoder )
 {
   arg.requireInteger();
   JSONProduceAsyncUserdata *jsonProduceAsyncUserdata = new JSONProduceAsyncUserdata( this, arg.integerValue() );
   getUnwrapped()->createComputeState()->produceJSONAsync(
     jsonProduceAsyncUserdata->notifyJSONArgObjectEncoder,
     &ValueProducerWrapper::JSONExecProduceAsyncFinishedCallback,
     jsonProduceAsyncUserdata
     );
 }
コード例 #9
0
ファイル: ConstArray.cpp プロジェクト: nikelin/PublicStable
ConstArray::ConstArray(
    RC::ConstHandle<RT::Manager> const &rtManager,
    RC::ConstHandle<RT::Desc> const &elementDesc,
    JSON::Entity const &entity
)
{
    entity.requireArray();
    m_fixedArrayDesc = rtManager->getFixedArrayOf( elementDesc, entity.value.array.size );
    m_data.resize( m_fixedArrayDesc->getAllocSize(), 0 );
    m_fixedArrayDesc->decodeJSON( entity, &m_data[0] );
}
コード例 #10
0
ファイル: Desc.cpp プロジェクト: EgoIncarnate/fe-devel
 static HostSpec parseHostSpec( JSON::Entity const &entity )
 {
   HostSpec result;
   if ( entity.isString() )
     result.push_back( entity.stringToStdString() );
   else if ( entity.isArray() )
   {
     JSON::ArrayDecoder arrayDecoder( entity );
     JSON::Entity elementEntity;
     while ( arrayDecoder.getNext( elementEntity ) )
     {
       try
       {
         elementEntity.requireString();
         result.push_back( elementEntity.stringToStdString() );
       }
       catch ( Exception e )
       {
         arrayDecoder.rethrow( e );
       }
     }
   }
   else
     throw Exception( "must be a string or an array" );
   return result;
 }
コード例 #11
0
ファイル: DictImpl.cpp プロジェクト: EgoIncarnate/fe-devel
    void DictImpl::decodeJSON( JSON::Entity const &entity, void *data ) const
    {
      entity.requireObject();

      RC::ConstHandle<StringImpl> keyImplAsStringImpl;
      if ( isString( m_keyImpl->getType() ) )
        keyImplAsStringImpl = RC::ConstHandle<StringImpl>::StaticCast( m_keyImpl );
      
      disposeData( data );
      memset( data, 0, sizeof(bits_t *) );
        
      void *keyData = alloca( m_keySize );
      m_keyImpl->initializeData( m_keyImpl->getDefaultData(), keyData );
      JSON::ObjectDecoder jsonObjectDecoder( entity );
      JSON::Entity keyString, valueEntity;
      while ( jsonObjectDecoder.getNext( keyString, valueEntity ) )
      {
        if ( keyImplAsStringImpl )
        {
          keyString.stringGetData( StringImpl::GetMutableValueData( keyData, keyString.stringLength() ) );
        }
        else
        {
          char *mutableData;
          char const *data;
          if ( keyString.stringIsShort() )
            data = keyString.stringShortData();
          else
          {
            mutableData = reinterpret_cast<char *>( alloca( keyString.stringLength() ) );
            keyString.stringGetData( mutableData );
            data = mutableData;
          }
          
          JSON::Decoder jsonDecoder( data, keyString.value.string.length );
          JSON::Entity jsonDecodedEntity;
          if ( !jsonDecoder.getNext( jsonDecodedEntity ) )
            throw Exception( "invalid JSON key" );
          m_keyImpl->decodeJSON( jsonDecodedEntity, keyData );
          if ( jsonDecoder.getNext( jsonDecodedEntity ) )
            throw Exception( "invalid JSON key" );
        }
        
        void *valueData = getMutable( data, keyData );
        m_valueImpl->decodeJSON( valueEntity, valueData );
      }
      m_keyImpl->disposeData( keyData );
    }
コード例 #12
0
ファイル: Inst.cpp プロジェクト: EgoIncarnate/fe-devel
    Inst::Inst(
      RC::ConstHandle<IO::Dir> const &extensionDir,
      std::string const &extensionName,
      std::string const &jsonDesc,
      std::vector<std::string> const &pluginDirs,
      RC::Handle<CG::Manager> const &cgManager,
      EDK::Callbacks const &callbacks,
      std::map< std::string, void (*)( void * ) > &implNameToDestructorMap
      )
      : m_name( extensionName )
      , m_jsonDesc( jsonDesc )
    {
      try
      {
        JSON::Decoder jsonDecode( jsonDesc.data(), jsonDesc.length() );
        JSON::Entity jsonEntity;
        if ( !jsonDecode.getNext( jsonEntity ) )
          throw Exception( "missing JSON entity" );
        jsonEntity.requireObject();
        m_desc = parseDesc( jsonEntity );
        if ( jsonDecode.getNext( jsonEntity ) )
          throw Exception( "extra JSON entity" );
      }
      catch ( Exception e )
      {
        throw "JSON description: " + e;
      }
      
      /*
      m_fabricLIBObject = LIB::NakedObject::Create();
      m_fabricLIBObject->set( "hostTriple", LIB::ReferencedString::Create( Util::getHostTriple() ) );
      m_fabricLIBObject->set( "DependencyGraph", LIBDG::Namespace::Create( dgContext ) );
      */
      std::vector< std::string > libs;
      m_desc.libs.appendMatching( Util::getHostTriple(), libs );
      std::string libSuffix = "-" + std::string(buildOS) + "-" + std::string(buildArch);
      
      for ( size_t i=0; i<libs.size(); ++i )
      {
        std::string resolvedName;
        SOLibHandle soLibHandle = SOLibOpen( libs[i]+libSuffix, resolvedName, false, pluginDirs );
        m_resolvedNameToSOLibHandleMap.insert( ResolvedNameToSOLibHandleMap::value_type( resolvedName, soLibHandle ) );
        m_orderedSOLibHandles.push_back( soLibHandle );
      }

      if ( !m_orderedSOLibHandles.empty() )
      {
        void *resolvedFabricEDKInitFunction = 0;
        for ( size_t i=0; i<m_orderedSOLibHandles.size(); ++i )
        {
          resolvedFabricEDKInitFunction = SOLibResolve( m_orderedSOLibHandles[i], "FabricEDKInit" );
          if ( resolvedFabricEDKInitFunction )
            break;
        }
        if ( !resolvedFabricEDKInitFunction )
          throw Exception( "error: extension doesn't implement function FabricEDKInit through macro IMPLEMENT_FABRIC_EDK_ENTRIES" );

        ( *( FabricEDKInitPtr )resolvedFabricEDKInitFunction )( callbacks );
      }
      
      for ( size_t i=0; i<m_orderedSOLibHandles.size(); ++i )
      {
        /*
        OnLoadFn onLoadFn = (OnLoadFn)SOLibResolve( m_orderedSOLibHandles[i], "FabricOnLoad" );
        if ( onLoadFn )
          onLoadFn( SDK::Value::Bind( m_fabricLIBObject ) );
        */
      }
      
      /*
      for ( size_t i=0; i<m_desc.interface.methods.size(); ++i )
      {
        std::string const &methodName = m_desc.interface.methods[i];
        Method method = 0;
        for ( size_t j=0; j<m_orderedSOLibHandles.size(); ++j )
        {
          SOLibHandle soLibHandle = m_orderedSOLibHandles[j];
          method = (Method)SOLibResolve( soLibHandle, methodName );
          if ( method )
            break;
        }
        if ( !method )
          throw Exception( "method "+_(methodName)+" not found" );
        m_methodMap.insert( MethodMap::value_type( methodName, method ) );
      }
      */
      
      
      std::vector<std::string> codeFiles;
      m_desc.code.appendMatching( Util::getHostTriple(), codeFiles );
      std::string filename;
      m_code = "";
      for ( std::vector<std::string>::const_iterator it=codeFiles.begin(); it!=codeFiles.end(); ++it )
      {
        std::string const &codeEntry = *it;
        
        if ( filename.empty() )
          filename = codeEntry;
          
        std::string code;
        try
        {
          code = extensionDir->getFileContents( codeEntry );
        }
        catch ( Exception e )
        {
          throw _(codeEntry) + ": " + e;
        }
        m_code += code + "\n";
      }
      
      RC::ConstHandle<KL::Source> source = KL::StringSource::Create( filename, m_code );
      RC::Handle<KL::Scanner> scanner = KL::Scanner::Create( source );
      m_ast = KL::Parse( scanner, m_diagnostics );
      if ( !m_diagnostics.containsError() )
        m_ast->registerTypes( cgManager, m_diagnostics );
      for ( CG::Diagnostics::const_iterator it=m_diagnostics.begin(); it!=m_diagnostics.end(); ++it )
      {
        CG::Location const &location = it->first;
        CG::Diagnostic const &diagnostic = it->second;
        FABRIC_LOG( "[%s] %s:%u:%u: %s: %s", extensionName.c_str(), location.getFilename()->c_str(), (unsigned)location.getLine(), (unsigned)location.getColumn(), diagnostic.getLevelDesc(), diagnostic.getDesc().c_str() );
      }
      if ( m_diagnostics.containsError() )
        throw Exception( "KL compile failed" );
      
      std::vector< RC::ConstHandle<AST::FunctionBase> > functionBases;
      m_ast->collectFunctionBases( functionBases );
      for ( std::vector< RC::ConstHandle<AST::FunctionBase> >::const_iterator it=functionBases.begin(); it!=functionBases.end(); ++it )
      {
        RC::ConstHandle<AST::FunctionBase> const &functionBase = *it;
        
        if ( !functionBase->getBody() )
        {
          std::string symbolName = functionBase->getSymbolName( cgManager );
          void *resolvedFunction = 0;
          for ( size_t i=0; i<m_orderedSOLibHandles.size(); ++i )
          {
            resolvedFunction = SOLibResolve( m_orderedSOLibHandles[i], symbolName );
            if ( resolvedFunction )
              break;
          }
          if ( !resolvedFunction )
            throw Exception( "error: symbol " + _(symbolName) + ", prototyped in KL, not found in native code" );
          m_externalFunctionMap.insert( ExternalFunctionMap::value_type( symbolName, resolvedFunction ) );
          
          if ( functionBase->isDestructor() )
          {
            RC::ConstHandle<AST::Destructor> destructor = RC::ConstHandle<AST::Destructor>::StaticCast( functionBase );
            std::string thisTypeName = destructor->getThisTypeName();
            implNameToDestructorMap[thisTypeName] = (void (*)( void * )) resolvedFunction;
          }
        }
      }

      m_jsConstants = m_desc.jsConstants.concatMatching( Util::getHostTriple() );
    }
コード例 #13
0
ファイル: OpaqueImpl.cpp プロジェクト: EgoIncarnate/fe-devel
void OpaqueImpl::decodeJSON( JSON::Entity const &entity, void *dst ) const
{
    entity.requireNullOrBoolean();
}
コード例 #14
0
ファイル: StringImpl.cpp プロジェクト: EgoIncarnate/fe-devel
 void StringImpl::decodeJSON( JSON::Entity const &entity, void *dst ) const
 {
   entity.requireString();
   entity.stringGetData( GetMutableValueData( dst, entity.stringLength() ) );
 }
コード例 #15
0
ファイル: OpaqueImpl.cpp プロジェクト: nikelin/PublicStable
 void OpaqueImpl::decodeJSON( JSON::Entity const &entity, void *dst ) const
 {
   entity.requireNull();
   memset( dst, 0, getAllocSize() );
 }