void desugar(AST *&ast_, unsigned obj_level) { if (auto *ast = dynamic_cast<Apply*>(ast_)) { desugar(ast->target, obj_level); for (Apply::Arg &arg : ast->args) desugar(arg.expr, obj_level); } else if (auto *ast = dynamic_cast<ApplyBrace*>(ast_)) { desugar(ast->left, obj_level); desugar(ast->right, obj_level); ast_ = alloc->make<Binary>(ast->location, ast->openFodder, ast->left, EF, BOP_PLUS, ast->right); } else if (auto *ast = dynamic_cast<Array*>(ast_)) { for (auto &el : ast->elements) desugar(el.expr, obj_level); } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) { for (ComprehensionSpec &spec : ast->specs) desugar(spec.expr, obj_level); desugar(ast->body, obj_level + 1); int n = ast->specs.size(); AST *zero = make<LiteralNumber>(E, EF, "0.0"); AST *one = make<LiteralNumber>(E, EF, "1.0"); auto *_r = id(U"$r"); auto *_l = id(U"$l"); std::vector<const Identifier*> _i(n); for (int i = 0; i < n ; ++i) { StringStream ss; ss << U"$i_" << i; _i[i] = id(ss.str()); } std::vector<const Identifier*> _aux(n); for (int i = 0; i < n ; ++i) { StringStream ss; ss << U"$aux_" << i; _aux[i] = id(ss.str()); } // Build it from the inside out. We keep wrapping 'in' with more ASTs. assert(ast->specs[0].kind == ComprehensionSpec::FOR); int last_for = n - 1; while (ast->specs[last_for].kind != ComprehensionSpec::FOR) last_for--; // $aux_{last_for}($i_{last_for} + 1, $r + [body]) AST *in = make<Apply>( ast->body->location, EF, var(_aux[last_for]), EF, Apply::Args { { make<Binary>(E, EF, var(_i[last_for]), EF, BOP_PLUS, one), EF}, { make<Binary>(E, EF, var(_r), EF, BOP_PLUS, singleton(ast->body)), EF} }, false, // trailingComma EF, EF, true // tailstrict ); for (int i = n - 1; i >= 0 ; --i) { const ComprehensionSpec &spec = ast->specs[i]; AST *out; if (i > 0) { int prev_for = i - 1; while (ast->specs[prev_for].kind != ComprehensionSpec::FOR) prev_for--; // aux_{prev_for}($i_{prev_for} + 1, $r) out = make<Apply>( // False branch. E, EF, var(_aux[prev_for]), EF, Apply::Args { { make<Binary>(E, EF, var(_i[prev_for]), EF, BOP_PLUS, one), EF, }, { var(_r), EF, } }, false, // trailingComma EF, EF, true // tailstrict ); } else { out = var(_r); } switch (spec.kind) { case ComprehensionSpec::IF: { /* if [[[...cond...]]] then [[[...in...]]] else [[[...out...]]] */ in = make<Conditional>( ast->location, EF, spec.expr, EF, in, // True branch. EF, out); // False branch. } break; case ComprehensionSpec::FOR: { /* local $l = [[[...array...]]] aux_{i}(i_{i}, r) = if i_{i} >= std.length($l) then [[[...out...]]] else local [[[...var...]]] = $l[i_{i}]; [[[...in...]]];` if std.type($l) != "array" then error "In comprehension, can only iterate over array.." else aux_{i}(0, r) tailstrict; */ in = make<Local>( ast->location, EF, Local::Binds { bind(_l, spec.expr), // Need to check expr is an array bind(_aux[i], make<Function>( ast->location, EF, EF, std::vector<Param>{Param(EF, _i[i], EF), Param(EF, _r, EF)}, false, // trailingComma EF, make<Conditional>( ast->location, EF, make<Binary>( E, EF, var(_i[i]), EF, BOP_GREATER_EQ, length(var(_l))), EF, out, EF, make<Local>( ast->location, EF, singleBind( spec.var, make<Index>(E, EF, var(_l), EF, false, var(_i[i]), EF, nullptr, EF, nullptr, EF) ), in) ) ))}, make<Conditional>( ast->location, EF, equals(ast->location, type(var(_l)), str(U"array")), EF, make<Apply>( E, EF, var(_aux[i]), EF, Apply::Args { {zero, EF}, { i == 0 ? make<Array>(E, EF, Array::Elements{}, false, EF) : static_cast<AST*>(var(_r)), EF, } }, false, // trailingComma EF, EF, true), // tailstrict EF, error(ast->location, U"In comprehension, can only iterate over array."))); } break; } } ast_ = in; } else if (auto *ast = dynamic_cast<Assert*>(ast_)) { desugar(ast->cond, obj_level); if (ast->message == nullptr) { ast->message = str(U"Assertion failed."); } desugar(ast->message, obj_level); desugar(ast->rest, obj_level); // if cond then rest else error msg AST *branch_false = alloc->make<Error>(ast->location, EF, ast->message); ast_ = alloc->make<Conditional>(ast->location, ast->openFodder, ast->cond, EF, ast->rest, EF, branch_false); } else if (auto *ast = dynamic_cast<Binary*>(ast_)) { desugar(ast->left, obj_level); desugar(ast->right, obj_level); bool invert = false; switch (ast->op) { case BOP_PERCENT: { AST *f_mod = alloc->make<Index>(E, EF, std(), EF, false, str(U"mod"), EF, nullptr, EF, nullptr, EF); Apply::Args args = {{ast->left, EF}, {ast->right, EF}}; ast_ = alloc->make<Apply>(ast->location, ast->openFodder, f_mod, EF, args, false, EF, EF, false); } break; case BOP_MANIFEST_UNEQUAL: invert = true; case BOP_MANIFEST_EQUAL: { ast_ = equals(ast->location, ast->left, ast->right); if (invert) ast_ = alloc->make<Unary>(ast->location, ast->openFodder, UOP_NOT, ast_); } break; default:; // Otherwise don't change it. } } else if (dynamic_cast<const BuiltinFunction*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) { desugar(ast->cond, obj_level); desugar(ast->branchTrue, obj_level); if (ast->branchFalse == nullptr) ast->branchFalse = alloc->make<LiteralNull>(LocationRange(), EF); desugar(ast->branchFalse, obj_level); } else if (auto *ast = dynamic_cast<Dollar*>(ast_)) { if (obj_level == 0) { throw StaticError(ast->location, "No top-level object found."); } ast_ = alloc->make<Var>(ast->location, EF, alloc->makeIdentifier(U"$")); } else if (auto *ast = dynamic_cast<Error*>(ast_)) { desugar(ast->expr, obj_level); } else if (auto *ast = dynamic_cast<Function*>(ast_)) { desugar(ast->body, obj_level); } else if (dynamic_cast<const Import*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const Importstr*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<Index*>(ast_)) { desugar(ast->target, obj_level); if (ast->isSlice) { if (ast->index == nullptr) ast->index = make<LiteralNull>(ast->location, EF); desugar(ast->index, obj_level); if (ast->end == nullptr) ast->end = make<LiteralNull>(ast->location, EF); desugar(ast->end, obj_level); if (ast->step == nullptr) ast->step = make<LiteralNull>(ast->location, EF); desugar(ast->step, obj_level); ast_ = make<Apply>( ast->location, EF, make<Index>( E, EF, std(), EF, false, str(U"slice"), EF, nullptr, EF, nullptr, EF), EF, std::vector<Apply::Arg>{ {ast->target, EF}, {ast->index, EF}, {ast->end, EF}, {ast->step, EF}, }, false, // trailing comma EF, EF, false // tailstrict ); } else { if (ast->id != nullptr) { assert(ast->index == nullptr); ast->index = str(ast->id->name); ast->id = nullptr; } desugar(ast->index, obj_level); } } else if (auto *ast = dynamic_cast<Local*>(ast_)) { for (auto &bind: ast->binds) desugar(bind.body, obj_level); desugar(ast->body, obj_level); for (auto &bind: ast->binds) { if (bind.functionSugar) { bind.body = alloc->make<Function>( ast->location, ast->openFodder, bind.parenLeftFodder, bind.params, false, bind.parenRightFodder, bind.body); bind.functionSugar = false; bind.params.clear(); } } } else if (dynamic_cast<const LiteralBoolean*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const LiteralNumber*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<LiteralString*>(ast_)) { if (ast->tokenKind != LiteralString::BLOCK) { ast->value = jsonnet_string_unescape(ast->location, ast->value); } ast->tokenKind = LiteralString::DOUBLE; ast->blockIndent.clear(); } else if (dynamic_cast<const LiteralNull*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<DesugaredObject*>(ast_)) { for (auto &field : ast->fields) { desugar(field.name, obj_level); desugar(field.body, obj_level + 1); } for (AST *assert : ast->asserts) { desugar(assert, obj_level + 1); } } else if (auto *ast = dynamic_cast<Object*>(ast_)) { // Hidden variable to allow outer/top binding. if (obj_level == 0) { const Identifier *hidden_var = alloc->makeIdentifier(U"$"); auto *body = alloc->make<Self>(E, EF); ast->fields.push_back(ObjectField::Local(EF, EF, hidden_var, EF, body, EF)); } desugarFields(ast, ast->fields, obj_level); DesugaredObject::Fields new_fields; ASTs new_asserts; for (const ObjectField &field : ast->fields) { if (field.kind == ObjectField::ASSERT) { new_asserts.push_back(field.expr2); } else if (field.kind == ObjectField::FIELD_EXPR) { new_fields.emplace_back(field.hide, field.expr1, field.expr2); } else { std::cerr << "INTERNAL ERROR: field should have been desugared: " << field.kind << std::endl; } } ast_ = alloc->make<DesugaredObject>(ast->location, new_asserts, new_fields); } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) { // Hidden variable to allow outer/top binding. if (obj_level == 0) { const Identifier *hidden_var = alloc->makeIdentifier(U"$"); auto *body = alloc->make<Self>(E, EF); ast->fields.push_back(ObjectField::Local(EF, EF, hidden_var, EF, body, EF)); } desugarFields(ast, ast->fields, obj_level); for (ComprehensionSpec &spec : ast->specs) desugar(spec.expr, obj_level); AST *field = ast->fields.front().expr1; AST *value = ast->fields.front().expr2; /* { [arr[0]]: local x = arr[1], y = arr[2], z = arr[3]; val_expr for arr in [ [key_expr, x, y, z] for ... ] } */ auto *_arr = id(U"$arr"); AST *zero = make<LiteralNumber>(E, EF, "0.0"); int counter = 1; Local::Binds binds; Array::Elements arr_e {Array::Element(field, EF)}; for (ComprehensionSpec &spec : ast->specs) { if (spec.kind == ComprehensionSpec::FOR) { std::stringstream num; num << counter++; binds.push_back(bind( spec.var, make<Index>(E, EF, var(_arr), EF, false, make<LiteralNumber>(E, EF, num.str()), EF, nullptr, EF, nullptr, EF))); arr_e.emplace_back(var(spec.var), EF); } } AST *arr = make<ArrayComprehension>( ast->location, EF, make<Array>(ast->location, EF, arr_e, false, EF), EF, false, ast->specs, EF); desugar(arr, obj_level); ast_ = make<ObjectComprehensionSimple>( ast->location, make<Index>(E, EF, var(_arr), EF, false, zero, EF, nullptr, EF, nullptr, EF), make<Local>( ast->location, EF, binds, value), _arr, arr); } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { desugar(ast->field, obj_level); desugar(ast->value, obj_level + 1); desugar(ast->array, obj_level); } else if (auto *ast = dynamic_cast<Parens*>(ast_)) { // Strip parens. desugar(ast->expr, obj_level); ast_ = ast->expr; } else if (dynamic_cast<const Self*>(ast_)) { // Nothing to do. } else if (auto * ast = dynamic_cast<SuperIndex*>(ast_)) { if (ast->id != nullptr) { assert(ast->index == nullptr); ast->index = str(ast->id->name); ast->id = nullptr; } desugar(ast->index, obj_level); } else if (auto *ast = dynamic_cast<Unary*>(ast_)) { desugar(ast->expr, obj_level); } else if (dynamic_cast<const Var*>(ast_)) { // Nothing to do. } else { std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; std::abort(); } }
void GLFrameBufferObject::initialise() { // Release depth and stencil, if they were bound mManager->releaseRenderBuffer(mDepth); mManager->releaseRenderBuffer(mStencil); mManager->releaseRenderBuffer(mMultisampleColourBuffer); // First buffer must be bound if(!mColour[0].buffer) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attachment 0 must have surface attached", "GLFrameBufferObject::initialise"); } // If we're doing multisampling, then we need another FBO which contains a // renderbuffer which is set up to multisample, and we'll blit it to the final // FBO afterwards to perform the multisample resolve. In that case, the // mMultisampleFB is bound during rendering and is the one with a depth/stencil // Store basic stats uint32 width = mColour[0].buffer->getWidth(); uint32 height = mColour[0].buffer->getHeight(); GLuint format = mColour[0].buffer->getGLFormat(); ushort maxSupportedMRTs = Root::getSingleton().getRenderSystem()->getCapabilities()->getNumMultiRenderTargets(); // Bind simple buffer to add colour attachments glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFB); // Bind all attachment points to frame buffer for(unsigned int x=0; x<maxSupportedMRTs; ++x) { if(mColour[x].buffer) { if(mColour[x].buffer->getWidth() != width || mColour[x].buffer->getHeight() != height) { StringStream ss; ss << "Attachment " << x << " has incompatible size "; ss << mColour[x].buffer->getWidth() << "x" << mColour[x].buffer->getHeight(); ss << ". It must be of the same as the size of surface 0, "; ss << width << "x" << height; ss << "."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLFrameBufferObject::initialise"); } if(mColour[x].buffer->getGLFormat() != format) { StringStream ss; ss << "Attachment " << x << " has incompatible format."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLFrameBufferObject::initialise"); } mColour[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT+x, mColour[x].zoffset); } else { // Detach glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+x, GL_RENDERBUFFER_EXT, 0); } } // Now deal with depth / stencil if (mMultisampleFB) { // Bind multisample buffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mMultisampleFB); // Create AA render buffer (colour) // note, this can be shared too because we blit it to the final FBO // right after the render is finished mMultisampleColourBuffer = mManager->requestRenderBuffer(format, width, height, mNumSamples); // Attach it, because we won't be attaching below and non-multisample has // actually been attached to other FBO mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT, mMultisampleColourBuffer.zoffset); // depth & stencil will be dealt with below } // Depth buffer is not handled here anymore. // See GLFrameBufferObject::attachDepthBuffer() & RenderSystem::setDepthBufferFor() // Do glDrawBuffer calls GLenum bufs[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; GLsizei n=0; for(unsigned int x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x) { // Fill attached colour buffers if(mColour[x].buffer) { bufs[x] = GL_COLOR_ATTACHMENT0_EXT + x; // Keep highest used buffer + 1 n = x+1; } else { bufs[x] = GL_NONE; } } if(glDrawBuffers) { // Drawbuffer extension supported, use it glDrawBuffers(n, bufs); } else { // In this case, the capabilities will not show more than 1 simultaneaous render target. glDrawBuffer(bufs[0]); } if (mMultisampleFB) { // we need a read buffer because we'll be blitting to mFB glReadBuffer(bufs[0]); } else { // No read buffer, by default, if we want to read anyway we must not forget to set this. glReadBuffer(GL_NONE); } // Check status GLuint status; status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); // Bind main buffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); switch(status) { case GL_FRAMEBUFFER_COMPLETE_EXT: // All is good break; case GL_FRAMEBUFFER_UNSUPPORTED_EXT: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "All framebuffer formats with this texture internal format unsupported", "GLFrameBufferObject::initialise"); default: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Framebuffer incomplete or other FBO status error", "GLFrameBufferObject::initialise"); } }
void GLESFrameBufferObject::initialise() { // Release depth and stencil, if they were bound mManager->releaseRenderBuffer(mDepth); mManager->releaseRenderBuffer(mStencil); mManager->releaseRenderBuffer(mMultisampleColourBuffer); /// First buffer must be bound if(!mColour[0].buffer) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attachment 0 must have surface attached", "GLESFrameBufferObject::initialise"); } // If we're doing multisampling, then we need another FBO which contains a // renderbuffer which is set up to multisample, and we'll blit it to the final // FBO afterwards to perform the multisample resolve. In that case, the // mMultisampleFB is bound during rendering and is the one with a depth/stencil /// Store basic stats size_t width = mColour[0].buffer->getWidth(); size_t height = mColour[0].buffer->getHeight(); GLuint format = mColour[0].buffer->getGLFormat(); PixelFormat ogreFormat = mColour[0].buffer->getFormat(); // Bind simple buffer to add colour attachments glBindFramebufferOES(GL_FRAMEBUFFER_OES, mFB); GL_CHECK_ERROR; /// Bind all attachment points to frame buffer for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x) { if(mColour[x].buffer) { if(mColour[x].buffer->getWidth() != width || mColour[x].buffer->getHeight() != height) { StringStream ss; ss << "Attachment " << x << " has incompatible size "; ss << mColour[x].buffer->getWidth() << "x" << mColour[x].buffer->getHeight(); ss << ". It must be of the same as the size of surface 0, "; ss << width << "x" << height; ss << "."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLESFrameBufferObject::initialise"); } if(mColour[x].buffer->getGLFormat() != format) { StringStream ss; ss << "Attachment " << x << " has incompatible format."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLESFrameBufferObject::initialise"); } mColour[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_OES+x, mColour[x].zoffset); } else { // Detach glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES+x, GL_RENDERBUFFER_OES, 0); GL_CHECK_ERROR; } } // Now deal with depth / stencil if (mMultisampleFB) { // Bind multisample buffer glBindFramebufferOES(GL_FRAMEBUFFER_OES, mMultisampleFB); GL_CHECK_ERROR; // Create AA render buffer (colour) // note, this can be shared too because we blit it to the final FBO // right after the render is finished mMultisampleColourBuffer = mManager->requestRenderBuffer(format, width, height, mNumSamples); // Attach it, because we won't be attaching below and non-multisample has // actually been attached to other FBO mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_OES, mMultisampleColourBuffer.zoffset); // depth & stencil will be dealt with below } /// Find suitable depth and stencil format that is compatible with colour format GLenum depthFormat, stencilFormat; mManager->getBestDepthStencil(ogreFormat, &depthFormat, &stencilFormat); /// Request surfaces mDepth = mManager->requestRenderBuffer(depthFormat, width, height, mNumSamples); if (depthFormat == GL_DEPTH24_STENCIL8_OES) { // bind same buffer to depth and stencil attachments mManager->requestRenderBuffer(mDepth); mStencil = mDepth; } else { // separate stencil mStencil = mManager->requestRenderBuffer(stencilFormat, width, height, mNumSamples); } /// Attach/detach surfaces if(mDepth.buffer) { mDepth.buffer->bindToFramebuffer(GL_DEPTH_ATTACHMENT_OES, mDepth.zoffset); } else { glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, 0); GL_CHECK_ERROR; } if(mStencil.buffer) { mStencil.buffer->bindToFramebuffer(GL_STENCIL_ATTACHMENT_OES, mStencil.zoffset); } else { glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, 0); GL_CHECK_ERROR; } /// Do glDrawBuffer calls GLenum bufs[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; GLsizei n=0; for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x) { // Fill attached colour buffers if(mColour[x].buffer) { bufs[x] = GL_COLOR_ATTACHMENT0_OES + x; // Keep highest used buffer + 1 n = x+1; } else { bufs[x] = GL_NONE; } } /// Check status GLuint status; status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); GL_CHECK_ERROR; /// Bind main buffer #if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE // The screen buffer is 1 on iPhone glBindFramebufferOES(GL_FRAMEBUFFER_OES, 1); #else glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); #endif GL_CHECK_ERROR; switch(status) { case GL_FRAMEBUFFER_COMPLETE_OES: // All is good break; case GL_FRAMEBUFFER_UNSUPPORTED_OES: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "All framebuffer formats with this texture internal format unsupported", "GLESFrameBufferObject::initialise"); default: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Framebuffer incomplete or other FBO status error", "GLESFrameBufferObject::initialise"); } }
void GLES2FrameBufferObject::initialise() { GLES2RenderSystem* rs = getGLES2RenderSystem(); assert(mContext == rs->_getCurrentContext()); // Release depth and stencil, if they were bound mManager->releaseRenderBuffer(mDepth); mManager->releaseRenderBuffer(mStencil); mManager->releaseRenderBuffer(mMultisampleColourBuffer); // First buffer must be bound if(!mColour[0].buffer) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attachment 0 must have surface attached", "GLES2FrameBufferObject::initialise"); } // If we're doing multisampling, then we need another FBO which contains a // renderbuffer which is set up to multisample, and we'll blit it to the final // FBO afterwards to perform the multisample resolve. In that case, the // mMultisampleFB is bound during rendering and is the one with a depth/stencil // Store basic stats uint32 width = mColour[0].buffer->getWidth(); uint32 height = mColour[0].buffer->getHeight(); GLuint format = mColour[0].buffer->getGLFormat(); ushort maxSupportedMRTs = rs->getCapabilities()->getNumMultiRenderTargets(); // Bind simple buffer to add colour attachments OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mFB)); bool isDepth = PixelUtil::isDepth(getFormat()); // Bind all attachment points to frame buffer for(unsigned int x = 0; x < maxSupportedMRTs; ++x) { if(mColour[x].buffer) { if(mColour[x].buffer->getWidth() != width || mColour[x].buffer->getHeight() != height) { StringStream ss; ss << "Attachment " << x << " has incompatible size "; ss << mColour[x].buffer->getWidth() << "x" << mColour[x].buffer->getHeight(); ss << ". It must be of the same as the size of surface 0, "; ss << width << "x" << height; ss << "."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLES2FrameBufferObject::initialise"); } if(mColour[x].buffer->getGLFormat() != format) { StringStream ss; ss << "Attachment " << x << " has incompatible format."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLES2FrameBufferObject::initialise"); } mColour[x].buffer->bindToFramebuffer( isDepth ? GL_DEPTH_ATTACHMENT : (GL_COLOR_ATTACHMENT0 + x), mColour[x].zoffset); } else { // Detach OGRE_CHECK_GL_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, static_cast<GLenum>(GL_COLOR_ATTACHMENT0+x), GL_RENDERBUFFER, 0)); } } // Now deal with depth / stencil if (mMultisampleFB) { // Bind multisample buffer OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mMultisampleFB)); // Create AA render buffer (colour) // note, this can be shared too because we blit it to the final FBO // right after the render is finished mMultisampleColourBuffer = mManager->requestRenderBuffer(format, width, height, mNumSamples); // Attach it, because we won't be attaching below and non-multisample has // actually been attached to other FBO mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0, mMultisampleColourBuffer.zoffset); // depth & stencil will be dealt with below } // Depth buffer is not handled here anymore. // See GLES2FrameBufferObject::attachDepthBuffer() & RenderSystem::setDepthBufferFor() if(rs->hasMinGLVersion(3, 0) && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN) // ED on Emscripten { GLenum bufs[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; GLsizei n=0; for(unsigned int x=0; x<maxSupportedMRTs; ++x) { // Fill attached colour buffers if(mColour[x].buffer) { bufs[x] = isDepth ? GL_DEPTH_ATTACHMENT : (GL_COLOR_ATTACHMENT0 + x); // Keep highest used buffer + 1 n = x+1; } else { bufs[x] = GL_NONE; } } // Drawbuffer extension supported, use it if(!isDepth) OGRE_CHECK_GL_ERROR(glDrawBuffers(n, bufs)); if (mMultisampleFB) { // we need a read buffer because we'll be blitting to mFB OGRE_CHECK_GL_ERROR(glReadBuffer(bufs[0])); } else { // No read buffer, by default, if we want to read anyway we must not forget to set this. OGRE_CHECK_GL_ERROR(glReadBuffer(GL_NONE)); } } // Check status GLuint status; OGRE_CHECK_GL_ERROR(status = glCheckFramebufferStatus(GL_FRAMEBUFFER)); // Bind main buffer #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS // The screen buffer is 1 on iOS OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, 1)); #else OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, 0)); #endif switch(status) { case GL_FRAMEBUFFER_COMPLETE: // All is good break; case GL_FRAMEBUFFER_UNSUPPORTED: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "All framebuffer formats with this texture internal format unsupported", "GLES2FrameBufferObject::initialise"); default: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Framebuffer incomplete or other FBO status error", "GLES2FrameBufferObject::initialise"); } }
void Widget::ProtoDeSerializeStateGroupBindings(const XML::Node& SelfRoot) { this->StateGroupBindings.clear(); XML::Attribute CurrAttrib; XML::Node BindingsNode = SelfRoot.GetChild( "StateGroupBindings" ); if( !BindingsNode.Empty() ) { if( BindingsNode.GetAttribute("Version").AsInt() == 1 ) { for( XML::NodeIterator BindingNodeIt = BindingsNode.begin() ; BindingNodeIt != BindingsNode.end() ; ++BindingNodeIt ) { if( (*BindingNodeIt).GetAttribute("Version").AsInt() == 1 ) { UInt32 StateID = 0; CurrAttrib = (*BindingNodeIt).GetAttribute("StateID"); if( !CurrAttrib.Empty() ) StateID = CurrAttrib.AsUint(); CurrAttrib = (*BindingNodeIt).GetAttribute("LayerGroupID"); if( !CurrAttrib.Empty() ) { UInt16 LayerGroupID = CurrAttrib.AsUint(); RenderLayerGroup* NamedGroup = this->GetRenderLayerGroup( LayerGroupID ); if( NamedGroup != NULL ) { this->StateGroupBindings.insert( std::pair<UInt32,RenderLayerGroup*>(StateID,NamedGroup) ); }else{ StringStream ExceptionStream; ExceptionStream << "Named RenderLayerGroup \"" << LayerGroupID << "\" not found when deserializing Widget named \"" << this->GetName() << "\"."; MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,ExceptionStream.str()); } } }else{ MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("StateGroupBindings") + ": Not Version 1."); } } }else{ MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("StateGroupBindings") + ": Not Version 1."); } } }
string DrawContext::discPath(u16 radius) { StringStream ss; ss << "disc-"<<radius; return ss.str(); }
CSSRule* CSSStream::ParseRule(CSSStyleSheet* parentStyleSheet, CSSRule* parentRule, ICSSRuleListener* pListener) { // stream->SkipSpaces(); getnextc(); if (m_c == L'/') { getnextc(); //if (c == L'*') EatChar(L'*'); { CSSCommentRule* p = new CSSCommentRule; //p->AddRef(); p->m_textOffset[0] = stream.m_ipos-2; p->m_textOffset[1] = stream.m_ipos-2; p->m_textOffset[2] = stream.m_ipos; p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; StringStream cssText; cssText << L"/*"; while (!stream.eof()) { if (stream.m_c == L'*') { stream.getnextc(); if (stream.m_c == L'/') { stream.getnextc(); break; } } cssText << (WCHAR)stream.m_c; } p->m_textOffset[3] = stream.m_ipos; stream.EatChar(L'*'); stream.EatChar(L'/'); p->m_textOffset[4] = stream.m_ipos; p->m_textOffset[5] = stream.m_ipos; cssText << L"*/"; p->m_cssText = cssText->str(); *pVal = p; } } else if (m_c == L'@') // at-rule { ASSERT(0); #if 0 String id = stream.GetID(); StringStream strbuilder; strbuilder << L"@"; strbuilder << id; int curly = 0; while (!stream.eof()) { strbuilder << (WCHAR)m_c; if (stream.m_c == L'{') { curly++; } else if (stream.m_c == L'}') { curly--; if (curly == 0) break; } else if (stream.m_c == L';') { if (curly == 0) { break; } } } // Read spaces while (!stream.eof()) { if (!isspace(stream.m_c)) { break; } strbuilder << (WCHAR)stream.m_c; stream.getnextc(); } String cssText = strbuilder->str(); pCallback->AtRule(id, cssText); if (id == L"charset") { CSSCharsetRule* p = new CSSCharsetRule; if (p) { // p->AddRef(); p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; p->set_cssText(cssText); *pVal = p; } } else if (id == L"import") { CSSImportRule* p = new CSSImportRule; if (p) { // p->AddRef(); p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; p->set_cssText(cssText); *pVal = p; } } else if (id == L"fontface") { CSSFontFaceRule* p = new CSSFontFaceRule; if (p) { // p->AddRef(); p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; p->set_cssText(cssText); *pVal = p; } } else if (id == L"media") { CSSMediaRule* p = new CSSMediaRule; if (p) { //p->AddRef(); p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; p->set_cssText(cssText); *pVal = p; } } else if (id == L"color-profile") { SVGColorProfileRule* p = new SVGColorProfileRule; if (p) { // p->AddRef(); p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; p->set_cssText(cssText); *pVal = p; } } /* else if (!tcscmp(id, L"charset")) { } */ else // Unknown at-rule { CSSUnknownRule* p = new CSSUnknownRule; if (p) { //p->AddRef(); p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; p->set_cssText(cssText); *pVal = p; } } #endif } else { ParseStyleRule(); if (p) { // p->m_textOffset[0] = stream.m_ipos; p->m_parentStyleSheet = parentStyleSheet; p->m_parentRule = parentRule; StringStream cssText; // Skip selectors while (!stream.eof()) { cssText << (WCHAR)stream.m_c; if (m_c == L'{') { break; } stream.getnextc(); } p->m_textOffset[1] = stream.m_ipos; // Skip style declaration stream.EatChar(L'{'); int curly = 1; p->m_textOffset[2] = stream.m_ipos; while (!stream.eof()) { cssText << (WCHAR)stream.m_c; p->m_textOffset[3] = stream.m_ipos; if (stream.m_c == '"') { stream.getnextc(); //if (delimiter == L'\'' || L'\"') { while (!stream.eof()) { cssText << (WCHAR)stream.m_c; if (stream.m_c == '\\') { stream.getnextc(); cssText << (WCHAR)stream.m_c; } else if (stream.m_c == '"') { break; } } } } else if (stream.m_c == L'{') { curly++; } else if (stream.m_c == L'}') { curly--; if (curly == 0) { break; } } } p->m_textOffset[4] = stream.m_ipos; // Read spaces while (!stream.eof()) { if (!isspace(stream.m_c)) { break; } cssText << (WCHAR)stream.m_c; stream.getnextc(); } p->m_textOffset[5] = stream.m_ipos; p->set_cssText(cssText->str()); p->m_pListener = pListener; *pVal = p; } } return Success; }
/** Detect which internal formats are allowed as RTT Also detect what combinations of stencil and depth are allowed with this internal format. */ void GLES2FBOManager::detectFBOFormats() { #if OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN memset(mProps, 0, sizeof(mProps)); // TODO: Fix that probing all formats slows down startup not just on the web also on Android / iOS mProps[PF_A8B8G8R8].valid = true; FormatProperties::Mode mode = {1, 0}; mProps[PF_A8B8G8R8].modes.push_back(mode); LogManager::getSingleton().logMessage("[GLES2] : detectFBOFormats is disabled on this platform (due performance reasons)"); #else // Try all formats, and report which ones work as target GLES2RenderSystem* rs = getGLES2RenderSystem(); GLuint fb = 0, tid = 0; bool hasGLES3 = rs->hasMinGLVersion(3, 0); const size_t depthCount = hasGLES3 ? DEPTHFORMAT_COUNT : DEPTHFORMAT_COUNT - 1; // 32_8 is not available on GLES2 const size_t stencilStep = hasGLES3 ? 3 : 1; // 1 and 4 bit not available on GLES3 for(size_t x = 0; x < PF_COUNT; ++x) { mProps[x].valid = false; // Fetch GL format token GLint internalFormat = GLES2PixelUtil::getGLInternalFormat((PixelFormat)x); GLenum fmt = GLES2PixelUtil::getGLOriginFormat((PixelFormat)x); GLenum type = GLES2PixelUtil::getGLOriginDataType((PixelFormat)x); // Note: letting PF_UNKNOWN pass here is for pure depth/ stencil formats // however there are reports that this crashes some unspecified android devices if((internalFormat == GL_NONE || fmt == GL_NONE || type == GL_NONE) && (x != 0)) continue; // not color-renderable in GLES if(fmt == GL_BGRA_EXT) continue; // No test for compressed formats if(PixelUtil::isCompressed((PixelFormat)x)) continue; // Create and attach framebuffer _createTempFramebuffer((PixelFormat)x, internalFormat, fmt, type, fb, tid); // Ignore status in case of fmt==GL_NONE, because no implementation will accept // a buffer without *any* attachment. Buffers with only stencil and depth attachment // might still be supported, so we must continue probing. if(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) { mProps[x].valid = true; StringStream str; str << "FBO " << PixelUtil::getFormatName((PixelFormat)x) << " depth/stencil support: "; // For each depth/stencil formats for (size_t depth = 0; depth < depthCount; ++depth) { if (depthFormats[depth] != GL_DEPTH24_STENCIL8 && depthFormats[depth] != GL_DEPTH32F_STENCIL8) { // General depth/stencil combination for (size_t stencil = 0; stencil < STENCILFORMAT_COUNT; stencil += stencilStep) { // StringStream l; // l << "Trying " << PixelUtil::getFormatName((PixelFormat)x) // << " D" << depthBits[depth] // << "S" << stencilBits[stencil]; // LogManager::getSingleton().logMessage(l.str()); if (_tryFormat(depthFormats[depth], stencilFormats[stencil])) { // Add mode to allowed modes str << "D" << depthBits[depth] << "S" << stencilBits[stencil] << " "; FormatProperties::Mode mode; mode.depth = depth; mode.stencil = stencil; mProps[x].modes.push_back(mode); } else { // There is a small edge case that FBO is trashed during the test // on some drivers resulting in undefined behavior glBindFramebuffer(GL_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fb); _createTempFramebuffer((PixelFormat)x, internalFormat, fmt, type, fb, tid); } } } else if(hasGLES3 || rs->checkExtension("GL_OES_packed_depth_stencil") ) { // Packed depth/stencil format if (_tryPackedFormat(depthFormats[depth])) { // Add mode to allowed modes str << "Packed-D" << depthBits[depth] << "S" << 8 << " "; FormatProperties::Mode mode; mode.depth = depth; mode.stencil = 0; // unuse mProps[x].modes.push_back(mode); } else { // There is a small edge case that FBO is trashed during the test // on some drivers resulting in undefined behavior glBindFramebuffer(GL_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fb); _createTempFramebuffer((PixelFormat)x, internalFormat, fmt, type, fb, tid); } } } LogManager::getSingleton().logMessage(str.str()); } // Delete texture and framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fb); if (internalFormat != GL_NONE) { glDeleteTextures(1, &tid); tid = 0; } } // Clear any errors glGetError(); #endif String fmtstring; for(size_t x = 0; x < PF_COUNT; ++x) { if(mProps[x].valid) fmtstring += PixelUtil::getFormatName((PixelFormat)x)+" "; } LogManager::getSingleton().logMessage("[GLES2] : Valid FBO targets " + fmtstring); }
Pair::~Pair() { StringStream ss; ss << "~Pair():[key=" << mKey << ",value=" << mValue << ']'; LogManager::getSingleton().logMessage( ss.str() ); }
/// Builds an index with payloads in the given Directory and performs different /// tests to verify the payload encoding static void encodingTest(const DirectoryPtr& dir) { PayloadAnalyzerPtr analyzer = newLucene<PayloadAnalyzer>(); IndexWriterPtr writer = newLucene<IndexWriter>(dir, analyzer, true, IndexWriter::MaxFieldLengthLIMITED); // should be in sync with value in TermInfosWriter int32_t skipInterval = 16; int32_t numTerms = 5; String fieldName = L"f1"; int32_t numDocs = skipInterval + 1; // create content for the test documents with just a few terms Collection<TermPtr> terms = generateTerms(fieldName, numTerms); StringStream sb; for (Collection<TermPtr>::iterator term = terms.begin(); term != terms.end(); ++term) { sb << (*term)->text() << L" "; } String content = sb.str(); int32_t payloadDataLength = numTerms * numDocs * 2 + numTerms * numDocs * (numDocs - 1) / 2; ByteArray payloadData = generateRandomData(payloadDataLength); DocumentPtr d = newLucene<Document>(); d->add(newLucene<Field>(fieldName, content, Field::STORE_NO, Field::INDEX_ANALYZED)); // add the same document multiple times to have the same payload lengths for all // occurrences within two consecutive skip intervals int32_t offset = 0; for (int32_t i = 0; i < 2 * numDocs; ++i) { analyzer->setPayloadData(fieldName, payloadData, offset, 1); offset += numTerms; writer->addDocument(d); } // make sure we create more than one segment to test merging writer->commit(); for (int32_t i = 0; i < numDocs; ++i) { analyzer->setPayloadData(fieldName, payloadData, offset, i); offset += i * numTerms; writer->addDocument(d); } writer->optimize(); // flush writer->close(); // Verify the index IndexReaderPtr reader = IndexReader::open(dir, true); ByteArray verifyPayloadData(ByteArray::newInstance(payloadDataLength)); offset = 0; Collection<TermPositionsPtr> tps = Collection<TermPositionsPtr>::newInstance(numTerms); for (int32_t i = 0; i < numTerms; ++i) { tps[i] = reader->termPositions(terms[i]); } while (tps[0]->next()) { for (int32_t i = 1; i < numTerms; ++i) { tps[i]->next(); } int32_t freq = tps[0]->freq(); for (int32_t i = 0; i < freq; ++i) { for (int32_t j = 0; j < numTerms; ++j) { tps[j]->nextPosition(); tps[j]->getPayload(verifyPayloadData, offset); offset += tps[j]->getPayloadLength(); } } } for (int32_t i = 0; i < numTerms; ++i) { tps[i]->close(); } EXPECT_TRUE(payloadData.equals(verifyPayloadData)); // test lazy skipping TermPositionsPtr tp = reader->termPositions(terms[0]); tp->next(); tp->nextPosition(); // now we don't read this payload tp->nextPosition(); EXPECT_EQ(1, tp->getPayloadLength()); ByteArray payload = tp->getPayload(ByteArray(), 0); EXPECT_EQ(payload[0], payloadData[numTerms]); tp->nextPosition(); // we don't read this payload and skip to a different document tp->skipTo(5); tp->nextPosition(); EXPECT_EQ(1, tp->getPayloadLength()); payload = tp->getPayload(ByteArray(), 0); EXPECT_EQ(payload[0], payloadData[5 * numTerms]); // Test different lengths at skip points tp->seek(terms[1]); tp->next(); tp->nextPosition(); EXPECT_EQ(1, tp->getPayloadLength()); tp->skipTo(skipInterval - 1); tp->nextPosition(); EXPECT_EQ(1, tp->getPayloadLength()); tp->skipTo(2 * skipInterval - 1); tp->nextPosition(); EXPECT_EQ(1, tp->getPayloadLength()); tp->skipTo(3 * skipInterval - 1); tp->nextPosition(); EXPECT_EQ(3 * skipInterval - 2 * numDocs - 1, tp->getPayloadLength()); // Test multiple call of getPayload() tp->getPayload(ByteArray(), 0); // it is forbidden to call getPayload() more than once without calling nextPosition() try { tp->getPayload(ByteArray(), 0); } catch (IOException& e) { EXPECT_TRUE(check_exception(LuceneException::IO)(e)); } reader->close(); // test long payload analyzer = newLucene<PayloadAnalyzer>(); writer = newLucene<IndexWriter>(dir, analyzer, true, IndexWriter::MaxFieldLengthLIMITED); String singleTerm = L"lucene"; d = newLucene<Document>(); d->add(newLucene<Field>(fieldName, singleTerm, Field::STORE_NO, Field::INDEX_ANALYZED)); // add a payload whose length is greater than the buffer size of BufferedIndexOutput payloadData = generateRandomData(2000); analyzer->setPayloadData(fieldName, payloadData, 100, 1500); writer->addDocument(d); writer->optimize(); // flush writer->close(); reader = IndexReader::open(dir, true); tp = reader->termPositions(newLucene<Term>(fieldName, singleTerm)); tp->next(); tp->nextPosition(); verifyPayloadData.resize(tp->getPayloadLength()); tp->getPayload(verifyPayloadData, 0); ByteArray portion(ByteArray::newInstance(1500)); MiscUtils::arrayCopy(payloadData.get(), 100, portion.get(), 0, 1500); EXPECT_TRUE(portion.equals(verifyPayloadData)); reader->close(); }
void RadioButton::ProtoDeSerializeGroupButtons(const XML::Node& SelfRoot) { this->RemoveFromButtonGroup(); XML::Attribute CurrAttrib; XML::Node ButtonsNode = SelfRoot.GetChild( "GroupButtons" ); if( !ButtonsNode.Empty() ) { if( ButtonsNode.GetAttribute("Version").AsInt() == 1 ) { for( XML::NodeIterator ButtonNodeIt = ButtonsNode.begin() ; ButtonNodeIt != ButtonsNode.end() ; ++ButtonNodeIt ) { if( (*ButtonNodeIt).GetAttribute("Version").AsInt() == 1 ) { String GroupButtonName; CurrAttrib = (*ButtonNodeIt).GetAttribute("GroupButtonName"); if( !CurrAttrib.Empty() ) GroupButtonName = CurrAttrib.AsString(); if( !GroupButtonName.empty() ) { Widget* NamedButton = this->ParentScreen->GetWidget(GroupButtonName); if( NamedButton != NULL && NamedButton->GetTypeName() == RadioButton::TypeName ) { this->AddToButtonGroup( static_cast<RadioButton*>( NamedButton ) ); }else{ StringStream ExceptionStream; ExceptionStream << "Named Widget \"" << GroupButtonName << "\" not found or not a RadioButton when deserializing Widget named \"" << this->GetName() << "\"."; MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,ExceptionStream.str()); } } }else{ MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("GroupButtons") + ": Not Version 1."); } } }else{ MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("GroupButtons") + ": Not Version 1."); } } }
String ParserStatus::buildMessage(const size_t line, const size_t column, const String& str) const { StringStream msg; msg << str << " (line " << line << ", column " << column << ")"; return msg.str(); }
void displayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 * tokenNames) { // Adopted code from https://github.com/antlr/antlr3/blob/master/runtime/C/src/antlr3baserecognizer.c pANTLR3_EXCEPTION ex; pANTLR3_COMMON_TOKEN theToken; pANTLR3_BASE_TREE theBaseTree; pANTLR3_COMMON_TREE theCommonTree; // Retrieve some info for easy reading. ex = recognizer->state->exception; String fileName; // See if there is a 'filename' we can use if (ex->streamName != NULL) { pANTLR3_STRING ftext; ftext = ex->streamName->to8(ex->streamName); fileName.assign((const char*)ftext->chars); } int line = recognizer->state->exception->line; StringStream ss; ss << (const char*) (recognizer->state->exception->message); // How we determine the next piece is dependent on which thing raised the // error. pANTLR3_STRING ttext; switch (recognizer->type) { case ANTLR3_TYPE_PARSER: { // Prepare the knowledge we know we have theToken = (pANTLR3_COMMON_TOKEN)(recognizer->state->exception->token); ttext = theToken->toString(theToken); ss << ", at offset " << recognizer->state->exception->charPositionInLine; if (theToken != NULL) { if (theToken->type == ANTLR3_TOKEN_EOF) ss << ", at <EOF>"; else // Guard against null text in a token ss << "\n near " << (ttext == NULL ? "<no text for the token>" : (const char*)ttext->chars) << "\n "; } } break; case ANTLR3_TYPE_TREE_PARSER: theBaseTree = (pANTLR3_BASE_TREE)(recognizer->state->exception->token); ttext = theBaseTree->toStringTree(theBaseTree); if (theBaseTree != NULL) { theCommonTree = (pANTLR3_COMMON_TREE) theBaseTree->super; if (theCommonTree != NULL) { theToken = (pANTLR3_COMMON_TOKEN) theBaseTree->getToken(theBaseTree); } ss << ", at offset " << theBaseTree->getCharPositionInLine(theBaseTree); ss << ", near " << (const char*)ttext->chars; } break; default: std::cerr << "Base recognizer function displayRecognitionError called by unknown parser type - provide override for this function\n"; return; break; } // Although this function should generally be provided by the implementation, this one // should be as helpful as possible for grammar developers and serve as an example // of what you can do with each exception type. In general, when you make up your // 'real' handler, you should debug the routine with all possible errors you expect // which will then let you be as specific as possible about all circumstances. // // Note that in the general case, errors thrown by tree parsers indicate a problem // with the output of the parser or with the tree grammar itself. The job of the parser // is to produce a perfect (in traversal terms) syntactically correct tree, so errors // at that stage should really be semantic errors that your own code determines and handles // in whatever way is appropriate. switch (ex->type) { case ANTLR3_UNWANTED_TOKEN_EXCEPTION: // Indicates that the recognizer was fed a token which seesm to be // spurious input. We can detect this when the token that follows // this unwanted token would normally be part of the syntactically // correct stream. Then we can see that the token we are looking at // is just something that should not be there and throw this exception. if (tokenNames == NULL) ss << " : Extraneous input..."; else { if (ex->expecting == ANTLR3_TOKEN_EOF) ss << " : Extraneous input - expected <EOF>\n"; else ss << " : Extraneous input - expected " << tokenNames[ex->expecting] << " ...\n"; } break; case ANTLR3_MISSING_TOKEN_EXCEPTION: // Indicates that the recognizer detected that the token we just // hit would be valid syntactically if preceeded by a particular // token. Perhaps a missing ';' at line end or a missing ',' in an // expression list, and such like. if (tokenNames == NULL) ss << " : Missing token (" << ex->expecting << ")...\n"; else { if (ex->expecting == ANTLR3_TOKEN_EOF) ss << " : Missing <EOF>\n"; else ss << " : Missing " << tokenNames[ex->expecting] << " \n"; } break; case ANTLR3_RECOGNITION_EXCEPTION: // Indicates that the recognizer received a token // in the input that was not predicted. This is the basic exception type // from which all others are derived. So we assume it was a syntax error. // You may get this if there are not more tokens and more are needed // to complete a parse for instance. ss << " : syntax error...\n"; break; case ANTLR3_MISMATCHED_TOKEN_EXCEPTION: // We were expecting to see one thing and got another. This is the // most common error if we coudl not detect a missing or unwanted token. // Here you can spend your efforts to // derive more useful error messages based on the expected // token set and the last token and so on. The error following // bitmaps do a good job of reducing the set that we were looking // for down to something small. Knowing what you are parsing may be // able to allow you to be even more specific about an error. if (tokenNames == NULL) ss << " : syntax error...\n"; else { if (ex->expecting == ANTLR3_TOKEN_EOF) ss << " : expected <EOF>\n"; else ss << " : expected " << tokenNames[ex->expecting] << " ...\n"; } break; case ANTLR3_NO_VIABLE_ALT_EXCEPTION: // We could not pick any alt decision from the input given // so god knows what happened - however when you examine your grammar, // you should. It means that at the point where the current token occurred // that the DFA indicates nowhere to go from here. ss << " : cannot match to any predicted input...\n"; break; case ANTLR3_MISMATCHED_SET_EXCEPTION: { ANTLR3_UINT32 count; ANTLR3_UINT32 bit; ANTLR3_UINT32 size; ANTLR3_UINT32 numbits; pANTLR3_BITSET errBits; // This means we were able to deal with one of a set of // possible tokens at this point, but we did not see any // member of that set. ss << " : unexpected input...\n expected one of : "; // What tokens could we have accepted at this point in the // parse? count = 0; errBits = antlr3BitsetLoad (ex->expectingSet); numbits = errBits->numBits (errBits); size = errBits->size (errBits); if (size > 0) { // However many tokens we could have dealt with here, it is usually // not useful to print ALL of the set here. I arbitrarily chose 8 // here, but you should do whatever makes sense for you of course. // No token number 0, so look for bit 1 and on. for (bit = 1; bit < numbits && count < 8 && count < size; bit++) { // TODO: This doesn;t look right - should be asking if the bit is set!! if (tokenNames[bit]) { ss << (count > 0 ? ", " : "") << tokenNames[bit]; count++; } } ss << "\n"; } else { std::cerr << "Actually dude, we didn't seem to be expecting anything here, or at least\n"; std::cerr << "I could not work out what I was expecting, like so many of us these days!\n"; } } break; case ANTLR3_EARLY_EXIT_EXCEPTION: // We entered a loop requiring a number of token sequences // but found a token that ended that sequence earlier than // we should have done. ss << " : missing elements...\n"; break; default: // We don't handle any other exceptions here, but you can // if you wish. If we get an exception that hits this point // then we are just going to report what we know about the // token. ss << " : syntax not recognized...\n"; break; } THROW_EXCEPT(Exception::ERR_PARSE, ss.str(), fileName, line); }
void Entresol::ConstructFromXML(const String& EngineDataPath, const Mezzanine::ArchiveType ArchType, const String& InitializerFile) { //Add default manager factories AddAllEngineDefaultManagerFactories(); //Set some sane Defaults for some values. this->ManualLoopBreak = false; // Create Ogre. SetupOgre(); // Load the necessary plugins. SubSystemParticleFXPlugin = new Ogre::ParticleFXPlugin(); Ogre::Root::getSingleton().installPlugin(SubSystemParticleFXPlugin); // Set up the data we'll be populating. XML::Attribute CurrAttrib; String GUIInit, ResourceInit, PluginsInit, LogFileName; String PluginExtension, PluginPath; // Create or set the resource manager. /// @todo This currently forces our default resource manager to be constructed, which isn't in line with our factory/initiailzation design. /// This should be addressed somehow. if(ResourceManager::SingletonValid()) { AddManager(ResourceManager::GetSingletonPtr()); } else { AddManager(new ResourceManager(EngineDataPath, ArchType)); } // Open and load the initializer doc. ResourceManager* ResourceMan = GetResourceManager(); /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready. Resource::FileStream InitStream(InitializerFile,EngineDataPath); XML::Document InitDoc; XML::ParseResult DocResult = InitDoc.Load(InitStream); if( DocResult.Status != XML::StatusOk ) { StringStream ExceptionStream; ExceptionStream << "Failed to parse XML file \"" << InitializerFile << "\"."; MEZZ_EXCEPTION(Exception::SYNTAX_ERROR_EXCEPTION_XML,ExceptionStream.str()); } XML::Node InitRoot = InitDoc.GetChild("InitializerRoot"); if( InitRoot.Empty() ) { StringStream ExceptionStream; ExceptionStream << "Failed to find expected Root node in \"" << InitializerFile << "\"."; MEZZ_EXCEPTION(Exception::SYNTAX_ERROR_EXCEPTION_XML,ExceptionStream.str()); } // Get the world settings and set them. XML::Node WorldSettings = InitRoot.GetChild("WorldSettings"); for( XML::NodeIterator SetIt = WorldSettings.begin() ; SetIt != WorldSettings.end() ; ++SetIt ) { String SecName = (*SetIt).Name(); if( "FrameSettings" == SecName ) { CurrAttrib = (*SetIt).GetAttribute("TargetFrameRate"); if(CurrAttrib.Empty()) { CurrAttrib = (*SetIt).GetAttribute("TargetFrameTime"); if(!CurrAttrib.Empty()) SetTargetFrameTimeMicroseconds(CurrAttrib.AsWhole()); }else{ this->SetTargetFrameRate(CurrAttrib.AsWhole()); } } else { MEZZ_EXCEPTION(Exception::SYNTAX_ERROR_EXCEPTION_XML,String("Unknown WorldSetting ")+SecName); } } SetupLogging(LogFileName); // Get the other initializer files we'll be using, since we'll need the plugins initializer. XML::Node InitFiles = InitRoot.GetChild("OtherInitializers"); for( XML::NodeIterator InitIt = InitFiles.begin() ; InitIt != InitFiles.end() ; ++InitIt ) { String InitFileName = (*InitIt).Name(); if( "PluginInit" == InitFileName ) { CurrAttrib = (*InitIt).GetAttribute("FileName"); if(!CurrAttrib.Empty()) PluginsInit = CurrAttrib.AsString(); } else if( "ResourceInit" == InitFileName ) { CurrAttrib = (*InitIt).GetAttribute("FileName"); if(!CurrAttrib.Empty()) ResourceInit = CurrAttrib.AsString(); } else if( "GUIInit" == InitFileName ) { CurrAttrib = (*InitIt).GetAttribute("FileName"); if(!CurrAttrib.Empty()) GUIInit = CurrAttrib.AsString(); } } // Load additional resource groups /*if(!ResourceInit.empty()) { /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready. Resource::FileStream ResourceStream(ResourceInit,EngineDataPath); XML::Document ResourceDoc; ResourceDoc.Load(ResourceStream); // Get an iterator to the first resource group node, and declare them all. XML::Node ResourceLocations = ResourceDoc.GetChild("ResourceLocations"); for( XML::NodeIterator GroupIt = ResourceLocations.begin() ; GroupIt != ResourceLocations.end() ; ++GroupIt ) { String GroupName, GroupType, GroupPath; bool GroupRecursive = false; // Get the group path CurrAttrib = (*GroupIt).GetAttribute("GroupPath"); if(!CurrAttrib.Empty()) GroupPath = CurrAttrib.AsString(); // Get the group type CurrAttrib = (*GroupIt).GetAttribute("GroupType"); if(!CurrAttrib.Empty()) GroupType = CurrAttrib.AsString(); // Get the group name CurrAttrib = (*GroupIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); // Get whether this is recursive CurrAttrib = (*GroupIt).GetAttribute("Recursive"); if(!CurrAttrib.Empty()) GroupRecursive = StringTool::ConvertToBool(CurrAttrib.AsString()); // Finally create the resource location. ResourceMan->AddAssetLocation(GroupPath,GroupType,GroupName,GroupRecursive); } // Get what resource groups should be initialized. XML::Node InitGroups = ResourceDoc.GetChild("InitGroups"); for( XML::NodeIterator InitIt = InitGroups.begin() ; InitIt != InitGroups.end() ; ++InitIt ) { String GroupName; CurrAttrib = (*InitIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); ResourceMan->InitAssetGroup(GroupName); } }//*/ // Create the requested managers and set their necessary values. XML::Node Managers = InitRoot.GetChild("Managers"); for( XML::NodeIterator ManIt = Managers.begin() ; ManIt != Managers.end() ; ++ManIt ) { CreateManager( (*ManIt).Name(), (*ManIt) ); } // Load additional resource groups if(!ResourceInit.empty()) { /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready. Resource::FileStream ResourceStream(ResourceInit,EngineDataPath); XML::Document ResourceDoc; ResourceDoc.Load(ResourceStream); // Get an iterator to the first resource group node, and declare them all. XML::Node ResourceLocations = ResourceDoc.GetChild("ResourceLocations"); for( XML::NodeIterator GroupIt = ResourceLocations.begin() ; GroupIt != ResourceLocations.end() ; ++GroupIt ) { String GroupName, GroupPath; ArchiveType GroupType; bool GroupRecursive = false; // Get the group path CurrAttrib = (*GroupIt).GetAttribute("GroupPath"); if(!CurrAttrib.Empty()) GroupPath = CurrAttrib.AsString(); // Get the group type CurrAttrib = (*GroupIt).GetAttribute("GroupType"); if(!CurrAttrib.Empty()) GroupType = ResourceManager::GetArchiveTypeFromString(CurrAttrib.AsString()); // Get the group name CurrAttrib = (*GroupIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); // Get whether this is recursive CurrAttrib = (*GroupIt).GetAttribute("Recursive"); if(!CurrAttrib.Empty()) GroupRecursive = StringTools::ConvertToBool(CurrAttrib.AsString()); // Finally create the resource location. ResourceMan->AddAssetLocation(GroupPath,GroupType,GroupName,GroupRecursive); } // Get what resource groups should be initialized. XML::Node InitGroups = ResourceDoc.GetChild("InitGroups"); for( XML::NodeIterator InitIt = InitGroups.begin() ; InitIt != InitGroups.end() ; ++InitIt ) { String GroupName; CurrAttrib = (*InitIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); ResourceMan->InitAssetGroup(GroupName); } } // Configure the UI if(!GUIInit.empty()) { /// @todo This is currently not implemented. } SanityChecks(); }
static int run(int argc, const Char* const* argv){ ScopedMessage message; try{ bool show_usage = false; bool quiet = false; const Char* source_file_arg = NULL; for (int i = 1; i < argc; ++i) { String arg = argv[i]; if (arg[0] == '-') { if (arg == _("--help") || arg == _("-h")) show_usage = true; else if (arg == _("--quiet") || arg == _("-q")) quiet = true; } else { // multiple file arguments is erroneous if (source_file_arg != NULL) show_usage = true; source_file_arg = argv[i]; } } if(show_usage || source_file_arg == NULL){ message<<_("Usage: ")<<fs::system_complete(argv[0]).leaf()<<_(" [--quiet] <filename>")<<endl<<endl; return 1; } const Path source_file = fs::system_complete(source_file_arg); Path target_dir = fs::system_complete(argv[0]).branch_path(); if(!fs::exists(source_file)){ message<<source_file<<endl<<_("File not found.")<<endl; return 1; } ArchiveType content = read_archive_content_sd7(source_file); if(content == R_OTHER){ content = read_archive_content_sdz(source_file); } if(content == R_OTHER){ message<<_("'")<<source_file.leaf()<<_("' is not a valid map/mod ") _("it may be corrupted, try to redownload it.")<<endl; return 1; } //for(Path test_path = source_file; test_path.has_root_directory(); ){ // if(fs::equivalent(test_path, target_dir)){ // message<<_("'")<<source_file.leaf()<<_("' already exists in the Spring directory.")<<endl; // return 1; // } // test_path = test_path.branch_path(); //} if(content == R_MAP){ //message<<"isMap: "<<filename<<endl; target_dir /= _("maps"); }else if(content == R_MOD){ //message<<"isMod: "<<filename<<endl; target_dir /= _("mods"); }else{ assert(false); } if(!fs::exists(target_dir)){ message<<_("The target directory '")<<target_dir<<_("' doesn't exist.")<<endl; return 1; } // stash existing files away if (fs::exists(target_dir / source_file.leaf())) { int i = 0; Path target_test; do { String stashed = (source_file.leaf() + _(".old")); if (i > 0) { StringStream tmp; tmp << i; stashed += _(".")+tmp.str(); } target_test = target_dir / stashed; ++i; } while (fs::exists(target_test)); fs::rename(target_dir / source_file.leaf(), target_test); message << "File with same name found. It has been moved to " << endl << target_test << endl << endl; } target_dir /= source_file.leaf(); fs::rename(source_file, target_dir); if (!quiet) { message<<_("The ")<<(content == R_MAP? _("map '") : _("mod '"))<<source_file.leaf() <<_("' has been saved succesfully to '")<<target_dir.branch_path()<<_("'.")<<endl <<_("Use the reload mods/maps button in the lobby to make Spring find it.")<<endl; } } catch(FilesystemPathError& error) { fs::errno_type error_nr = fs::lookup_errno(error.system_error()); message<<_("Cannot move file: "); switch(error_nr){ case EPERM: case EACCES:{ message<<_("Permission denied."); break; } case ENOSPC:{ message<<_("Not enough free disk space."); break; } case ENOENT:{ message<<_("Invalid path."); break; } case EROFS:{ message<<_("Target path is read only."); break; } case EEXIST:{ message<<_("Target folder already contains a file named '")<<error.path1().leaf()<<_("'."); break; } default:{ message<<strerror(error_nr)<<_("."); } } message<<endl<<endl; message<<_("Source file: ")<<error.path1()<<endl; message<<_("Target folder: ")<<error.path2().branch_path()<<endl; } catch(fs::filesystem_error& error) { message<<_("Filesystem error in: ")<<error.what()<<endl; } catch(std::exception& error) { message<<_("Found an exception with: ")<<error.what()<<endl; } catch(...) { message<<_("Found an unknown exception.")<<endl; } return 0; }
void desugar(AST *&ast_) { if (auto *ast = dynamic_cast<Apply*>(ast_)) { desugar(ast->target); for (AST *&arg : ast->arguments) desugar(arg); } else if (auto *ast = dynamic_cast<Array*>(ast_)) { for (AST *&el : ast->elements) desugar(el); } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) { for (ComprehensionSpec &spec : ast->specs) desugar(spec.expr); desugar(ast->body); int n = ast->specs.size(); AST *zero = make<LiteralNumber>(E, 0.0); AST *one = make<LiteralNumber>(E, 1.0); auto *_r = id(U"$r"); auto *_l = id(U"$l"); std::vector<const Identifier*> _i(n); for (int i = 0; i < n ; ++i) { StringStream ss; ss << U"$i_" << i; _i[i] = id(ss.str()); } std::vector<const Identifier*> _aux(n); for (int i = 0; i < n ; ++i) { StringStream ss; ss << U"$aux_" << i; _aux[i] = id(ss.str()); } // Build it from the inside out. We keep wrapping 'in' with more ASTs. assert(ast->specs[0].kind == ComprehensionSpec::FOR); int last_for = n - 1; while (ast->specs[last_for].kind != ComprehensionSpec::FOR) last_for--; // $aux_{last_for}($i_{last_for} + 1, $r + [body]) AST *in = make<Apply>( ast->body->location, var(_aux[last_for]), std::vector<AST*> { make<Binary>(E, var(_i[last_for]), BOP_PLUS, one), make<Binary>(E, var(_r), BOP_PLUS, singleton(ast->body)) }, true // tailstrict ); for (int i = n - 1; i >= 0 ; --i) { const ComprehensionSpec &spec = ast->specs[i]; AST *out; if (i > 0) { int prev_for = i - 1; while (ast->specs[prev_for].kind != ComprehensionSpec::FOR) prev_for--; // aux_{prev_for}($i_{prev_for} + 1, $r) out = make<Apply>( // False branch. E, var(_aux[prev_for]), std::vector<AST*> { make<Binary>(E, var(_i[prev_for]), BOP_PLUS, one), var(_r)}, true // tailstrict ); } else { out = var(_r); } switch (spec.kind) { case ComprehensionSpec::IF: { /* if [[[...cond...]]] then [[[...in...]]] else [[[...out...]]] */ in = make<Conditional>( ast->location, spec.expr, in, // True branch. out); // False branch. } break; case ComprehensionSpec::FOR: { /* local $l = [[[...array...]]]; local aux_{i}(i_{i}, r) = if i_{i} >= std.length(l) then [[[...out...]]] else local [[[...var...]]] = l[i_{i}]; [[[...in...]]] aux_{i}(0, r) tailstrict; */ in = make<Local>( ast->location, Local::Binds { {_l, spec.expr}, {_aux[i], make<Function>( ast->location, std::vector<const Identifier*>{_i[i], _r}, make<Conditional>( ast->location, make<Binary>( E, var(_i[i]), BOP_GREATER_EQ, length(var(_l))), out, make<Local>( ast->location, Local::Binds {{ spec.var, make<Index>(E, var(_l), var(_i[i])) }}, in) ) )}}, make<Apply>( E, var(_aux[i]), std::vector<AST*> { zero, i == 0 ? make<Array>(E, std::vector<AST*>{}) : static_cast<AST*>(var(_r)) }, true)); // tailstrict } break; } } ast_ = in; } else if (auto *ast = dynamic_cast<Binary*>(ast_)) { desugar(ast->left); desugar(ast->right); } else if (dynamic_cast<const BuiltinFunction*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) { desugar(ast->cond); desugar(ast->branchTrue); desugar(ast->branchFalse); } else if (auto *ast = dynamic_cast<Error*>(ast_)) { desugar(ast->expr); } else if (auto *ast = dynamic_cast<Function*>(ast_)) { desugar(ast->body); } else if (dynamic_cast<const Import*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const Importstr*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<Index*>(ast_)) { desugar(ast->target); desugar(ast->index); } else if (auto *ast = dynamic_cast<Local*>(ast_)) { for (auto &bind: ast->binds) desugar(bind.second); desugar(ast->body); } else if (dynamic_cast<const LiteralBoolean*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const LiteralNumber*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const LiteralString*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const LiteralNull*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<Object*>(ast_)) { for (auto &assert : ast->asserts) { desugar(assert); } for (auto &field : ast->fields) { desugar(field.name); desugar(field.body); } } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) { for (ComprehensionSpec &spec : ast->specs) desugar(spec.expr); desugar(ast->field); desugar(ast->value); /* { [arr[0]]: local x = arr[1], y = arr[2], z = arr[3]; val_expr for arr in [ [key_expr, x, y, z] for ... ] } */ auto *_arr = id(U"$arr"); AST *zero = make<LiteralNumber>(E, 0.0); int counter = 1; Local::Binds binds; auto arr_e = std::vector<AST*> {ast->field}; for (ComprehensionSpec &spec : ast->specs) { if (spec.kind == ComprehensionSpec::FOR) { binds[spec.var] = make<Index>(E, var(_arr), make<LiteralNumber>(E, double(counter++))); arr_e.push_back(var(spec.var)); } } AST *arr = make<ArrayComprehension>( ast->location, make<Array>(ast->location, arr_e), ast->specs); desugar(arr); ast_ = make<ObjectComprehensionSimple>( ast->location, make<Index>(E, var(_arr), zero), make<Local>( ast->location, binds, ast->value), _arr, arr); } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { desugar(ast->field); desugar(ast->value); desugar(ast->array); } else if (dynamic_cast<const Self*>(ast_)) { // Nothing to do. } else if (dynamic_cast<const Super*>(ast_)) { // Nothing to do. } else if (auto *ast = dynamic_cast<Unary*>(ast_)) { desugar(ast->expr); } else if (dynamic_cast<const Var*>(ast_)) { // Nothing to do. } else { std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; std::abort(); } }
unsigned Stream::ReadAt(void *buffer, uint64_t pos, size_t len, size_t *pread) { /** @todo Isn't thread-safe like the other ReadAt's. Add a mutex. */ LOG(HTTP) << "hs" << this << ".ReadAt(" << pos << ",+" << len << ") lastpos=" << m_last_pos << "\n"; if (!m_need_fetch && pos != m_last_pos) { m_socket.Close(); m_socket.Open(); m_need_fetch = true; Seek(pos); } if (m_len && pos == m_len) { *pread = 0; return 0; } if (m_need_fetch) { m_socket.SetNonBlocking(false); LOG(HTTP) << "hs" << this << ": synchronous connect\n"; unsigned int rc = m_socket.Connect(m_ipe); if (rc != 0) { LOG(HTTP) << "hs" << this << " can't connect: " << rc << "\n"; return rc; } std::string headers = "GET"; headers += " " + m_path + " HTTP/1.1\r\n"; headers += "Host: " + m_host + "\r\n"; if (pos) { if (m_len) { headers += util::Printf() << "Range: bytes=" << pos << "-" << (m_len-1) << "\r\n"; } else { /* This is a bit nasty. Some "traditional" Receiver * servers (in particular, Jupiter) don't like * one-ended ranges. All such servers are on the * "traditional" Receiver port of 12078; all such * servers don't deal with >4GB files anyway. They do, * however, deal with clipping large ranges to the * actual size. */ if (m_ipe.port == 12078) { headers += util::Printf() << "Range: bytes=" << pos << "-4294967295\r\n"; } else { headers += util::Printf() << "Range: bytes=" << pos << "-\r\n"; } } } headers += "User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n"; headers += "\r\n"; rc = m_socket.WriteAll(headers.c_str(), headers.length()); if (rc != 0) { TRACE << "Can't even write headers: " << rc << "\n"; return rc; } LOG(HTTP) << "hs" << this << " sent headers:\n" << headers; rc = m_socket.SetNonBlocking(true); if (rc != 0) { TRACE << "Can't set non-blocking: " << rc << "\n"; return rc; } util::GreedyLineReader lr(&m_socket); http::Parser hp(&lr); bool is_error = false; for (;;) { unsigned int httpcode; rc = hp.GetResponseLine(&httpcode, NULL); LOG(HTTP) << "GetResponseLine returned " << rc << "\n"; if (rc == 0) { is_error = (httpcode != 206 && httpcode != 200); break; } if (rc != EWOULDBLOCK) { TRACE << "GetLine failed " << rc << "\n"; return rc; } if (rc == EWOULDBLOCK) { rc = m_socket.WaitForRead(30000); if (rc != 0) { TRACE << "hs" << this << " socket won't come ready " << rc << "\n"; return rc; } } } m_socket.SetNonBlocking(false); bool got_range = false; uint64_t clen = 0; for (;;) { std::string key, value; rc = hp.GetHeaderLine(&key, &value); // Note that PeekingLineReader uses ReadPeek which doesn't use // the internal timeout. if (rc == EWOULDBLOCK) { rc = m_socket.WaitForRead(5000); if (rc != 0) { TRACE << "hs" << this << " socket won't come ready in headers " << rc << "\n"; return rc; } continue; } if (rc) { TRACE << "GetHeaderLine says " << rc << ", bailing\n"; return rc; } if (key.empty()) break; LOG(HTTP) << "hs" << this << " " << key << ": " << value << "\n"; if (!strcasecmp(key.c_str(), "Content-Range")) { uint64_t rmin, rmax, elen = 0; /* HTTP/1.1 says "Content-Range: bytes X-Y/Z" * but traditional Receiver servers send * "Content-Range: bytes=X-Y" */ if (util::Scanf64(value.c_str(), "bytes %llu-%llu/%llu", &rmin, &rmax, &elen) == 3 || util::Scanf64(value.c_str(), "bytes=%llu-%llu/%llu", &rmin, &rmax, &elen) == 3 || util::Scanf64(value.c_str(), "bytes %llu-%llu", &rmin, &rmax) == 2 || util::Scanf64(value.c_str(), "bytes=%llu-%llu", &rmin, &rmax) == 2) { if (elen) m_len = elen; else m_len = rmax + 1; got_range = true; } } else if (!strcasecmp(key.c_str(), "Content-Length")) { util::Scanf64(value.c_str(), "%llu", &clen); } } if (!got_range) m_len = clen; if (is_error) { std::unique_ptr<util::Stream> epage(CreatePartialStream(&m_socket, 0, clen)); StringStream ssp; CopyStream(epage.get(), &ssp); TRACE << "HTTP error page: " << ssp.str() << "\n"; return EINVAL; } m_need_fetch = false; m_last_pos = pos; lr.ReadLeftovers(buffer, len, pread); if (*pread) { m_last_pos += *pread; return 0; } } unsigned int rc = m_socket.Read(buffer, len, pread); if (!rc) { m_last_pos += *pread; LOG(HTTP) << "hs" << this << " socket read " << *pread << " bytes\n"; } else { LOG(HTTP) << "hs" << this << " socket read error " << rc << "\n"; } return rc; }
ReparentBrushesCommand* ReparentBrushesCommand::reparent(Model::MapDocument& document, const Model::BrushList& brushes, Model::Entity& newParent) { StringStream name; name << (brushes.size() == 1 ? "Move Brush to " : "Move Brushes to "); name << (newParent.classname() != NULL ? *newParent.classname() : Model::Entity::NoClassnameValue); return new ReparentBrushesCommand(document, name.str(), brushes, newParent); }
string DrawContext::ringPath(u16 radius, u16 thickness) { StringStream ss; ss << "ring-"<<radius<<"-"<<thickness; return ss.str(); }
//--------------------------------------------------------------------- bool Technique::checkGPURules(StringStream& errors) { const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities(); StringStream includeRules; bool includeRulesPresent = false; bool includeRuleMatched = false; // Check vendors first for (GPUVendorRuleList::const_iterator i = mGPUVendorRules.begin(); i != mGPUVendorRules.end(); ++i) { if (i->includeOrExclude == INCLUDE) { includeRulesPresent = true; includeRules << caps->vendorToString(i->vendor) << " "; if (i->vendor == caps->getVendor()) includeRuleMatched = true; } else // EXCLUDE { if (i->vendor == caps->getVendor()) { errors << "Excluded GPU vendor: " << caps->vendorToString(i->vendor) << std::endl; return false; } } } if (includeRulesPresent && !includeRuleMatched) { errors << "Failed to match GPU vendor: " << includeRules.str( ) << std::endl; return false; } // now check device names includeRules.str(BLANKSTRING); includeRulesPresent = false; includeRuleMatched = false; for (GPUDeviceNameRuleList::const_iterator i = mGPUDeviceNameRules.begin(); i != mGPUDeviceNameRules.end(); ++i) { if (i->includeOrExclude == INCLUDE) { includeRulesPresent = true; includeRules << i->devicePattern << " "; if (StringUtil::match(caps->getDeviceName(), i->devicePattern, i->caseSensitive)) includeRuleMatched = true; } else // EXCLUDE { if (StringUtil::match(caps->getDeviceName(), i->devicePattern, i->caseSensitive)) { errors << "Excluded GPU device: " << i->devicePattern << std::endl; return false; } } } if (includeRulesPresent && !includeRuleMatched) { errors << "Failed to match GPU device: " << includeRules.str( ) << std::endl; return false; } // passed return true; }
void GLES2FrameBufferObject::initialise() { // Release depth and stencil, if they were bound mManager->releaseRenderBuffer(mDepth); mManager->releaseRenderBuffer(mStencil); mManager->releaseRenderBuffer(mMultisampleColourBuffer); /// First buffer must be bound if(!mColour[0].buffer) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attachment 0 must have surface attached", "GLES2FrameBufferObject::initialise"); } // If we're doing multisampling, then we need another FBO which contains a // renderbuffer which is set up to multisample, and we'll blit it to the final // FBO afterwards to perform the multisample resolve. In that case, the // mMultisampleFB is bound during rendering and is the one with a depth/stencil ushort maxSupportedMRTs = Root::getSingleton().getRenderSystem()->getCapabilities()->getNumMultiRenderTargets(); /// Store basic stats size_t width = mColour[0].buffer->getWidth(); size_t height = mColour[0].buffer->getHeight(); GLuint format = mColour[0].buffer->getGLFormat(); // Bind simple buffer to add colour attachments glBindFramebuffer(GL_FRAMEBUFFER, mFB); GL_CHECK_ERROR; /// Bind all attachment points to frame buffer for(size_t x=0; x<maxSupportedMRTs; ++x) { if(mColour[x].buffer) { if(mColour[x].buffer->getWidth() != width || mColour[x].buffer->getHeight() != height) { StringStream ss; ss << "Attachment " << x << " has incompatible size "; ss << mColour[x].buffer->getWidth() << "x" << mColour[x].buffer->getHeight(); ss << ". It must be of the same as the size of surface 0, "; ss << width << "x" << height; ss << "."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLES2FrameBufferObject::initialise"); } if(mColour[x].buffer->getGLFormat() != format) { StringStream ss; ss << "Attachment " << x << " has incompatible format."; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLES2FrameBufferObject::initialise"); } mColour[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0+x, mColour[x].zoffset); } else { // Detach glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+x, GL_RENDERBUFFER, 0); GL_CHECK_ERROR; } } // Now deal with depth / stencil if (mMultisampleFB) { // Bind multisample buffer glBindFramebuffer(GL_FRAMEBUFFER, mMultisampleFB); GL_CHECK_ERROR; // Create AA render buffer (colour) // note, this can be shared too because we blit it to the final FBO // right after the render is finished mMultisampleColourBuffer = mManager->requestRenderBuffer(format, width, height, mNumSamples); // Attach it, because we won't be attaching below and non-multisample has // actually been attached to other FBO mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0, mMultisampleColourBuffer.zoffset); // depth & stencil will be dealt with below } GL_CHECK_ERROR; /// Depth buffer is not handled here anymore. /// See GLES2FrameBufferObject::attachDepthBuffer() & RenderSystem::setDepthBufferFor() GLenum bufs[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x) { // Fill attached colour buffers if(mColour[x].buffer) { bufs[x] = GL_COLOR_ATTACHMENT0 + x; } else { bufs[x] = GL_NONE; } } /// Check status GLuint status; status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GL_CHECK_ERROR; /// Bind main buffer #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS // The screen buffer is 1 on iOS glBindFramebuffer(GL_FRAMEBUFFER, 1); #else glBindFramebuffer(GL_FRAMEBUFFER, 0); #endif GL_CHECK_ERROR; switch(status) { case GL_FRAMEBUFFER_COMPLETE: // All is good break; case GL_FRAMEBUFFER_UNSUPPORTED: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "All framebuffer formats with this texture internal format unsupported", "GLES2FrameBufferObject::initialise"); default: OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Framebuffer incomplete or other FBO status error", "GLES2FrameBufferObject::initialise"); } }
String CrashHandler::getStackTrace() { StringStream stackTrace; void *trace[BS_MAX_STACKTRACE_DEPTH]; int trace_size = backtrace(trace, BS_MAX_STACKTRACE_DEPTH); char **messages = backtrace_symbols(trace, trace_size); // Most lines returned by backtrace_symbols() look like this: // // <path/to/binary>(mangled_symbol+offset) [address] // // For those lines, we demangle the symbol with abi::__cxa_demangle(), // others are good as is. for (int i = 0; i < trace_size && messages != NULL; ++i) { // Try to find the characters surrounding the mangled name: '(' and '+' char *mangled_name = NULL, *offset_begin = NULL, *offset_end = NULL; for (char *p = messages[i]; *p; ++p) { if (*p == '(') mangled_name = p; else if (*p == '+') offset_begin = p; else if (*p == ')') { offset_end = p; break; } } bool lineContainsMangledSymbol = mangled_name != NULL && offset_begin != NULL && offset_end != NULL && mangled_name < offset_begin; stackTrace << toString(i) << ") "; if (lineContainsMangledSymbol) { *mangled_name++ = '\0'; *offset_begin++ = '\0'; *offset_end++ = '\0'; int status; char *real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status); char *output_name = status == 0 /* Demangling successful */? real_name : mangled_name; stackTrace << String(messages[i]) << ": " << output_name << "+" << offset_begin << offset_end; free(real_name); } else stackTrace << String(messages[i]); if (i < trace_size - 1) stackTrace << "\n"; } free(messages); return stackTrace.str(); }
void GLFrameBufferObject::rebuild() { // First buffer must be bound if(!mColor[0].buffer) BS_EXCEPT(InvalidParametersException, "Attachment 0 must have surface attached"); // Store basic stats UINT32 width = mColor[0].buffer->getWidth(); UINT32 height = mColor[0].buffer->getHeight(); UINT16 maxSupportedMRTs = BansheeEngine::RenderAPICore::instancePtr()->getCapabilities()->getNumMultiRenderTargets(); // Bind simple buffer to add color attachments glBindFramebuffer(GL_FRAMEBUFFER, mFB); bool bindAllLayers = false; // Bind all attachment points to frame buffer for(UINT16 x = 0; x < maxSupportedMRTs; ++x) { if(mColor[x].buffer) { if(mColor[x].buffer->getWidth() != width || mColor[x].buffer->getHeight() != height) { StringStream ss; ss << "Attachment " << x << " has incompatible size "; ss << mColor[x].buffer->getWidth() << "x" << mColor[x].buffer->getHeight(); ss << ". It must be of the same as the size of surface 0, "; ss << width << "x" << height; ss << "."; BS_EXCEPT(InvalidParametersException, ss.str()); } // Note: I'm attaching textures to FBO while renderbuffers might yield better performance if I // don't need to read from them mColor[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0 + x, mColor[x].zoffset, mColor[x].allLayers); bindAllLayers |= mColor[x].allLayers; } else { // Detach glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + x, 0, 0); } } if(mDepthStencilBuffer != nullptr) mDepthStencilBuffer->bindToFramebuffer(GL_DEPTH_STENCIL_ATTACHMENT, 0, bindAllLayers); // Do glDrawBuffer calls GLenum bufs[BS_MAX_MULTIPLE_RENDER_TARGETS]; GLsizei n = 0; for(UINT32 x = 0; x < BS_MAX_MULTIPLE_RENDER_TARGETS; ++x) { // Fill attached colour buffers if(mColor[x].buffer) { bufs[x] = GL_COLOR_ATTACHMENT0 + x; // Keep highest used buffer + 1 n = x+1; } else { bufs[x] = GL_NONE; } } glDrawBuffers(n, bufs); // No read buffer, by default, if we want to read anyway we must not forget to set this. glReadBuffer(GL_NONE); // Check status GLuint status; status = glCheckFramebufferStatus(GL_FRAMEBUFFER); // Bind main buffer glBindFramebuffer(GL_FRAMEBUFFER, 0); switch(status) { case GL_FRAMEBUFFER_COMPLETE: break; case GL_FRAMEBUFFER_UNSUPPORTED: BS_EXCEPT(InvalidParametersException, "All framebuffer formats with this texture internal format unsupported"); default: BS_EXCEPT(InvalidParametersException, "Framebuffer incomplete or other FBO status error"); } }
LEMON_UNITTEST_CASE(FileSystemUnittest,exist_Test) { String current = current_directory(); current_directory(current); LEMON_CHECK(current_directory() == current); String dirName = LEMON_TEXT("{C3F0C7DD-A2A8-42B5-BF87-277345DE9774}"); if(exists(dirName)) { if(is_directory(dirName)) remove_directories(dirName); else remove_file(dirName); } create_directory(dirName); LEMON_CHECK(exists(dirName)); const static size_t children = 100; for(size_t i = 0; i < children ; ++ i) { StringStream stream; stream << LEMON_TEXT("{C3F0C7DD-A2A8-42B5-BF87-277345DE9774}/") << i; String currentFile = stream.str(); create_directory(currentFile); LEMON_CHECK(exists(currentFile)); } directory_iteartor_t iter(dirName); directory_iteartor_t end; size_t i; for(i = 0;iter != end; ++ iter,++i) { if(LEMON_TEXT(".") == *iter) continue; if(LEMON_TEXT("..") == *iter) continue; String path = dirName + LEMON_TEXT("/") + *iter; remove_directory(path); LEMON_CHECK(!exists(path)); } LEMON_CHECK(children == (i - 2)); remove_directory(dirName); LEMON_CHECK(!exists(dirName)); }
string Layer::description() { StringStream os; os << "[Layer "<<(u64)this<<" '"<<name<<"']"; return os.str(); }
void write_stringstream(const StringStream& s, OutputStream& out) { out.write(s.str().c_str(), s.str().size()); }
bool Builder::run(const BuilderParams ¶ms) { mParams = params; collectFiles(); // initialize sc-memory sc_memory_params p; sc_memory_params_clear(&p); p.clear = mParams.clearOutput ? SC_TRUE : SC_FALSE; p.config_file = mParams.configFile.empty() ? 0 : mParams.configFile.c_str(); p.repo_path = mParams.outputPath.c_str(); p.ext_path = mParams.extensionsPath.size() > 0 ? mParams.extensionsPath.c_str() : 0; sc_memory_initialize(&p); mContext = sc_memory_context_new(sc_access_lvl_make_min); std::cout << "Build knowledge base from sources... " << std::endl; // process founded files uint32 done = 0, last_progress = -1; tFileSet::iterator it, itEnd = mFileSet.end(); for (it = mFileSet.begin(); it != itEnd; ++it) { uint32 progress = (uint32)(((float)++done / (float)mFileSet.size()) * 100); if (mParams.showFileNames) { std::cout << "[ " << progress << "% ] " << *it << std::endl; } else { if (last_progress != progress) { if (progress % 10 == 0) { std::cout << "[" << progress << "%]"; std::cout.flush(); } else { std::cout << "."; std::cout.flush(); } last_progress = progress; } } try { processFile(*it); } catch(const Exception &e) { StringStream ss; ss << e.getDescription() << " in " << e.getFileName() << " at line " << e.getLineNumber(); mErrors.push_back(ss.str()); } } std::cout << std::endl << "done" << std::endl; // print errors std::cout << std::endl << "-------" << std::endl << "Errors:" << std::endl; int idx = 1; tStringList::iterator itErr, itErrEnd = mErrors.end(); for (itErr = mErrors.begin(); itErr != itErrEnd; ++itErr) std::cout << "[" << idx++ << "]\t" << *itErr << std::endl; // print statistics sc_stat stat; sc_memory_stat(mContext, &stat); unsigned int all_count = stat.arc_count + stat.node_count + stat.link_count; std::cout << std::endl << "Statistics" << std::endl; std::cout << "Nodes: " << stat.node_count << "(" << ((float)stat.node_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Arcs: " << stat.arc_count << "(" << ((float)stat.arc_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Links: " << stat.link_count << "(" << ((float)stat.link_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Total: " << all_count << std::endl; sc_memory_context_free(mContext); sc_memory_shutdown(SC_TRUE); return true; }
String FileInfo::GetFullFilePath() const { StringStream ss; ss << _pathToDirectory << L"\\" << _filename; return ss.str(); }
String FilteredQuery::toString(const String& field) { StringStream buffer; buffer << L"filtered(" << query->toString(field) << L")->" << filter->toString() << boostString(); return buffer.str(); }
GpuProgramPtr GBufferMaterialGeneratorImpl::generateVertexShader(MaterialGenerator::Perm permutation) { StringStream ss; if(mIsGLSL) { ss << "#version 150" << std::endl; ss << "in vec4 vertex;" << std::endl; ss << "in vec3 normal;" << std::endl; uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8; for (uint32 i=0; i<numTexCoords; i++) { ss << "in vec2 uv" << i << ';' << std::endl; } if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << "in vec3 tangent;" << std::endl; } //TODO : Skinning inputs ss << std::endl; #ifdef WRITE_LINEAR_DEPTH ss << "out vec3 oViewPos;" << std::endl; #else ss << "out float oDepth;" << std::endl; #endif ss << "out vec3 oNormal;" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << "out vec3 oTangent;" << std::endl; ss << "out vec3 oBiNormal;" << std::endl; } for (uint32 i=0; i<numTexCoords; i++) { ss << "out vec2 oUv" << i << ";" << std::endl; } ss << std::endl; ss << "uniform mat4 cWorldViewProj;" << std::endl; ss << "uniform mat4 cWorldView;" << std::endl; ss << "void main()" << std::endl; ss << "{" << std::endl; ss << " gl_Position = cWorldViewProj * vertex;" << std::endl; ss << " oNormal = (cWorldView * vec4(normal,0)).xyz;" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " oTangent = (cWorldView * vec4(tangent,0)).xyz;" << std::endl; ss << " oBiNormal = cross(oNormal, oTangent);" << std::endl; } #ifdef WRITE_LINEAR_DEPTH ss << " oViewPos = (cWorldView * vertex).xyz;" << std::endl; #else ss << " oDepth = gl_Position.w;" << std::endl; #endif for (uint32 i=0; i<numTexCoords; i++) { ss << " oUv" << i << " = uv" << i << ';' << std::endl; } ss << "}" << std::endl; String programSource = ss.str(); String programName = mBaseName + "VP_" + StringConverter::toString(permutation); #if OGRE_DEBUG_MODE LogManager::getSingleton().getDefaultLog()->logMessage(programSource); #endif // Create shader object HighLevelGpuProgramPtr ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram(programName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", GPT_VERTEX_PROGRAM); ptrProgram->setSource(programSource); ptrProgram->setParameter("syntax", "glsl150"); const GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters(); params->setNamedAutoConstant("cWorldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); params->setNamedAutoConstant("cWorldView", GpuProgramParameters::ACT_WORLDVIEW_MATRIX); ptrProgram->load(); return GpuProgramPtr(ptrProgram); } else {