VariableIdSet AnalysisAbstractionLayer::astSubTreeVariables(SgNode* node, VariableIdMapping& vidm) {
  VariableIdSet vset;
  RoseAst ast(node);
  for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) {
    VariableId vid; // default creates intentionally an invalid id.
    if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) {
      vid=vidm.variableId(varDecl);
    } else if(SgVarRefExp* varRefExp=isSgVarRefExp(*i)) {
      vid=vidm.variableId(varRefExp);
    } else if(SgInitializedName* initName=isSgInitializedName(*i)) {
      vid=vidm.variableId(initName);
    }
    if(vid.isValid())
      vset.insert(vid);
  }
  return vset;
}
Esempio n. 2
0
bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds) {
    if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffectReadDstColor()) {
        return true;
    }
    GrRenderTarget* rt = this->drawState()->getRenderTarget();
    SkIRect copyRect;
    const GrClipData* clip = this->getClip();
    clip->getConservativeBounds(rt, &copyRect);

    if (drawBounds) {
        SkIRect drawIBounds;
        drawBounds->roundOut(&drawIBounds);
        if (!copyRect.intersect(drawIBounds)) {
#ifdef SK_DEBUG
            GrPrintf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
#endif
            return false;
        }
    } else {
#ifdef SK_DEBUG
        //GrPrintf("No dev bounds when dst copy is made.\n");
#endif
    }

    // MSAA consideration: When there is support for reading MSAA samples in the shader we could
    // have per-sample dst values by making the copy multisampled.
    GrTextureDesc desc;
    this->initCopySurfaceDstDesc(rt, &desc);
    desc.fWidth = copyRect.width();
    desc.fHeight = copyRect.height();

    GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch);

    if (NULL == ast.texture()) {
        GrPrintf("Failed to create temporary copy of destination texture.\n");
        return false;
    }
    SkIPoint dstPoint = {0, 0};
    if (this->copySurface(ast.texture(), rt, copyRect, dstPoint)) {
        dstCopy->setTexture(ast.texture());
        dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
        return true;
    } else {
        return false;
    }
}
Esempio n. 3
0
bool
AstMatching::performSingleMatch(SgNode* node, MatchOperationList* matchOperationSequence) {
  if(matchOperationSequence==0) {
    std::cerr << "matchOperationSequence==0. Bailing out." <<std::endl;
    exit(1);
  }
  if(_status.debug) 
    std::cout << "perform-single-match:"<<std::endl;    
  SingleMatchResult smr; // we intentionally avoid dynamic allocation for var-bindings of a single pattern
  RoseAst ast(node);
  RoseAst::iterator pattern_ast_iter=ast.begin().withNullValues();
  if(_status.debug) 
    std::cout << "single-match-start:"<<std::endl;    
  bool tmpresult=matchOperationSequence->performOperation(_status, pattern_ast_iter, smr);
  if(_status.debug) 
    std::cout << "single-match-end"<<std::endl;    
  if(tmpresult)
    _status.mergeSingleMatchResult(smr);
  return tmpresult;
}
Esempio n. 4
0
std::shared_ptr<AST> AST::create(const Source &source, const String &sourceCode, CXTranslationUnit unit)
{
    std::shared_ptr<AST> ast(new AST);
    ast->mState.reset(new sel::State {true});
    sel::State &state = *ast->mState;
    registerClasses(state);
    ast->mSourceCode = sourceCode;
    state["sourceFile"] = source.sourceFile().ref();
    state["sourceCode"] = sourceCode.ref();
    state["write"] = [ast](const std::string &str) {
        // error() << "writing" << str;
        ast->mReturnValues.append(str);
    };

    exposeArray(state["commandLine"], source.toCommandLine(Source::Default|Source::IncludeCompiler|Source::IncludeSourceFile));

    if (unit) {
        UserData userData;
        userData.ast = ast.get();
        visitor(clang_getTranslationUnitCursor(unit), clang_getNullCursor(), &userData);

        const Cursor root = userData.parents.front();
        state["root"] = [root]() { return root; };
        state["findByUsr"] = [ast](const std::string &usr) {
            return ast->mByUsr.value(usr);
        };

        state["findByOffset"] = [ast](const std::string &str) {
            // int offset = atoi(str.c_str());
            // if (offset) {

            // } else
            // sscanf
            // return mByUsr.value(usr);
        };
        const String script = Path(TO_STR(RTAGS_SOURCE_DIR) "/rtags.lua").readAll();
        state(script.constData());
    }
    return ast;
}
Esempio n. 5
0
TEST_F(QueryTest, testAttributes) {
  static const char *args[] = {"SCHEMA", "title", "text", "body", "text"};
  QueryError err = {QUERY_OK};
  IndexSpec *spec = IndexSpec_Parse("idx", args, sizeof(args) / sizeof(const char *), &err);
  RedisSearchCtx ctx = SEARCH_CTX_STATIC(NULL, spec);

  const char *qt =
      "(@title:(foo bar) => {$weight: 0.5} @body:lol => {$weight: 0.2}) => "
      "{$weight:0.3; $slop:2; $inorder:true}";
  QASTCXX ast(ctx);
  ASSERT_TRUE(ast.parse(qt)) << ast.getError();
  QueryNode *n = ast.root;
  ASSERT_EQ(0.3, n->opts.weight);
  ASSERT_EQ(2, n->opts.maxSlop);
  ASSERT_EQ(1, n->opts.inOrder);

  ASSERT_EQ(n->type, QN_PHRASE);
  ASSERT_EQ(QueryNode_NumChildren(n), 2);
  ASSERT_EQ(0.5, n->children[0]->opts.weight);
  ASSERT_EQ(0.2, n->children[1]->opts.weight);
  IndexSpec_Free(ctx.spec);
}
Esempio n. 6
0
static ASTPtr parseWords(const char** fptr, const char*** wordSourcesPtr) {
  assert(**fptr == '{');
  Words* words = new Words(*fptr, **wordSourcesPtr);
  ++*wordSourcesPtr;
  ASTPtr ast(words);
  ++*fptr;
  parseWhitespaces(fptr); // { is a token
  if (**fptr == 'w') {
    ++*fptr;
    parseWhitespaces(fptr); // w is a token
    if (**fptr == '-') {
      words->wordSilhouette = parseSilhouetteCharLiteral(fptr);
    }
    parseFillers(fptr, &words->interwordFillers);
  } else {
    throw DSLException(*fptr, "Expected w after {.");
  }
  if (**fptr != '}') {
    throw DSLException(*fptr, "Expected }, ->, or interword fillers.");
  }
  ++*fptr;
  parseWhitespaces(fptr); // } is a token
  return ast;
}
Esempio n. 7
0
bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
                                           const SkBitmap& src,
                                           const Context& ctx,
                                           SkBitmap* result,
                                           SkIPoint* offset) const {
    SkBitmap background = src;
    SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
    if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &background,
                                                       &backgroundOffset)) {
        return onFilterImage(proxy, src, ctx, result, offset);
    }
    GrTexture* backgroundTex = background.getTexture();
    SkBitmap foreground = src;
    SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
    if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground,
                                                       &foregroundOffset)) {
        return onFilterImage(proxy, src, ctx, result, offset);
    }
    GrTexture* foregroundTex = foreground.getTexture();
    GrContext* context = foregroundTex->getContext();

    GrEffect* xferEffect = NULL;

    GrTextureDesc desc;
    desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
    desc.fWidth = src.width();
    desc.fHeight = src.height();
    desc.fConfig = kSkia8888_GrPixelConfig;

    GrAutoScratchTexture ast(context, desc);
    if (NULL == ast.texture()) {
        return false;
    }
    SkAutoTUnref<GrTexture> dst(ast.detach());

    GrContext::AutoRenderTarget art(context, dst->asRenderTarget());

    if (!fMode || !fMode->asNewEffect(&xferEffect, backgroundTex)) {
        // canFilterImageGPU() should've taken care of this
        SkASSERT(false);
        return false;
    }

    SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foregroundTex);
    foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOffset.fX),
                                  SkIntToScalar(backgroundOffset.fY-foregroundOffset.fY));


    SkRect srcRect;
    src.getBounds(&srcRect);

    GrPaint paint;
    paint.addColorTextureEffect(foregroundTex, foregroundMatrix);
    paint.addColorEffect(xferEffect)->unref();
    context->drawRect(paint, srcRect);

    offset->fX = backgroundOffset.fX;
    offset->fY = backgroundOffset.fY;
    WrapTexture(dst, src.width(), src.height(), result);
    return true;
}
int main(int argc, char **argv)
{
    Action action = ACTION_UNKNOWN;
    int retval = 1;
    const char *infile = NULL;
    const char *outfile = NULL;
    int i;

    MOJOSHADER_preprocessorDefine *defs = NULL;
    unsigned int defcount = 0;

    include_paths = (const char **) malloc(sizeof (char *));
    include_paths[0] = ".";
    include_path_count = 1;

    // !!! FIXME: clean this up.
    for (i = 1; i < argc; i++)
    {
        const char *arg = argv[i];

        if (strcmp(arg, "-P") == 0)
        {
            if ((action != ACTION_UNKNOWN) && (action != ACTION_PREPROCESS))
                fail("Multiple actions specified");
            action = ACTION_PREPROCESS;
        } // if

        else if (strcmp(arg, "-A") == 0)
        {
            if ((action != ACTION_UNKNOWN) && (action != ACTION_ASSEMBLE))
                fail("Multiple actions specified");
            action = ACTION_ASSEMBLE;
        } // else if

        else if (strcmp(arg, "-T") == 0)
        {
            if ((action != ACTION_UNKNOWN) && (action != ACTION_AST))
                fail("Multiple actions specified");
            action = ACTION_AST;
        } // else if

        else if (strcmp(arg, "-C") == 0)
        {
            if ((action != ACTION_UNKNOWN) && (action != ACTION_COMPILE))
                fail("Multiple actions specified");
            action = ACTION_COMPILE;
        } // else if

        else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
        {
            if ((action != ACTION_UNKNOWN) && (action != ACTION_VERSION))
                fail("Multiple actions specified");
            action = ACTION_VERSION;
        } // else if

        else if (strcmp(arg, "-o") == 0)
        {
            if (outfile != NULL)
                fail("multiple output files specified");

            arg = argv[++i];
            if (arg == NULL)
                fail("no filename after '-o'");
            outfile = arg;
        } // if

        else if (strcmp(arg, "-I") == 0)
        {
            arg = argv[++i];
            if (arg == NULL)
                fail("no path after '-I'");

            include_paths = (const char **) realloc(include_paths,
                       (include_path_count+1) * sizeof (char *));
            include_paths[include_path_count] = arg;
            include_path_count++;
        } // if

        else if (strncmp(arg, "-D", 2) == 0)
        {
            arg += 2;
            char *ident = strdup(arg);
            char *ptr = strchr(ident, '=');
            const char *val = "";
            if (ptr)
            {
                *ptr = '\0';
                val = ptr+1;
            } // if

            defs = (MOJOSHADER_preprocessorDefine *) realloc(defs,
                       (defcount+1) * sizeof (MOJOSHADER_preprocessorDefine));
            defs[defcount].identifier = ident;
            defs[defcount].definition = val;
            defcount++;
        } // else if

        else
        {
            if (infile != NULL)
                fail("multiple input files specified");
            infile = arg;
        } // else
    } // for

    if (action == ACTION_UNKNOWN)
        action = ACTION_ASSEMBLE;

    if (action == ACTION_VERSION)
    {
        printf("mojoshader-compiler, changeset %s\n", MOJOSHADER_CHANGESET);
        return 0;
    } // if

    if (infile == NULL)
        fail("no input file specified");

    FILE *io = fopen(infile, "rb");
    if (io == NULL)
        fail("failed to open input file");

    fseek(io, 0, SEEK_END);
    long fsize = ftell(io);
    fseek(io, 0, SEEK_SET);
    if (fsize == -1)
        fsize = 1000000;
    char *buf = (char *) malloc(fsize);
    const int rc = fread(buf, 1, fsize, io);
    fclose(io);
    if (rc == EOF)
        fail("failed to read input file");

    FILE *outio = outfile ? fopen(outfile, "wb") : stdout;
    if (outio == NULL)
        fail("failed to open output file");


    if (action == ACTION_PREPROCESS)
        retval = (!preprocess(infile, buf, rc, outfile, defs, defcount, outio));
    else if (action == ACTION_ASSEMBLE)
        retval = (!assemble(infile, buf, rc, outfile, defs, defcount, outio));
    else if (action == ACTION_AST)
        retval = (!ast(infile, buf, rc, outfile, defs, defcount, outio));
    else if (action == ACTION_COMPILE)
        retval = (!compile(infile, buf, rc, outfile, defs, defcount, outio));

    if ((retval != 0) && (outfile != NULL))
        remove(outfile);

    free(buf);

    for (i = 0; i < defcount; i++)
        free((void *) defs[i].identifier);
    free(defs);

    free(include_paths);

    return retval;
} // main
Esempio n. 9
0
void ClientGame::processMessage(MessagePtr msg)
{
    switch(msg->getType())
    {
    case MessageType::SRV_ASTEROID_SPAWN:
    {
        print("ClientGame: spawning asteroid\n");
        AsteroidSpawnMessage *spawn_msg = static_cast<AsteroidSpawnMessage*>(msg.get());
        AsteroidPtr ast(new Asteroid(this, spawn_msg->getData(), asteroid_data));
        entities.push_back(ast);
        asteroids.push_back(ast);
    }
    break;
    case MessageType::SRV_SHIP_SPAWN:
    {
        ShipSpawnMessage *spawn_msg = static_cast<ShipSpawnMessage*>(msg.get());
        const ShipSpawnData &d = spawn_msg->getData();

        ShipPtr ship(new Ship(this, d));
        entities.push_back(ship);
        ships.push_back(ship);

        print(format("ClientGame: spawning ship id=%1% name=%2%\n") % ship->getID() % ship->getName());
    }
    break;
    case MessageType::SRV_BULLET_SPAWN:
    {
        BulletSpawnMessage *spawn_msg = static_cast<BulletSpawnMessage*>(msg.get());
        const BulletSpawnData &d = spawn_msg->getData();

        BulletPtr bullet(new Bullet(this, d));
        entities.push_back(bullet);
        if(Audio::distToListener(d.state.position) < 200.0f)
            Audio::playSFX("sounds/laser0.wav", false, d.state.position, 0.5f, 10.0f);
        print(format("ClientGame: spawning bullet id=%1%\n") % bullet->getID());
    }
    break;
    case MessageType::SRV_SHIP_STATE:
    {
        ShipStateMessage *state_msg = static_cast<ShipStateMessage*>(msg.get());
        int id = state_msg->getEntityID();

        //print(format("ClientGame: received ship state data for ship id=%1%\n") % id);

        //TODO use a map?
        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == id)
            {
                ships[i]->setStateData(state_msg->getData());
                break;
            }
    }
    break;
    case MessageType::SRV_SHIP_OWNER:
    {
        ShipOwnerMessage *owner_msg = static_cast<ShipOwnerMessage*>(msg.get());
        print("owner message\n");

        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == owner_msg->getData().ship_id)
            {
                print("owner message\n");
                player_ship = ships[i];
                ship_cam->setShip(player_ship);
                break;
            }
    }
    case MessageType::SRV_ASTEROID_STATE:
    {
        AsteroidStateMessage *state_msg = static_cast<AsteroidStateMessage*>(msg.get());
        int id = state_msg->getEntityID();

        //print(format("ClientGame: received asteroid state data for asteroid id=%1%\n") % id);

        for(unsigned int i = 0; i < asteroids.size(); i++)
            if(asteroids[i]->getID() == id)
            {
                asteroids[i]->setStateData(state_msg->getData());
                break;
            }
    }
    break;
    case MessageType::SRV_ENTITY_DELETE:
    {
        print("ClientGame: deleting entity\n");
        EntityDeleteMessage *delete_msg = static_cast<EntityDeleteMessage*>(msg.get());
        int id = delete_msg->getData().entity_id;

        for(unsigned int i = 0; i < entities.size(); i++)
            if(entities[i]->getID() == id)
            {
                entities[i]->die();
                entities.erase(entities.begin()+i);
                break;
            }

        if(player_ship && id == player_ship->getID())
            player_ship.reset();

        //TODO do this properly
        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == id)
            {
                cml::vector2f pos = ships[i]->getPosition();
                cml::vector3f col1(ships[i]->getBodyColor().data());
                cml::vector3f col2 = cml::vector3f(0.0f, 0.0f, 0.0f);
                ExplosionEmitterPtr e(new ExplosionEmitter(pos, col1, col2, 40, 50.0f, 1.6f));
                particle_system->addEmitter(e);
                if(Audio::distToListener(pos) < 200.0f)
                    Audio::playSFX("sounds/explosion0.wav", false, pos, 0.1f, 10.0f);

                ships.erase(ships.begin()+i);
                break;
            }

        for(unsigned int i = 0; i < asteroids.size(); i++)
            if(asteroids[i]->getID() == id)
            {
                AsteroidPtr a = asteroids[i];
                if(a->getBounds().intersects(game_bounds))
                {
                    cml::vector2f pos = a->getPosition();
                    cml::vector3f col1 = cml::vector3f(1.0f, 0.0f, 0.0f);
                    cml::vector3f col2 = cml::vector3f(0.1f, 0.0f, 0.0f);
                    ExplosionEmitterPtr e(new ExplosionEmitter(pos, col1, col2, 50, 30.0f, 1.6f));
                    particle_system->addEmitter(e);

                    col1.set(0.2f, 0.2f, 0.0f);
                    col2.set(0.0f, 0.0f, 0.0f);
                    ExplosionEmitterQuadsPtr e2(new ExplosionEmitterQuads(pos, col1, col2, 30, 20.0f, 1.6f));
                    particle_system->addEmitter(e2);

                    if(Audio::distToListener(pos) < 300.0f)
                        Audio::playSFX(asteroid_explosions[rand()%asteroid_explosions.size()], false, pos, 0.01f, 1.0f);
                }
                asteroids.erase(asteroids.begin()+i);
                break;
            }

        /*
        for(unsigned int i = 0; i < bullets.size(); i++)
            if(bullets[i]->getID() == id)
            {
                bullets.erase(bullets.begin()+i);
                break;
            }
        */
    }
    break;
    case MessageType::SRV_SCORE:
    {
        ScoreMessage *score_msg = static_cast<ScoreMessage*>(msg.get());
        scores = score_msg->getData();
    }
    break;
    default:
        break;
    }
}
bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
                                           const SkBitmap& src,
                                           const SkMatrix& ctm,
                                           SkBitmap* result,
                                           SkIPoint* offset) {
    SkBitmap background;
    SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
    if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &background,
                                               &backgroundOffset)) {
        return false;
    }
    GrTexture* backgroundTex = background.getTexture();
    SkBitmap foreground;
    SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
    if (!SkImageFilterUtils::GetInputResultGPU(getInput(1), proxy, src, ctm, &foreground,
                                               &foregroundOffset)) {
        return false;
    }
    GrTexture* foregroundTex = foreground.getTexture();
    GrContext* context = foregroundTex->getContext();

    GrEffectRef* xferEffect = NULL;

    GrTextureDesc desc;
    desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
    desc.fWidth = src.width();
    desc.fHeight = src.height();
    desc.fConfig = kSkia8888_GrPixelConfig;

    GrAutoScratchTexture ast(context, desc);
    SkAutoTUnref<GrTexture> dst(ast.detach());

    GrContext::AutoRenderTarget art(context, dst->asRenderTarget());

    SkXfermode::Coeff sm, dm;
    if (!SkXfermode::AsNewEffectOrCoeff(fMode, &xferEffect, &sm, &dm, backgroundTex)) {
        return false;
    }

    SkMatrix foregroundMatrix = GrEffect::MakeDivByTextureWHMatrix(foregroundTex);
    foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOffset.fX),
                                  SkIntToScalar(backgroundOffset.fY-foregroundOffset.fY));


    SkRect srcRect;
    src.getBounds(&srcRect);
    if (NULL != xferEffect) {
        GrPaint paint;
        paint.addColorTextureEffect(foregroundTex, foregroundMatrix);
        paint.addColorEffect(xferEffect)->unref();
        context->drawRect(paint, srcRect);
    } else {
        GrPaint backgroundPaint;
        SkMatrix backgroundMatrix = GrEffect::MakeDivByTextureWHMatrix(backgroundTex);
        backgroundPaint.addColorTextureEffect(backgroundTex, backgroundMatrix);
        context->drawRect(backgroundPaint, srcRect);

        GrPaint foregroundPaint;
        foregroundPaint.setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm));
        foregroundPaint.addColorTextureEffect(foregroundTex, foregroundMatrix);
        context->drawRect(foregroundPaint, srcRect);
    }
    offset->fX += backgroundOffset.fX;
    offset->fY += backgroundOffset.fY;
    return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), result);
}
Esempio n. 11
0
/*****************************************************************************
	受信結果処理
*****************************************************************************/
void CGainer::processEvent(const std::string &event)
{
	if ( event.length() == 0 ) {
		return;
	}

	switch(event[0])
	{
	case '!': // something wrong
		break;

	case 'h': // led on
		m_led = true;
		break;

	case 'l': // led off
		m_led = false;
		break;

	case 'N': // button pressed
		execute_sstp_button(true);
		break;
	case 'F': // button released
		execute_sstp_button(false);
		break;

	case 'i':
	case 'I':
		{ // analog_input
			std::string::size_type ast(event.find('*'));
			std::string s(event.substr(1, ast-1));
			
			int ai[GAINER_MAX_INPUTS];
			
			if ( CONFIG[m_config][AIN] == 4 ) {
				sscanf(s.c_str(), "%02X%02X%02X%02X",
					&ai[0], &ai[1],&ai[2], &ai[3]);
				
				for ( int i = 0 ; i < 4 ; ++i ) {
					m_analogInputs[i] = static_cast<BYTE>(ai[i]);
				}
			}
			else if ( CONFIG[m_config][AIN] == 8 ) {
				sscanf(s.c_str(), "%02X%02X%02X%02X%02X%02X%02X%02X",
					&ai[0], &ai[1],&ai[2], &ai[3], 
					&ai[4], &ai[5],&ai[6], &ai[7] );
				
				for ( int i = 0 ; i < 8 ; ++i ) {
					m_analogInputs[i] = static_cast<BYTE>(ai[i]);
				}
			}

			if ( event[0] == 'i' ) {
				execute_sstp_analog();
			}
		}
		break;

	case 'r':
	case 'R':
		{ // digital input
			std::string::size_type ast(event.find('*'));
			std::string s(event.substr(1, ast-1));
			sscanf(s.c_str(),"%04X",&m_digitalInputs);
			
			if ( event[0] == 'r' ) {
				execute_sstp_digital();
			}
		}
		break;

	default:
		break;
	}

	char c = event[0];

	if ( c != 'r' && c != 'i' && c != 'N' && c != 'F' ) {
		if ( ! (m_config == 7 && c == 'a') ) {
			EnterCriticalSection(&m_receive_queue_lock);
			m_receive_queue.push(event);
			ReleaseSemaphore(m_receive_queue_semaphore,1,NULL);
			LeaveCriticalSection(&m_receive_queue_lock);
		}
	}
}
Esempio n. 12
0
TEST(bash_ast, parse_illegal_script)
{
  EXPECT_THROW(bash_ast ast(get_src_dir() + std::string("/scripts/illegal_script.sh")), libbash::parse_exception);
}
Esempio n. 13
0
void Ide::SetupFormat() {
	FormatDlg dlg;
	dlg.Title("Format setup");
	WithSetupFontLayout<ParentCtrl> fnt;
	WithSetupHlLayout<ParentCtrl> hlt;
	WithSetupEditorLayout<ParentCtrl> edt;
	WithSetupIdeLayout<ParentCtrl> ide;
	WithSetupAssistLayout<ParentCtrl> assist;
	WithSetupMobilePlatformsLayout<ParentCtrl> mobile;
	AStyleSetupDialog ast(this);
#ifdef PLATFORM_WIN32
	ide.console_txt.Hide();
	ide.console.Hide();
	ide.kde.Hide();
	ide.gnome.Hide();
	ide.xterm.Hide();
	ide.mate.Hide();
	
#endif
	ide.kde <<= callback2(SetConsole, &ide.console, "/usr/bin/konsole -e");
	ide.gnome <<= callback2(SetConsole, &ide.console, "/usr/bin/gnome-terminal -x");
	ide.mate <<= callback2(SetConsole, &ide.console, "/usr/bin/mate-terminal -x");
	ide.xterm <<= callback2(SetConsole, &ide.console, "/usr/bin/xterm -e");
	
	edt.lineends
		.Add(LF, "LF")
		.Add(CRLF, "CRLF")
		.Add(DETECT_LF, "Detect with default LF")
		.Add(DETECT_CRLF, "Detect with default CRLF");
	
	edt.filetabs
		.Add(AlignedFrame::LEFT, "Left")
		.Add(AlignedFrame::TOP, "Top")
		.Add(AlignedFrame::RIGHT, "Right")
		.Add(AlignedFrame::BOTTOM, "Bottom")
		.Add(-1, "Off");
		
	edt.tabs_crosses
		.Add(AlignedFrame::LEFT, "Left")
		.Add(AlignedFrame::RIGHT, "Right")
		.Add(-1, "Off");
	
	dlg.Add(fnt, "Fonts");
	dlg.Add(hlt, "Syntax highlighting");
	dlg.Add(edt, "Editor");
	dlg.Add(assist, "Assist");
	dlg.Add(ide, "IDE");
	dlg.Add(ast, "Code formatting");
	dlg.Add(mobile, "Mobile platforms");
	dlg.WhenClose = dlg.Acceptor(IDEXIT);
	FontSelectManager ed, vf, con, f1, f2, tf;
	ed.Set(fnt.face, fnt.height, fnt.bold, fnt.italic, fnt.naa);
	vf.Set(fnt.vface, fnt.vheight, fnt.vbold, fnt.vitalic, fnt.vnaa);
	con.Set(fnt.cface, fnt.cheight, fnt.cbold, fnt.citalic, fnt.cnaa);
	tf.Set(fnt.tface, fnt.theight, fnt.tbold, fnt.titalic, fnt.tnaa);
	f1.Set(fnt.face1, fnt.height1, fnt.bold1, fnt.italic1, fnt.naa1);
	f2.Set(fnt.face2, fnt.height2, fnt.bold2, fnt.italic2, fnt.naa2);
	ed.Set(editorfont);
	vf.Set(veditorfont);
	con.Set(consolefont);
	tf.Set(tfont);
	f1.Set(font1);
	f2.Set(font2);
	DlCharset(edt.charset);
	edt.tabsize.MinMax(1, 100).NotNull();
	edt.tabsize <<= editortabsize;
	edt.indent_amount.MinMax(1, 100).NotNull();
	edt.indent_amount <<= indent_spaces ? indent_amount : editortabsize;
	edt.indent_amount.Enable(indent_spaces);
	CtrlRetriever rtvr;
	int hs = hilite_scope;
	rtvr
		(hlt.hilite_scope, hs)
		(hlt.hilite_bracket, hilite_bracket)
		(hlt.hilite_ifdef, hilite_ifdef)
		(hlt.hilite_if_endif, hilite_if_endif)
		(hlt.thousands_separator, thousands_separator)
		(hlt.hline, hline)

		(edt.indent_spaces, indent_spaces)
		(edt.no_parenthesis_indent, no_parenthesis_indent)
		(edt.showtabs, show_tabs)
		(edt.warnwhitespace, warnwhitespace)
		(edt.lineends, line_endings)
		(edt.numbers, line_numbers)
		(edt.bookmark_pos, bookmark_pos)
		(edt.bordercolumn, bordercolumn)
		(edt.bordercolor, bordercolor)
		(edt.findpicksel, find_pick_sel)
		(edt.findpicktext, find_pick_text)
		(edt.deactivate_save, deactivate_save)
		(edt.filetabs, filetabs)
		(edt.tabs_icons, tabs_icons)
		(edt.tabs_crosses, tabs_crosses)
		(edt.tabs_grouping, tabs_grouping)
		(edt.tabs_stacking, tabs_stacking)
		(edt.tabs_serialize, tabs_serialize)
		(edt.persistent_find_replace, persistent_find_replace)
		(edt.find_replace_restore_pos, find_replace_restore_pos)

		(assist.barline, barline)
		(assist.auto_enclose, auto_enclose)
		(assist.commentdp, editor.commentdp)
		(assist.header_guards, header_guards)
		(assist.insert_include, insert_include)
		(assist.mark_lines, mark_lines)
		(assist.qtfsel, qtfsel)
		(assist.assist, editor.auto_assist)

		(ide.showtime, showtime)
		(ide.show_status_bar, show_status_bar)
		(ide.toolbar_in_row, toolbar_in_row)
		(ide.splash_screen, splash_screen)
		(ide.sort, sort)
		(ide.mute_sounds, mute_sounds)
		(ide.wrap_console_text, wrap_console_text)
		(ide.hydra1_threads, hydra1_threads)
		(ide.gdbSelector, gdbSelector)
		(ide.chstyle, chstyle)
		(ide.console, LinuxHostConsole)
		(ide.output_per_assembly, output_per_assembly)

		(ast.BracketIndent,					astyle_BracketIndent)
		(ast.NamespaceIndent,               astyle_NamespaceIndent)
		(ast.BlockIndent,                   astyle_BlockIndent)
		(ast.CaseIndent,                    astyle_CaseIndent)
		(ast.ClassIndent,                   astyle_ClassIndent)
		(ast.LabelIndent,                   astyle_LabelIndent)
		(ast.SwitchIndent,                  astyle_SwitchIndent)
		(ast.PreprocessorIndent,            astyle_PreprocessorIndent)
		(ast.MinInStatementIndentLength,    astyle_MinInStatementIndentLength)
		(ast.MaxInStatementIndentLength,    astyle_MaxInStatementIndentLength)
		(ast.BreakClosingHeaderBracketsMode,astyle_BreakClosingHeaderBracketsMode)
		(ast.BreakElseIfsMode,              astyle_BreakElseIfsMode)
		(ast.BreakOneLineBlocksMode,        astyle_BreakOneLineBlocksMode)
		(ast.SingleStatementsMode,          astyle_SingleStatementsMode)
		(ast.BreakBlocksMode,               astyle_BreakBlocksMode)
		(ast.BreakClosingHeaderBlocksMode,  astyle_BreakClosingHeaderBlocksMode)
		(ast.BracketFormatMode,             astyle_BracketFormatMode)
		(ast.ParensPaddingMode,             astyle_ParensPaddingMode)
		(ast.ParensUnPaddingMode,           astyle_ParensUnPaddingMode)
		(ast.OperatorPaddingMode,           astyle_OperatorPaddingMode)
		(ast.EmptyLineFill,                 astyle_EmptyLineFill)
		(ast.TabSpaceConversionMode,        astyle_TabSpaceConversionMode)
		(ast.TestBox,						astyle_TestBox)
		
		(mobile.AndroidSDKPath, androidSDKPath)
	;
	hlt.hlstyle.AddColumn("Style");
	hlt.hlstyle.AddColumn("Color").Ctrls(HlPusherFactory);
	hlt.hlstyle.AddColumn("Bold").Ctrls<Option>();
	hlt.hlstyle.AddColumn("Italic").Ctrls<Option>();
	hlt.hlstyle.AddColumn("Underline").Ctrls<Option>();
	hlt.hlstyle.ColumnWidths("211 80 45 45 80");
	hlt.hlstyle.EvenRowColor().NoHorzGrid().SetLineCy(EditField::GetStdHeight() + 2);
	ReadHlStyles(hlt.hlstyle);
	edt.charset <<= (int)default_charset;
	edt.tabsize <<= rtvr <<=
		hlt.hlstyle.WhenCtrlsAction = ed.WhenAction = tf.WhenAction =
		con.WhenAction = f1.WhenAction = f2.WhenAction = dlg.Breaker(222);
	ide.showtimeafter <<= Nvl((Date)FileGetTime(ConfigFile("version")), GetSysDate() - 1);
	hlt.hl_restore <<= dlg.Breaker(333);
	ide.chstyle.Add(0, "Host platform");
	ide.chstyle.Add(1, "Standard");
	ide.chstyle.Add(2, "Classic");
	ide.chstyle.Add(3, "Host platform, blue bars");
	ide.chstyle.Add(4, "Standard, blue bars");

	FrameRight<Button> uscBrowse;
	uscBrowse.SetImage(CtrlImg::right_arrow());
	uscBrowse <<= callback1(AddPath, &ide.uscpath);
	ide.uscpath.AddFrame(uscBrowse);
	ide.uscpath <<= LoadFile(GetHomeDirFile("usc.path"));
	
	FrameRight<Button> androidSDKDownload;
	androidSDKDownload.SetImage(IdeImg::DownloadBlack());
	androidSDKDownload.Tip("Download");
	androidSDKDownload <<= callback1(LaunchWebBrowser, AndroidSDK::GetDownloadUrl());
	mobile.AndroidSDKPath.AddFrame(androidSDKDownload);
	
	FrameRight<Button> androidSDKBrowse;
	androidSDKBrowse.SetImage(CtrlImg::right_arrow());
	androidSDKBrowse.Tip("Select directory");
	androidSDKBrowse <<= callback1(InsertPath, &mobile.AndroidSDKPath);
	mobile.AndroidSDKPath.AddFrame(androidSDKBrowse);
	mobile.AndroidSDKPath <<= androidSDKPath;
	
	for(;;) {
		int c = dlg.Run();
		Upp::SaveFile(GetHomeDirFile("usc.path"), ~ide.uscpath);
		editorfont = ed.Get();
		tfont = tf.Get();
		veditorfont = vf.Get();
		consolefont = con.Get();
		font1 = f1.Get();
		font2 = f2.Get();
		editortabsize = Nvl((int)~edt.tabsize, 4);
		rtvr.Retrieve();
		console.SetSlots(minmax(hydra1_threads, 1, 256));
		hilite_scope = hs;
		if(indent_spaces)
			indent_amount = ~edt.indent_amount;
		else {
			indent_amount = editortabsize;
			edt.indent_amount <<= editortabsize;
		}
		edt.indent_amount.Enable(indent_spaces);
		default_charset = (byte)(int)~edt.charset;
		for(int i = 0; i < CodeEditor::HL_COUNT; i++)
			editor.SetHlStyle(i, hlt.hlstyle.Get(i, 1), hlt.hlstyle.Get(i, 2),
			                     hlt.hlstyle.Get(i, 3), hlt.hlstyle.Get(i, 4));
		UpdateFormat();
		if(c == IDEXIT)
			break;
		if(c == 333 && PromptYesNo("Restore default highlighting colors?")) {
			editor.DefaultHlStyles();
			ReadHlStyles(hlt.hlstyle);
		}
	}
	FileSetTime(ConfigFile("version"), ToTime(~ide.showtimeafter));
	FinishConfig();
	SaveConfig();
}
Esempio n. 14
0
int main(int argc, char** argv) {
  
  llvm::cl::ParseCommandLineOptions(argc, argv, "");
  
  clock_t start,end;
  start = clock();
  
  
  // generate cross reference info
  clang::idx::Program Prog;
  clang::idx::Indexer Idxer(Prog);
  
  
  std::ifstream inf(InputFilename.c_str(), std::ios::in);
  std::cout << InputFilename << " read." <<std::endl;
  std::vector<std::string> lines;
  std::string line;
  
  while(getline(inf, line)) lines.push_back(line);
  
  inf.close();
  std::vector<clang::ASTUnit*> astList;
  
  std::vector<std::string>::iterator itr;
  for(itr=lines.begin();itr!=lines.end();++itr) {
    std::cout << itr->c_str() << std::endl;
    const char* inputs[] = {argv[0],itr->c_str()};
    llvm::OwningPtr<clang::ASTUnit>  ast(generateASTUnitFromSource(inputs));
    astList.push_back(ast.take());
  }

  std::cout <<  "loaded TU size: " << astList.size() << std::endl;
  for (unsigned i = 0, e = astList.size(); i != e; ++i) {
    std::cout <<  "load astList[" << i << "]" ;
    std::cout.flush();
    
    ASTUnitTU *TU = new ASTUnitTU(astList[i]);
    Idxer.IndexAST(TU);
    std::cout <<  "... OK!" << std::endl;
  }
  
  clang::idx::Analyzer* analyzer = new clang::idx::Analyzer(Idxer.getProgram(),Idxer);

  // get Entity  
  clang::idx::Entity Ent =
  	clang::idx::Entity::get("a", Idxer.getProgram());
  std::cout << Ent.getPrintableName() << std::endl;
  
  //clang::FunctionDecl *FD;
  for (unsigned i = 0, e = astList.size(); i != e; ++i) {
    auto decl = Ent.getDecl(astList[i]->getASTContext());
    if (decl) {
      std::cout << "found!" << std::endl;
      Handler* handler = new Handler();
      analyzer->FindReferences(decl,*handler);
      return 0;
    }
  }
  
  //clang::idx::TranslationUnit *TU;
  //llvm::tie(FD, TU) = Idxer.getDefinitionFor(Ent);
  
  
  
  
  end = clock();
  printf("%.2f second spend.\n",(double)(end-start)/CLOCKS_PER_SEC);
  
  return 0;
}