Beispiel #1
0
// Load the key-descriptor from a property tree.
KeyboardMap::KeyDescriptor &KeyboardMap::KeyDescriptor::load(const boost::property_tree::ptree &data)
{
	// ID
	_id = data.get<std::string>("id");

	// Label
	std::string rawLabel = data.get<std::string>("label");
	parseLabel(rawLabel);

	// Scan codes
	_scan_code_unix    = data.get<ScanCode>("scan-code.unix"   );
	_scan_code_windows = data.get<ScanCode>("scan-code.windows");

	// Geometry
	_in_numeric_keypad = data.get<bool>("geometry.in-nkp");
	std::size_t line1 = data.get<std::size_t>("geometry.line-bottom");
	std::size_t line2 = data.get<std::size_t>("geometry.line-top"   );
	_line_bottom = std::max(line1, line2);
	_line_top    = std::min(line1, line2);
	std::size_t line_count = _line_bottom - _line_top + 1;
	_per_line_x     = parse_int_list(data.get<std::string>("geometry.x"    ), line_count,   0, 0);
	_per_line_width = parse_int_list(data.get<std::string>("geometry.width"), line_count, 100, MINIMUM_KEY_SIZE);

	// Return a reference to the object
	return *this;
}
void UnwrappedLineParser::parseCaseLabel() {
  assert(FormatTok->Tok.is(tok::kw_case) && "'case' expected");
  // FIXME: fix handling of complex expressions here.
  do {
    nextToken();
  } while (!eof() && !FormatTok->Tok.is(tok::colon));
  parseLabel();
}
Beispiel #3
0
QString tooltipForTreeLeaf(const TreeLeafItem* node, const SnapshotItem* snapshot, const QByteArray& label)
{
    QString tooltip = i18n("<dt>cost:</dt><dd>%1, i.e. %2% of snapshot #%3</dd>", prettyCost(node ? node->cost() : 0),
                    // yeah nice how I round to two decimals, right? :D
                    double(int(double(node ? node->cost() : 0)/snapshot->cost()*10000))/100, snapshot->number());
    tooltip += formatLabelForTooltip(parseLabel(label));
    return finalizeTooltip(tooltip);
}
Beispiel #4
0
void Parser::flowIMP(void)
{
    if (!accept(tok[tkp])){
        error("FLOW: Unexpected char at: ", tkp);
        tkp++;
        return;
    }

    if (tok[tkp] == 'A'){
        if (tok[tkp + 1] == 'A'){
            tkp += 2;
            push("Mark ");
            parseLabel();
        }
        else if (tok[tkp + 1] == 'B'){
            tkp += 2;
            push("Call ");
            parseLabel();
        }
        else if (tok[tkp + 1] == 'C'){
            tkp += 2;
            push("Jump ");
            parseLabel();
        }
    }
    else if (tok[tkp] == 'B'){
        if (tok[tkp + 1] == 'A'){
            tkp += 2;
            push("JumpZ ");
            parseLabel();
        }
        else if (tok[tkp + 1] == 'B'){
            tkp += 2;
            push("JumpN ");
            parseLabel();
        }
        else if (tok[tkp + 1] == 'C'){
            tkp += 2;
            push("Return");
        }
    }
}
Beispiel #5
0
QByteArray prettyLabel(const QByteArray& label)
{
    ParsedLabel parsed = parseLabel(label);
    const QByteArray func = shortenTemplates(parsed.function);

    if (!parsed.location.isEmpty()) {
        return func + " (" + parsed.location + ")";
    } else {
        return func;
    }
}
Beispiel #6
0
TESTLIB_DLL_EXPORT bool TestOutputDriver::getAttributesMap(TestInfo *test, 
                RunGroup *group, std::map<std::string, std::string> &attrs) {
  if ((NULL == test) || (NULL == test->label)) {
    return false;
  }

  // Fill in attributes corresponding to the TestInfo object
  // Ugh.  To do this properly I need to either parse TestInfo's label field
  // or change how TestInfo is constructed so it takes all the attributes I'm
  // interested in.  I think I'd be better off parsing the label field, so we
  // don't need to change TestInfo whenever build parameters change.
  // What's a good way to parse a string using C++?
  parseLabel(&attrs, const_cast<char *>(test->label));
  return true;
}
Beispiel #7
0
CAssemblerCommand* Parser::parseCommand()
{
	CAssemblerCommand* command;

	while (checkEquLabel() || checkMacroDefinition())
	{
		// do nothing, just parse all the equs and macros there are
		if (hasError())
			return handleError();
	}
	
	updateFileInfo();

	if (atEnd())
		return new DummyCommand();
	
	if ((command = parseLabel()) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = parseMacroCall()) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = Arch->parseDirective(*this)) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = parseDirective(directives)) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = Arch->parseOpcode(*this)) != nullptr)
		return command;
	if (hasError())
		return handleError();

	const Token& token = peekToken();
	printError(token,L"Parse error '%s'",token.getOriginalText());
	return handleError();
}
void UnwrappedLineParser::parseStructuralElement() {
  assert(!FormatTok->Tok.is(tok::l_brace));
  switch (FormatTok->Tok.getKind()) {
  case tok::at:
    nextToken();
    if (FormatTok->Tok.is(tok::l_brace)) {
      parseBracedList();
      break;
    }
    switch (FormatTok->Tok.getObjCKeywordID()) {
    case tok::objc_public:
    case tok::objc_protected:
    case tok::objc_package:
    case tok::objc_private:
      return parseAccessSpecifier();
    case tok::objc_interface:
    case tok::objc_implementation:
      return parseObjCInterfaceOrImplementation();
    case tok::objc_protocol:
      return parseObjCProtocol();
    case tok::objc_end:
      return; // Handled by the caller.
    case tok::objc_optional:
    case tok::objc_required:
      nextToken();
      addUnwrappedLine();
      return;
    default:
      break;
    }
    break;
  case tok::kw_namespace:
    parseNamespace();
    return;
  case tok::kw_inline:
    nextToken();
    if (FormatTok->Tok.is(tok::kw_namespace)) {
      parseNamespace();
      return;
    }
    break;
  case tok::kw_public:
  case tok::kw_protected:
  case tok::kw_private:
    parseAccessSpecifier();
    return;
  case tok::kw_if:
    parseIfThenElse();
    return;
  case tok::kw_for:
  case tok::kw_while:
    parseForOrWhileLoop();
    return;
  case tok::kw_do:
    parseDoWhile();
    return;
  case tok::kw_switch:
    parseSwitch();
    return;
  case tok::kw_default:
    nextToken();
    parseLabel();
    return;
  case tok::kw_case:
    parseCaseLabel();
    return;
  case tok::kw_try:
    parseTryCatch();
    return;
  case tok::kw_extern:
    nextToken();
    if (FormatTok->Tok.is(tok::string_literal)) {
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace)) {
        parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
        addUnwrappedLine();
        return;
      }
    }
    break;
  case tok::identifier:
    if (FormatTok->IsForEachMacro) {
      parseForOrWhileLoop();
      return;
    }
    // In all other cases, parse the declaration.
    break;
  default:
    break;
  }
  do {
    switch (FormatTok->Tok.getKind()) {
    case tok::at:
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace))
        parseBracedList();
      break;
    case tok::kw_enum:
      parseEnum();
      break;
    case tok::kw_typedef:
      nextToken();
      // FIXME: Use the IdentifierTable instead.
      if (FormatTok->TokenText == "NS_ENUM")
        parseEnum();
      break;
    case tok::kw_struct:
    case tok::kw_union:
    case tok::kw_class:
      parseRecord();
      // A record declaration or definition is always the start of a structural
      // element.
      break;
    case tok::semi:
      nextToken();
      addUnwrappedLine();
      return;
    case tok::r_brace:
      addUnwrappedLine();
      return;
    case tok::l_paren:
      parseParens();
      break;
    case tok::caret:
      nextToken();
      if (FormatTok->Tok.isAnyIdentifier() ||
          FormatTok->isSimpleTypeSpecifier())
        nextToken();
      if (FormatTok->is(tok::l_paren))
        parseParens();
      if (FormatTok->is(tok::l_brace))
        parseChildBlock();
      break;
    case tok::l_brace:
      if (!tryToParseBracedList()) {
        // A block outside of parentheses must be the last part of a
        // structural element.
        // FIXME: Figure out cases where this is not true, and add projections
        // for them (the one we know is missing are lambdas).
        if (Style.BreakBeforeBraces != FormatStyle::BS_Attach)
          addUnwrappedLine();
        FormatTok->Type = TT_FunctionLBrace;
        parseBlock(/*MustBeDeclaration=*/false);
        addUnwrappedLine();
        return;
      }
      // Otherwise this was a braced init list, and the structural
      // element continues.
      break;
    case tok::kw_try:
      // We arrive here when parsing function-try blocks.
      parseTryCatch();
      return;
    case tok::identifier: {
      StringRef Text = FormatTok->TokenText;
      if (Style.Language == FormatStyle::LK_JavaScript && Text == "function") {
        tryToParseJSFunction();
        break;
      }
      nextToken();
      if (Line->Tokens.size() == 1) {
        if (FormatTok->Tok.is(tok::colon)) {
          parseLabel();
          return;
        }
        // Recognize function-like macro usages without trailing semicolon.
        if (FormatTok->Tok.is(tok::l_paren)) {
          parseParens();
          if (FormatTok->NewlinesBefore > 0 &&
              tokenCanStartNewLine(FormatTok->Tok) && Text == Text.upper()) {
            addUnwrappedLine();
            return;
          }
        } else if (FormatTok->HasUnescapedNewline && Text.size() >= 5 &&
                   Text == Text.upper()) {
          // Recognize free-standing macros like Q_OBJECT.
          addUnwrappedLine();
          return;
        }
      }
      break;
    }
    case tok::equal:
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace)) {
        parseBracedList();
      }
      break;
    case tok::l_square:
      parseSquare();
      break;
    default:
      nextToken();
      break;
    }
  } while (!eof());
}
Beispiel #9
0
/* Функция компиляци
 * Осуществляется как проверки, так и вызовв других
 * функций для проверок или преобразваний.
 * Проверки на правельность написания мнемокода ассамблера
 * и заменна мнемокода на коды команд, так же замена символов
 * адресации на коды адресации, и также меток на их дресса
 * - Входные данные: исходные мнемокод ассамблера с виджета
 * - Выходные данные: записать данных в ячейки ОЗУ сформированных
 * во время выполнения функции
 */
void Compiler::exec(QString &strSource)
{
  if(strSource.isEmpty()) return;
  QTime startTime = QTime::currentTime();

  strSource = parseLabel(strSource);
  QStringList slCommandPair = strSource.split(" ");

  mBar->setStyleSheet("QProgressBar {border: 1px solid rgb(83, 83, 83);background-color: rgb(38, 40, 41);border-radius: 5px;} QProgressBar::chunk {background-color: rgb(64, 66, 68);width: 20px; }");
  mBar->setMaximum(slCommandPair.size() - 1);
  mBar->setValue(0);

  QStringList debugList;
  QString isRegistr, strCode, strCmd, strArg = "000", typeAdrr = "0",
          debugArg = " ", debugCmd = " ", resParseCmd = "", error = "";

  int indexCmd = 0;
  for(int i = 0; i < slCommandPair.size(); i ++, mBar->setValue(i)) {
    strCmd = slCommandPair.at(i);
    debugCmd = slCommandPair.at(i);
    strCmd = strCmd.toLower();
    resParseCmd = parseSpecialCommand(strCmd,
                                      i + 1 < slCommandPair.size() ?
                                      slCommandPair.at(i + 1) : " ",
                                      error);
    qDebug() <<"ParseCmd: " << resParseCmd;
    if(resParseCmd != "-1" && error.isEmpty()) {
      mMemory->set(indexCmd, resParseCmd);
      debugList.append(strCmd);
      indexCmd ++;
    } else if(!error.isEmpty()) {
      fireError(error, indexCmd); return;
    } else {
      if(i < slCommandPair.size()) {
        if(i + 1 < slCommandPair.size()) {
          isRegistr = slCommandPair.at(i + 1);
          strCode = isRegistr.contains('r') || isRegistr.contains('R') ?
                    mGenCode->getCode(strCmd + "R") : mGenCode->getCode(strCmd);
        } else {
          fireError("нет аргумента для команды: " +  strCmd, indexCmd); return;
        }
      } else {
        fireError("нет аргумента для команды: " +  strCmd, indexCmd); return;
      }

      if(strCode != "-1") {
        if((i + 1) < slCommandPair.size() ) {
          if(mGenCode->getCode(slCommandPair.at(i + 1)) == "-1") {
            i ++;
            strArg = slCommandPair.at(i); debugArg = strArg;
            parseArguments(strArg, typeAdrr);
          } else {
            fireError("не верный аргумент команды: " +  strCmd, indexCmd); return;
          }
        } else {
          fireError("нет аргумента для команды: " +  strCmd, indexCmd); return;
        }

        while(strArg.size() < 3) strArg.push_front("0");
        strArg = strArg.replace('r', '0');

        debugList.append(debugCmd + " " + debugArg);
        mMemory->set(indexCmd, strCode + typeAdrr + strArg);
        indexCmd ++;
      } else {
        if(out) {
          fireError(" не верная команда", indexCmd);return;
        }
      }
    }
  }
  updateLog(startTime);
  mDpanel->updateCode(debugList);
}
Beispiel #10
0
QByteArray locationInLabel(const QByteArray& label)
{
    return parseLabel(label).location;
}
Beispiel #11
0
QByteArray addressInLabel(const QByteArray& label)
{
    return parseLabel(label).address;
}
Beispiel #12
0
QByteArray functionInLabel(const QByteArray& label)
{
    return parseLabel(label).function;
}
Beispiel #13
0
void UnwrappedLineParser::parseStatement() {
  parseComments();

  switch (FormatTok.Tok.getKind()) {
  case tok::kw_namespace:
    parseNamespace();
    return;
  case tok::kw_public:
  case tok::kw_protected:
  case tok::kw_private:
    parseAccessSpecifier();
    return;
  case tok::kw_if:
    parseIfThenElse();
    return;
  case tok::kw_for:
  case tok::kw_while:
    parseForOrWhileLoop();
    return;
  case tok::kw_do:
    parseDoWhile();
    return;
  case tok::kw_switch:
    parseSwitch();
    return;
  case tok::kw_default:
    nextToken();
    parseLabel();
    return;
  case tok::kw_case:
    parseCaseLabel();
    return;
  default:
    break;
  }
  int TokenNumber = 0;
  do {
    ++TokenNumber;
    switch (FormatTok.Tok.getKind()) {
    case tok::kw_enum:
      parseEnum();
      return;
    case tok::semi:
      nextToken();
      addUnwrappedLine();
      return;
    case tok::l_paren:
      parseParens();
      break;
    case tok::l_brace:
      parseBlock();
      addUnwrappedLine();
      return;
    case tok::identifier:
      nextToken();
      if (TokenNumber == 1 && FormatTok.Tok.is(tok::colon)) {
        parseLabel();
        return;
      }
      break;
    case tok::equal:
      nextToken();
      // Skip initializers as they will be formatted by a later step.
      if (FormatTok.Tok.is(tok::l_brace))
        nextToken();
      break;
    default:
      nextToken();
      break;
    }
  } while (!eof());
}
Beispiel #14
0
static PyObject *parseFasta(PyObject *self, PyObject *args) {

    /* Parse sequences from *filename* into the memory pointed by the
       Numpy array passed as Python object. */

    char *filename;
    PyArrayObject *msa;
    PyObject *labels = PyList_New(0);
    PyObject *mapping = PyDict_New();
    
    if (!PyArg_ParseTuple(args, "sO", &filename, &msa))
        return NULL;



    if (!labels || !mapping)
        return PyErr_NoMemory();

    char *line = malloc((FASTALINELEN) * sizeof(char));
    if (!line)
        return PyErr_NoMemory();

    char *data = (char *) PyArray_DATA(msa);

    int aligned = 1;
    char ch, errmsg[LENLABEL] = "failed to parse FASTA file at line ";
    long index = 0, count = 0;
    long iline = 0, i, seqlen = 0, curlen = 0;

    FILE *file = fopen(filename, "rb");
    while (fgets(line, FASTALINELEN, file) != NULL) {
        iline++;
        if (line[0] == '>') {
            if (seqlen != curlen) {
                if (seqlen) {
                    aligned = 0;
                    free(line);
                    free(data);
                    fclose(file);
                    PyErr_SetString(PyExc_IOError, intcat(errmsg, iline));
                    return NULL;
                } else
                    seqlen = curlen;
            }
            // `line + 1` is to omit `>` character
            count += parseLabel(labels, mapping, line + 1, FASTALINELEN);
            curlen = 0;
        } else {
            for (i = 0; i < FASTALINELEN; i++) {
                ch = line[i];
                if (ch < 32)
                    break;
                else {
                    data[index++] = ch;
                    curlen++;
                }
            }
        }
    }
    fclose(file);

    free(line);
    if (aligned && seqlen != curlen) {
        PyErr_SetString(PyExc_IOError, intcat(errmsg, iline));
        return NULL;
    }

    npy_intp dims[2] = {index / seqlen, seqlen};
    PyArray_Dims arr_dims;
    arr_dims.ptr = dims;
    arr_dims.len = 2;
    PyArray_Resize(msa, &arr_dims, 0, NPY_CORDER);
    PyObject *result = Py_BuildValue("(OOOi)", msa, labels, mapping, count);
    Py_DECREF(labels);
    Py_DECREF(mapping);
    return result;
}
Beispiel #15
0
static PyObject *parseSelex(PyObject *self, PyObject *args) {

    /* Parse sequences from *filename* into the the memory pointed by the
       Numpy array passed as Python object.  */

    char *filename;
    PyArrayObject *msa;

    if (!PyArg_ParseTuple(args, "sO", &filename, &msa))
        return NULL;

    long i = 0, beg = 0, end = 0;
    long size = SELEXLINELEN + 1, iline = 0, seqlen = 0;
    char errmsg[LENLABEL] = "failed to parse SELEX/Stockholm file at line ";

    PyObject *labels = PyList_New(0), *mapping = PyDict_New();
    if (!labels || !mapping)
        return PyErr_NoMemory();
    char *line = malloc(size * sizeof(char));
    if (!line)
        return PyErr_NoMemory();
    char *data = (char *) PyArray_DATA(msa);
    /* figure out where the sequence starts and ends in a line*/
    FILE *file = fopen(filename, "rb");
    while (fgets(line, size, file) != NULL) {
        iline++;
        if (line[0] == '#' || line[0] == '/' || line[0] == '%')
            continue;
        for (i = 0; i < size; i++)
            if (line[i] == ' ')
                break;
        for (; i < size; i++)
            if (line[i] != ' ')
                break;
        beg = i;
        for (; i < size; i++)
            if (line[i] < 32)
                break;
        end = i;
        seqlen = end - beg;
        break;
    }
    iline--;
    fseek(file, - strlen(line), SEEK_CUR);

    long index = 0, count = 0;

    int space = beg - 1; /* index of space character before sequence */
    while (fgets(line, size, file) != NULL) {
        iline++;
        if (line[0] == '#' || line[0] == '/' || line[0] == '%')
            continue;

        if (line[space] != ' ') {
            free(line);
            fclose(file);
            PyErr_SetString(PyExc_IOError, intcat(errmsg, iline));
            return NULL;
        }

        count += parseLabel(labels, mapping, line, space);

        for (i = beg; i < end; i++)
            data[index++] = line[i];
    }
    fclose(file);
    free(line);
    npy_intp dims[2] = {index / seqlen, seqlen};
    PyArray_Dims arr_dims;
    arr_dims.ptr = dims;
    arr_dims.len = 2;
    PyArray_Resize(msa, &arr_dims, 0, NPY_CORDER);
    PyObject *result = Py_BuildValue("(OOOi)", msa, labels, mapping, count);
    Py_DECREF(labels);
    Py_DECREF(mapping);

    return result;
}