Esempio n. 1
0
void
EmsMessage::parseRCWWOpmodeMessage()
{
    parseBool(0, 1, EmsValue::EigenesProgrammAktiv, EmsValue::WW);
    parseBool(1, 1, EmsValue::EigenesProgrammAktiv, EmsValue::Zirkulation);

    parseEnum(2, EmsValue::Betriebsart, EmsValue::WW);
    parseEnum(3, EmsValue::Betriebsart, EmsValue::Zirkulation);

    parseBool(4, 1, EmsValue::Desinfektion, EmsValue::WW);
    parseEnum(5, EmsValue::DesinfektionTag, EmsValue::WW);
    parseInteger(6, 1, EmsValue::DesinfektionStunde, EmsValue::WW);
    parseNumeric(8, 1, 1, EmsValue::MaxTemp, EmsValue::WW);
    parseBool(9 ,1, EmsValue::EinmalLadungsLED, EmsValue::WW);
}
Esempio n. 2
0
void
EmsMessage::parseRCSystemParameterMessage()
{
    parseNumeric(5, 1, 1, EmsValue::MinTemp, EmsValue::Aussen);
    parseEnum(6, EmsValue::GebaeudeArt, EmsValue::None);
    parseBool(21, 1, EmsValue::ATDaempfung, EmsValue::None);
}
Esempio n. 3
0
void
EmsMessage::parseUBAParameterWWMessage()
{
    parseBool(1, 0, EmsValue::KesselSchalter, EmsValue::WW);
    parseNumeric(2, 1, 1, EmsValue::SetTemp, EmsValue::WW);
    parseNumeric(8, 1, 1, EmsValue::DesinfektionsTemp, EmsValue::WW);
    parseEnum(7,EmsValue::Schaltpunkte, EmsValue::Zirkulation);
}
Esempio n. 4
0
void
EmsMessage::parseRCHKOpmodeMessage(EmsValue::SubType subtype)
{
    parseEnum(0, EmsValue::HeizArt, subtype);
    parseNumeric(1, 1, 2, EmsValue::NachtTemp, subtype);
    parseNumeric(2, 1, 2, EmsValue::TagTemp, subtype);
    parseNumeric(3, 1, 2, EmsValue::UrlaubTemp, subtype);
    parseNumeric(4, 1, 2, EmsValue::RaumEinfluss, subtype);
    parseNumeric(6, 1, 2, EmsValue::RaumOffset, subtype);
    parseEnum(7, EmsValue::Betriebsart, subtype);
    parseNumeric(16, 1, 1, EmsValue::MinTemp, subtype);
    parseNumeric(35, 1, 1, EmsValue::MaxTemp, subtype);
    parseBool(19, 1, EmsValue::SchaltzeitOptimierung, subtype);
    parseNumeric(22, 1, 1, EmsValue::SchwelleSommerWinter, subtype);
    parseNumeric(23, 1, 1, EmsValue::FrostSchutzTemp, subtype);
    parseEnum(25, EmsValue::RegelungsArt, subtype);
    parseEnum(28, EmsValue::Frostschutz, subtype);
    parseEnum(32, EmsValue::HeizSystem, subtype);
    parseEnum(33, EmsValue::FuehrungsGroesse, subtype);
    parseNumeric(36, 1, 1, EmsValue::AuslegungsTemp, subtype);
    parseNumeric(37, 1, 2, EmsValue::RaumUebersteuerTemp, subtype);
    parseNumeric(38, 1, 1, EmsValue::AbsenkungsAbbruchTemp, subtype);
    parseNumeric(39, 1, 1, EmsValue::AbsenkungsSchwellenTemp, subtype);
    parseNumeric(40, 1, 1, EmsValue::UrlaubAbsenkungsSchwellenTemp, subtype);
    parseEnum(41, EmsValue::UrlaubAbsenkungsArt, subtype);
}
Esempio n. 5
0
void
EmsMessage::parseUBAMaintenanceSettingsMessage()
{
    parseEnum(0,EmsValue::Wartungsmeldungen, EmsValue::Kessel);
    parseInteger(1, 1, EmsValue::HektoStundenVorWartung, EmsValue::Kessel);
    if (canAccess(2, sizeof(EmsProto::DateRecord))) {
	EmsProto::DateRecord *record = (EmsProto::DateRecord *) &m_data.at(2 - m_offset);
	m_valueHandler(EmsValue(EmsValue::Wartungstermin, EmsValue::Kessel, *record));
    }
}
Esempio n. 6
0
void
EmsMessage::parseUBAMonitorWWMessage()
{
    parseNumeric(0, 1, 1, EmsValue::SollTemp, EmsValue::WW);
    parseNumeric(1, 2, 10, EmsValue::IstTemp, EmsValue::WW);
    parseInteger(10, 3, EmsValue::WarmwasserbereitungsZeit, EmsValue::None);
    parseInteger(13, 3, EmsValue::WarmwasserBereitungen, EmsValue::None);

    parseBool(5, 0, EmsValue::Tagbetrieb, EmsValue::WW);
    parseBool(5, 1, EmsValue::EinmalLadungAktiv, EmsValue::WW);
    parseBool(5, 2, EmsValue::DesinfektionAktiv, EmsValue::WW);
    parseBool(5, 3, EmsValue::WarmwasserBereitung, EmsValue::None);
    parseBool(5, 4, EmsValue::NachladungAktiv, EmsValue::WW);
    parseBool(5, 5, EmsValue::WarmwasserTempOK, EmsValue::None);
    parseBool(7, 0, EmsValue::Tagbetrieb, EmsValue::Zirkulation);
    parseBool(7, 2, EmsValue::ZirkulationAktiv, EmsValue::None);

    parseEnum(8, EmsValue::WWSystemType, EmsValue::None);
}
Esempio n. 7
0
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());
}
Esempio n. 8
0
void Moc::parse()
{
    QList<NamespaceDef> namespaceList;
    bool templateClass = false;
    while (hasNext()) {
        Token t = next();
        switch (t) {
            case NAMESPACE: {
                int rewind = index;
                if (test(IDENTIFIER)) {
                    if (test(EQ)) {
                        // namespace Foo = Bar::Baz;
                        until(SEMIC);
                    } else if (!test(SEMIC)) {
                        NamespaceDef def;
                        def.name = lexem();
                        next(LBRACE);
                        def.begin = index - 1;
                        until(RBRACE);
                        def.end = index;
                        index = def.begin + 1;
                        namespaceList += def;
                        index = rewind;
                    }
                }
                break;
            }
            case SEMIC:
            case RBRACE:
                templateClass = false;
                break;
            case TEMPLATE:
                templateClass = true;
                break;
            case MOC_INCLUDE_BEGIN:
                currentFilenames.push(symbol().unquotedLexem());
                break;
            case MOC_INCLUDE_END:
                currentFilenames.pop();
                break;
            case Q_DECLARE_INTERFACE_TOKEN:
                parseDeclareInterface();
                break;
            case Q_DECLARE_METATYPE_TOKEN:
                parseDeclareMetatype();
                break;
            case USING:
                if (test(NAMESPACE)) {
                    while (test(SCOPE) || test(IDENTIFIER))
                        ;
                    next(SEMIC);
                }
                break;
            case CLASS:
            case STRUCT: {
                if (currentFilenames.size() <= 1)
                    break;

                ClassDef def;
                if (!parseClassHead(&def))
                    continue;

                while (inClass(&def) && hasNext()) {
                    if (next() == Q_OBJECT_TOKEN) {
                        def.hasQObject = true;
                        break;
                    }
                }

                if (!def.hasQObject)
                    continue;

                for (int i = namespaceList.size() - 1; i >= 0; --i)
                    if (inNamespace(&namespaceList.at(i)))
                        def.qualified.prepend(namespaceList.at(i).name + "::");

                knownQObjectClasses.insert(def.classname);
                knownQObjectClasses.insert(def.qualified);

                continue; }
            default: break;
        }
        if ((t != CLASS && t != STRUCT)|| currentFilenames.size() > 1)
            continue;
        ClassDef def;
        if (parseClassHead(&def)) {
            FunctionDef::Access access = FunctionDef::Private;
            for (int i = namespaceList.size() - 1; i >= 0; --i)
                if (inNamespace(&namespaceList.at(i)))
                    def.qualified.prepend(namespaceList.at(i).name + "::");
            while (inClass(&def) && hasNext()) {
                switch ((t = next())) {
                case PRIVATE:
                    access = FunctionDef::Private;
                    if (test(Q_SIGNALS_TOKEN))
                        error("Signals cannot have access specifier");
                    break;
                case PROTECTED:
                    access = FunctionDef::Protected;
                    if (test(Q_SIGNALS_TOKEN))
                        error("Signals cannot have access specifier");
                    break;
                case PUBLIC:
                    access = FunctionDef::Public;
                    if (test(Q_SIGNALS_TOKEN))
                        error("Signals cannot have access specifier");
                    break;
                case CLASS: {
                    ClassDef nestedDef;
                    if (parseClassHead(&nestedDef)) {
                        while (inClass(&nestedDef) && inClass(&def)) {
                            t = next();
                            if (t >= Q_META_TOKEN_BEGIN && t < Q_META_TOKEN_END)
                                error("Meta object features not supported for nested classes");
                        }
                    }
                } break;
                case Q_SIGNALS_TOKEN:
                    parseSignals(&def);
                    break;
                case Q_SLOTS_TOKEN:
                    switch (lookup(-1)) {
                    case PUBLIC:
                    case PROTECTED:
                    case PRIVATE:
                        parseSlots(&def, access);
                        break;
                    default:
                        error("Missing access specifier for slots");
                    }
                    break;
                case Q_OBJECT_TOKEN:
                    def.hasQObject = true;
                    if (templateClass)
                        error("Template classes not supported by Q_OBJECT");
                    if (def.classname != "Qt" && def.classname != "QObject" && def.superclassList.isEmpty())
                        error("Class contains Q_OBJECT macro but does not inherit from QObject");
                    break;
                case Q_GADGET_TOKEN:
                    def.hasQGadget = true;
                    if (templateClass)
                        error("Template classes not supported by Q_GADGET");
                    break;
                case Q_PROPERTY_TOKEN:
                    parseProperty(&def);
                    break;
                case Q_ENUMS_TOKEN:
                    parseEnumOrFlag(&def, false);
                    break;
                case Q_FLAGS_TOKEN:
                    parseEnumOrFlag(&def, true);
                    break;
                case Q_DECLARE_FLAGS_TOKEN:
                    parseFlag(&def);
                    break;
                case Q_CLASSINFO_TOKEN:
                    parseClassInfo(&def);
                    break;
                case Q_INTERFACES_TOKEN:
                    parseInterfaces(&def);
                    break;
                case Q_PRIVATE_SLOT_TOKEN:
                    parseSlotInPrivate(&def, access);
                    break;
                case Q_PRIVATE_PROPERTY_TOKEN:
                    parsePrivateProperty(&def);
                    break;
                case ENUM: {
                    EnumDef enumDef;
                    if (parseEnum(&enumDef))
                        def.enumList += enumDef;
                } break;
                default:
                    FunctionDef funcDef;
                    funcDef.access = access;
                    int rewind = index;
                    if (parseMaybeFunction(&def, &funcDef)) {
                        if (funcDef.isConstructor) {
                            if ((access == FunctionDef::Public) && funcDef.isInvokable) {
                                def.constructorList += funcDef;
                                while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
                                    funcDef.wasCloned = true;
                                    funcDef.arguments.removeLast();
                                    def.constructorList += funcDef;
                                }
                            }
                        } else if (funcDef.isDestructor) {
                            // don't care about destructors
                        } else {
                            if (access == FunctionDef::Public)
                                def.publicList += funcDef;
                            if (funcDef.isSlot) {
                                def.slotList += funcDef;
                                while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
                                    funcDef.wasCloned = true;
                                    funcDef.arguments.removeLast();
                                    def.slotList += funcDef;
                                }
                            } else if (funcDef.isSignal) {
                                def.signalList += funcDef;
                                while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
                                    funcDef.wasCloned = true;
                                    funcDef.arguments.removeLast();
                                    def.signalList += funcDef;
                                }
                            } else if (funcDef.isInvokable) {
                                def.methodList += funcDef;
                                while (funcDef.arguments.size() > 0 && funcDef.arguments.last().isDefault) {
                                    funcDef.wasCloned = true;
                                    funcDef.arguments.removeLast();
                                    def.methodList += funcDef;
                                }
                            }
                        }
                    } else {
                        index = rewind;
                    }
                }
            }

            next(RBRACE);

            if (!def.hasQObject && !def.hasQGadget && def.signalList.isEmpty() && def.slotList.isEmpty()
                && def.propertyList.isEmpty() && def.enumDeclarations.isEmpty())
                continue; // no meta object code required


            if (!def.hasQObject && !def.hasQGadget)
                error("Class declarations lacks Q_OBJECT macro.");

            checkSuperClasses(&def);
            checkProperties(&def);

            classList += def;
            knownQObjectClasses.insert(def.classname);
            knownQObjectClasses.insert(def.qualified);
        }
    }
}
Esempio n. 9
0
int main(int argc, char **argv)
{
usb_dev_handle  *handle = NULL;
int             opt, len, action, argcnt;
char            *myName = argv[0], *s, *rxBuffer = NULL;
FILE            *fp;

    while((opt = getopt(argc, argv, "?hv:p:V:P:S:d:D:O:e:n:tbw")) != -1){
        switch(opt){
        case 'h':
        case '?':   /* -h or -? (print this help and exit) */
            usage(myName);
            exit(1);
        case 'v':   /* -v <vendor-id> (defaults to 0x%x, can be '*' for any VID) */
            vendorID = myAtoi(optarg);
            break;
        case 'p':   /* -p <product-id> (defaults to 0x%x, can be '*' for any PID) */
            productID = myAtoi(optarg);
            break;
        case 'V':   /* -V <vendor-name-pattern> (shell style matching, defaults to '*') */
            vendorNamePattern = optarg;
            break;
        case 'P':   /* -P <product-name-pattern> (shell style matching, defaults to '*') */
            productNamePattern = optarg;
            break;
        case 'S':   /* -S <serial-pattern> (shell style matching, defaults to '*') */
            serialPattern = optarg;
            break;
        case 'd':   /* -d <databytes> (data bytes for requests given on command line) */
            while((s = strtok(optarg, ", ")) != NULL){
                optarg = NULL;
                if(sendBytes != NULL){
                    sendBytes = realloc(sendBytes, sendByteCount + 1);
                }else{
                    sendBytes = malloc(sendByteCount + 1);
                }
                sendBytes[sendByteCount++] = myAtoi(s);
            }
            break;
        case 'D':   /* -D <file> (data bytes for request taken from file) */
            if((fp = fopen(optarg, "rb")) == NULL){
                fprintf(stderr, "error opening %s: %s\n", optarg, strerror(errno));
                exit(1);
            }
            fseek(fp, 0, SEEK_END);
            len = ftell(fp);
            fseek(fp, 0, SEEK_SET);
            if(sendBytes != NULL){
                sendBytes = realloc(sendBytes, sendByteCount + len);
            }else{
                sendBytes = malloc(sendByteCount + len);
            }
            fread(sendBytes + sendByteCount, 1, len, fp);   /* would need error checking */
            sendByteCount += len;
            fclose(fp);
            break;
        case 'O':   /* -O <file> (write received data bytes to file) */
            outputFile = optarg;
            break;
        case 'e':   /* -e <endpoint> (specify endpoint for some commands) */
            endpoint = myAtoi(optarg);
            break;
        case 't':   /* -t <timeout> (specify USB timeout in milliseconds) */
            usbTimeout = myAtoi(optarg);
            break;
        case 'b':   /* -b (binary output format, default is hex) */
            outputFormatIsBinary = 1;
            break;
        case 'n':   /* -n <count> (maximum number of bytes to receive) */
            usbCount = myAtoi(optarg);
            break;
        case 'c':   /* -c <configuration> (device configuration to choose) */
            usbConfiguration = myAtoi(optarg);
            break;
        case 'i':   /* -i <interface> (configuration interface to claim) */
            usbInterface = myAtoi(optarg);
            break;
        case 'w':   /* -w (suppress USB warnings, default is verbose) */
            showWarnings = 0;
            break;
        default:
            fprintf(stderr, "Option -%c unknown\n", opt);
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;
    if(argc < 1){
        usage(myName);
        exit(1);
    }
    argcnt = 2;
    if(strcasecmp(argv[0], "list") == 0){
        action = ACTION_LIST;
        argcnt = 1;
    }else if(strcasecmp(argv[0], "control") == 0){
        action = ACTION_CONTROL;
        argcnt = 7;
    }else if(strcasecmp(argv[0], "interrupt") == 0){
        action = ACTION_INTERRUPT;
    }else if(strcasecmp(argv[0], "bulk") == 0){
        action = ACTION_BULK;
    }else{
        fprintf(stderr, "command %s not known\n", argv[0]);
        usage(myName);
        exit(1);
    }
    if(argc < argcnt){
        fprintf(stderr, "Not enough arguments.\n");
        usage(myName);
        exit(1);
    }
    if(argc > argcnt){
        fprintf(stderr, "Warning: only %d arguments expected, rest ignored.\n", argcnt);
    }
    usb_init();
    if(usbOpenDevice(&handle, vendorID, vendorNamePattern, productID, productNamePattern, serialPattern, action == ACTION_LIST ? stdout : NULL, showWarnings ? stderr : NULL) != 0){
        fprintf(stderr, "Could not find USB device with VID=0x%x PID=0x%x Vname=%s Pname=%s Serial=%s\n", vendorID, productID, vendorNamePattern, productNamePattern, serialPattern);
        exit(1);
    }
    if(action == ACTION_LIST)
        exit(0);                /* we've done what we were asked to do already */
    usbDirection = parseEnum(argv[1], "out", "in", NULL);
    if(usbDirection){   /* IN transfer */
        rxBuffer = malloc(usbCount);
    }
    if(action == ACTION_CONTROL){
        int requestType;
        usbType = parseEnum(argv[2], "standard", "class", "vendor", "reserved", NULL);
        usbRecipient = parseEnum(argv[3], "device", "interface", "endpoint", "other", NULL);
        usbRequest = myAtoi(argv[4]);
        usbValue = myAtoi(argv[5]);
        usbIndex = myAtoi(argv[6]);
        requestType = ((usbDirection & 1) << 7) | ((usbType & 3) << 5) | (usbRecipient & 0x1f);
        if(usbDirection){   /* IN transfer */
            len = usb_control_msg(handle, requestType, usbRequest, usbValue, usbIndex, rxBuffer, usbCount, usbTimeout);
        }else{              /* OUT transfer */
            len = usb_control_msg(handle, requestType, usbRequest, usbValue, usbIndex, sendBytes, sendByteCount, usbTimeout);
        }
    }else{  /* must be ACTION_INTERRUPT or ACTION_BULK */
        int retries = 1;
        if(usb_set_configuration(handle, usbConfiguration) && showWarnings){
            fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror());
        }
        /* now try to claim the interface and detach the kernel HID driver on
         * linux and other operating systems which support the call.
         */
        while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
            if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){
                fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror());
            }
#endif
        }
        if(len != 0 && showWarnings)
            fprintf(stderr, "Warning: could not claim interface: %s\n", usb_strerror());
        if(action == ACTION_INTERRUPT){
            if(usbDirection){   /* IN transfer */
                len = usb_interrupt_read(handle, endpoint, rxBuffer, usbCount, usbTimeout);
            }else{
                len = usb_interrupt_write(handle, endpoint, sendBytes, sendByteCount, usbTimeout);
            }
        }else{
            if(usbDirection){   /* IN transfer */
                len = usb_bulk_read(handle, endpoint, rxBuffer, usbCount, usbTimeout);
            }else{
                len = usb_bulk_write(handle, endpoint, sendBytes, sendByteCount, usbTimeout);
            }
        }
    }
    if(len < 0){
        fprintf(stderr, "USB error: %s\n", usb_strerror());
        exit(1);
    }
    if(usbDirection == 0)   /* OUT */
        printf("%d bytes sent.\n", len);
    if(rxBuffer != NULL){
        FILE *fp = stdout;
        if(outputFile != NULL){
            fp = fopen(outputFile, outputFormatIsBinary ? "wb" : "w");
            if(fp == NULL){
                fprintf(stderr, "Error writing \"%s\": %s\n", outputFile, strerror(errno));
                exit(1);
            }
        }
        if(outputFormatIsBinary){
            fwrite(rxBuffer, 1, len, fp);
        }else{
            int i;
            for(i = 0; i < len; i++){
                if(i != 0){
                    if(i % 16 == 0){
                        fprintf(fp, "\n");
                    }else{
                        fprintf(fp, " ");
                    }
                }
                fprintf(fp, "0x%02x", rxBuffer[i] & 0xff);
            }
            if(i != 0)
                fprintf(fp, "\n");
        }
    }
    usb_close(handle);
    if(rxBuffer != NULL)
        free(rxBuffer);
    return 0;
}
Esempio n. 10
0
bool ClassParser::parseHeader(const char *strHeader, const char *strHeaderFullFilePath)
{
    unsigned int i;
    unsigned int iCount = strlen(strHeader);
    int iSquareBracketsOfClassIndex = 0;
    unsigned int iPosition;
    bool bIsParsed;

    EParseAction eAction = PARSE_ACTION_NOTHING;
    EParseActionSecondary eSecondaryAction = PARSE_ACTION_SECONDARY_NOTHING;

    for (i=0; i<iCount; i++) {

        switch (eAction) {

        case PARSE_ACTION_NOTHING:
            if (strncmp(strHeader+i, "/*", 2) == 0) {
                eAction = PARSE_ACTION_COMMENTS_OUT_MULTI_LINE;
                i++;

                if (ClassParserFind::findToNextChar(strHeader+i+1, "*/", &iPosition)) {

                    i+=iPosition+2;
                    eAction = PARSE_ACTION_NOTHING;
                }
            }
            else if (strncmp(strHeader+i, "//", 2) == 0) {
                eAction = PARSE_ACTION_COMMENTS_OUT_SINGLE_LINE;
                i++;
                if (ClassParserFind::findToNextChar(strHeader+i+1, "\n", &iPosition)) {

                    i+=iPosition+1;
                    eAction = PARSE_ACTION_NOTHING;
                }
            }
            else {
                if (eSecondaryAction != PARSE_ACTION_SECONDARY_NOTHING &&
                        eSecondaryAction != PARSE_ACTION_SECONDARY_IN_CLASS_BEGIN &&
                        eSecondaryAction != PARSE_ACTION_SECONDARY_IN_GOT_CLASS_NAME)
                {

                    if (strHeader[i] == '{') {

                        iSquareBracketsOfClassIndex++;
                    }
                    else if (strHeader[i] == '}') {

                        iSquareBracketsOfClassIndex--;
                        if (iSquareBracketsOfClassIndex == 0) {
                            eSecondaryAction = PARSE_ACTION_SECONDARY_NOTHING;
                            if (ClassParserFind::findToNextChar(strHeader+i, ";", &iPosition)) {

                                i+=iPosition;
                            }
                        }
                    }
                }

                switch (eSecondaryAction) {

                case PARSE_ACTION_SECONDARY_NOTHING:
                    if (strncmp(strHeader+i, "class", 5) == 0) {
                        ClassParserInformation s;
                        s.m_strClassType = "class";
                        s.m_strFromHeaderFile = strHeaderFullFilePath;
                        m_listClassInformation.append(s);
                        i += 5;
                        i += parseClass(strHeader+i, m_listClassInformation.size()-1);
                    }
                    else if (strncmp(strHeader+i, "struct", 6) == 0) {
                        ClassParserInformation s;
                        s.m_strClassType = "struct";
                        s.m_strFromHeaderFile = strHeaderFullFilePath;
                        m_listClassInformation.append(s);
                        i += 6;
                        i += parseClass(strHeader+i, m_listClassInformation.size()-1);
                    }
                    else if (strncmp(strHeader+i, "enum", 4) == 0) {
                        ClassParserInformation s;
                        s.m_strClassType = "enum";
                        s.m_strFromHeaderFile = strHeaderFullFilePath;
                        m_listClassInformation.append(s);
                        i += 4;
                        i += parseEnum(strHeader+i, m_listClassInformation.size()-1);
                    }
                    else if (strncmp(strHeader+i, "typedef", 7) == 0) {
                        ClassParserInformation s;
                        s.m_strClassType = "typedef";
                        s.m_strFromHeaderFile = strHeaderFullFilePath;
                        m_listClassInformation.append(s);
                        i += 7;
                        i += parseTypedef(strHeader+i, m_listClassInformation.size()-1);
                    }
                    else if (strncmp(strHeader+i, "template", 8) == 0) {
                        ClassParserInformation s;
                        s.m_strClassType = "template";
                        s.m_strFromHeaderFile = strHeaderFullFilePath;
                        i += 8;
                        i += ClassParserFind::parseTemplate(strHeader+i, &s);
                        m_listClassInformation.append(s);
                    }
                    else if (strncmp(strHeader+i, "union", 5) == 0) {
                        ClassParserInformation s;
                        s.m_strClassType = "union";
                        s.m_strFromHeaderFile = strHeaderFullFilePath;
                        i += 5;
                        i += ClassParserFind::parseTemplate(strHeader+i, &s);
                        m_listClassInformation.append(s);
                    }
                    else if (strncmp(strHeader+i, "#define", 7) == 0) {
                        i += 7;
                        i += ClassParserFind::parseDefine(strHeader+i, this);
                    }
                    else if (strncmp(strHeader+i, "#include", 8) == 0) {

                        bool bInPublicIncludeFolders;
                        QString strInclude = ClassParserFind::getIncludeHeader(strHeader+i+8, &iPosition, &bInPublicIncludeFolders);
                        if (strInclude.length() != 0) {

                            i+=8+iPosition;
                            ClassParserIncludeHeaderInformation s;
                            s.m_bInPublicIncludeFolders = bInPublicIncludeFolders;
                            s.m_strIncludeHeader = strInclude;
                            s.m_strIncludeHeaderWithFullFilePath = findFullFilePathForHeaderInformation(&s, strHeaderFullFilePath);
                            bIsParsed = isIncludeHeaderParsed(&s);
                            m_listIncludeHeader.append(s);

                            if (bIsParsed == false && s.m_strIncludeHeaderWithFullFilePath.length() != 0) {

                                QByteArray ba = s.m_strIncludeHeaderWithFullFilePath.toLatin1();
                                parse(ba.data());
                            }
                        }
                    }
                    else if (ClassParserFind::skipThisLine(strHeader, i, &iPosition) ) {

                        i=iPosition;
                    }
                    else  {

                        i+= ClassParserFind::parsePossibleFunctionFromThisLine(strHeader+i);
                    }

                    break;

                default:
                    break;
                }
            }

            break;
        case PARSE_ACTION_COMMENTS_OUT_MULTI_LINE:
            if (strncmp(strHeader+i, "*/", 2) == 0) {
                eAction = PARSE_ACTION_NOTHING;
                i++;
            }
            break;
        case PARSE_ACTION_COMMENTS_OUT_SINGLE_LINE:
            if (strncmp(strHeader+i, "\n", 1) == 0) {
                eAction = PARSE_ACTION_NOTHING;
                i++;
            }
            break;
        }
    }

    return false;
}
Esempio n. 11
0
unsigned int ClassParser::parseClass(const char *strHeader, int iClassIndex) {

    unsigned int i;
    unsigned int iCount = strlen(strHeader);
    unsigned int iPreviousImportantActionIndex = 0;
    int iSquareBracketsIndex = 0;
    int iSquareBracketsOfClassIndex = 0;
    int iBracketsIndex = 0;
    unsigned int iPosition;
    unsigned int iPositionAdd;
    int iMacroIndex;
    bool bInTheQuotes = false;
    EParseAction eAction = PARSE_ACTION_NOTHING;
    EParseActionSecondary eSecondaryAction = PARSE_ACTION_SECONDARY_IN_CLASS_BEGIN;
    EClassParserMemberType eFunctionType = FUNCTION_TYPE_PRIVATE;
    EClassParserMemberType eMemberType;

    for (i=0; i<iCount; i++) {
        switch (eAction) {

        case PARSE_ACTION_NOTHING:
            if (bInTheQuotes == false && strncmp(strHeader+i, "/*", 2) == 0) {
                eAction = PARSE_ACTION_COMMENTS_OUT_MULTI_LINE;
                i++;

                if (ClassParserFind::findToNextChar(strHeader+i+1, "*/", &iPosition)) {

                    i+=iPosition+2;
                    eAction = PARSE_ACTION_NOTHING;
                }
            }
            else if (bInTheQuotes == false && strncmp(strHeader+i, "//", 2) == 0) {
                eAction = PARSE_ACTION_COMMENTS_OUT_SINGLE_LINE;
                i++;
                if (ClassParserFind::findToNextChar(strHeader+i+1, "\n", &iPosition)) {

                    i+=iPosition+1;
                    eAction = PARSE_ACTION_NOTHING;
                }
            }
            else {
                if (eSecondaryAction != PARSE_ACTION_SECONDARY_NOTHING &&
                        eSecondaryAction != PARSE_ACTION_SECONDARY_IN_CLASS_BEGIN &&
                        eSecondaryAction != PARSE_ACTION_SECONDARY_IN_GOT_CLASS_NAME)
                {

                    if (strHeader[i] == '{') {

                        iSquareBracketsOfClassIndex++;
                    }
                    else if (strHeader[i] == '}') {

                        iSquareBracketsOfClassIndex--;
                        if (iSquareBracketsOfClassIndex == 0) {
                            eSecondaryAction = PARSE_ACTION_SECONDARY_NOTHING;
                            if (ClassParserFind::findToNextChar(strHeader+i, ";", &iPosition)) {

                                i+=iPosition;
                                return i;
                            }
                        }
                    }
                }

                if (bInTheQuotes == false) {

                    if (strHeader[i] == '\"') {

                        bInTheQuotes = true;
                        continue;
                    }
                }
                else {

                    if (i == 0 && strHeader[i] == '\"') {

                        bInTheQuotes = false;
                        continue;
                    }
                    else if (i != 0 && strHeader[i-1] != '\\' && strHeader[i] == '\"') {

                        bInTheQuotes = false;
                        continue;
                    }
                }

                if (bInTheQuotes == false) {

                    switch (eSecondaryAction) {

                    case PARSE_ACTION_SECONDARY_NOTHING:
                        break;

                    case PARSE_ACTION_SECONDARY_IN_CLASS_BEGIN:

                        eSecondaryAction = PARSE_ACTION_SECONDARY_IN_GOT_CLASS_NAME;
                        iPreviousImportantActionIndex = i;

                        i += ClassParserFind::parseClassName(strHeader+i, &m_listClassInformation[iClassIndex]);
                        if (strHeader[i] == ';') {
                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            return i;
                        }
                        else {
                            if (strHeader[i] == '{') {

                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                                eFunctionType = FUNCTION_TYPE_PRIVATE;
                                iSquareBracketsOfClassIndex++;
                            }
                        }
                        break;

                    case PARSE_ACTION_SECONDARY_IN_GOT_CLASS_NAME:

                        if (strHeader[i] == '{') {

                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            eFunctionType = FUNCTION_TYPE_PRIVATE;
                            iSquareBracketsOfClassIndex++;
                        }
                        break;

                    case PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING:
                    case PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FIRST_HAND_INFO:
                    case PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_BRACETS_OUT:

                        if ( !ClassParserFind::isThisEqualToSpace(strHeader[i]) &&
                                iSquareBracketsIndex == 0 && iBracketsIndex == 0 &&
                                strHeader[i] != '(' && strHeader[i] != '{' &&
                                strHeader[i] != ';' &&
                                strHeader[i] != ')' && strHeader[i] != '}' && strHeader[i] != '=') {

                            if (eSecondaryAction == PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_BRACETS_OUT) {

                                if (strncmp(strHeader+i, "const", 5) == 0) {

                                    i+=4;
                                    continue;
                                }
                                else if (iSquareBracketsIndex == 0 && iBracketsIndex == 0) {

                                    SClassParserPossibleMacroWithoutKnownledge s;
                                    s.m_pType = eFunctionType;
                                    s.m_strMacroLine = ClassParserFind::getStringBetween(strHeader, iPreviousImportantActionIndex, i) ;
                                    m_listClassInformation[iClassIndex].m_listPossibleMacroWithoutKnownledge.append( s );
                                }
                            }

                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            EClassParserClassMainType eClassType = ClassParserFind::isStartWithClassType(strHeader+i, &iPosition);

                            if (eClassType == CLASS_MAIN_TYPE_CLASS) {

                                ClassParserInformation s;
                                s.m_strClassType = "class";
                                s.m_iParentClassIndex = iClassIndex;
                                s.m_strFromHeaderFile = m_listClassInformation[iClassIndex].m_strFromHeaderFile;
                                m_listClassInformation.append(s);
                                i += iPosition;
                                i += parseClass(strHeader+i, m_listClassInformation.size()-1);
                            }
                            else if (eClassType == CLASS_MAIN_TYPE_STRUCT) {

                                ClassParserInformation s;
                                s.m_strClassType = "struct";
                                s.m_iParentClassIndex = iClassIndex;
                                s.m_strFromHeaderFile = m_listClassInformation[iClassIndex].m_strFromHeaderFile;
                                m_listClassInformation.append(s);
                                i += iPosition;
                                i += parseClass(strHeader+i, m_listClassInformation.size()-1);
                            }
                            else if (eClassType == CLASS_MAIN_TYPE_ENUM) {

                                ClassParserInformation s;
                                s.m_strClassType = "enum";
                                s.m_iParentClassIndex = iClassIndex;
                                s.m_strFromHeaderFile = m_listClassInformation[iClassIndex].m_strFromHeaderFile;
                                m_listClassInformation.append(s);
                                i += iPosition;
                                i += parseEnum(strHeader+i, m_listClassInformation.size()-1);
                            }
                            else if (eClassType == CLASS_MAIN_TYPE_TYPEDEF) {

                                ClassParserInformation s;
                                s.m_strClassType = "typedef";
                                s.m_iParentClassIndex = iClassIndex;
                                s.m_strFromHeaderFile = m_listClassInformation[iClassIndex].m_strFromHeaderFile;
                                m_listClassInformation.append(s);
                                i += iPosition;
                                i += parseTypedef(strHeader+i, m_listClassInformation.size()-1);
                            }
                            else if (eClassType == CLASS_MAIN_TYPE_TEMPLATE) {

                                ClassParserInformation s;
                                s.m_strClassType = "template";
                                s.m_iParentClassIndex = iClassIndex;
                                s.m_strFromHeaderFile = m_listClassInformation[iClassIndex].m_strFromHeaderFile;
                                i += iPosition;
                                i += ClassParserFind::parseTemplate(strHeader+i, &s);
                                m_listClassInformation.append(s);
                            }
                            else if (eClassType == CLASS_MAIN_TYPE_UNION) {

                                ClassParserInformation s;
                                s.m_strClassType = "union";
                                s.m_iParentClassIndex = iClassIndex;
                                s.m_strFromHeaderFile = m_listClassInformation[iClassIndex].m_strFromHeaderFile;
                                i += iPosition;
                                i += ClassParserFind::parseTemplate(strHeader+i, &s);
                                m_listClassInformation.append(s);
                            }
                            else if (ClassParserFind::skipThisLine(strHeader, i, &iPosition) ) {

                                i=iPosition;
                            }
                            else if (isStartWithMacroBeginForFunction(strHeader+i, &iMacroIndex)) {

                                ClassParserFind::getFunctionWithMacroBegin(strHeader, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPosition, m_listMacroBeginForMember[iMacroIndex]);
                                i += iPosition;
                            }
                            else {

                                eMemberType = ClassParserFind::isStartWithMemberType(strHeader+i, &iPosition);
                                if (eMemberType != FUNCTION_TYPE_NONE) {

                                    i+=iPosition;
                                    eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FIRST_HAND_INFO;
                                    eFunctionType = eMemberType;
                                }
                                else {

                                    eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_OR_DATATYPE;
                                    iPreviousImportantActionIndex = i;
                                }
                            }
                        }
                        else if (eSecondaryAction == PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_BRACETS_OUT) {

                            if (strHeader[i] == '{' ) {

                                iSquareBracketsIndex = 1;
                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_INLINE;
                            }
                            else if (strHeader[i] == ';' ) {

                                // This call creates function from
                                // emit foo(); in inline function.
                                // Also Q_OBJECT handled incorrectly.
                                ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                                i+=iPositionAdd;
                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            }
                            else if (strHeader[i] == '=' && iBracketsIndex == 0 && iSquareBracketsIndex == 0) {

                                ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                                i+=iPositionAdd;
                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            }
                        }
                        break;
                    case PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_OR_DATATYPE:
                        if (strHeader[i] == ';') {

                            if (iSquareBracketsIndex == 0 && iBracketsIndex == 0) {

                                ClassParserFind::getDataTypeBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex]);
                            }
                            else {


                                ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                                i+=iPositionAdd;
                            }
                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                        }
                        else if (strHeader[i] == '(' ) {

                            iBracketsIndex++;
                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_BRACETS_IN;
                        }
                        break;
                    case PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_BRACETS_IN:
                        if (strHeader[i] == ';' ) {

                            ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                            i+=iPositionAdd;
                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                        }
                        else if (strHeader[i] == '(' ) {

                            iBracketsIndex++;
                        }
                        else if (strHeader[i] == ')' ) {

                            iBracketsIndex--;
                            if (iBracketsIndex == 0) {

                                char c = ClassParserFind::findToNextNextValidNonSpaceChar(strHeader+i+1, &iPosition);

                                if (c == '(') { // function? still continues

                                    i += iPosition;
                                    iBracketsIndex++;
                                }
                                else {

                                    eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_BRACETS_OUT;
                                }
                            }
                        }
                        else if (strHeader[i] == '=' && iBracketsIndex == 0 && iSquareBracketsIndex == 0) {

                            ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                            i+=iPositionAdd;
                            eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                        }
                        break;

                    case PARSE_ACTION_SECONDARY_IN_THE_CLASS_GETTING_FUNCTION_INLINE:

                        if (strHeader[i] == '{' ) {

                            iSquareBracketsIndex++;
                        }
                        else if (strHeader[i] == '}' ) {

                            iSquareBracketsIndex--;
                            if (iSquareBracketsIndex==0) {

                                ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                                i+=iPositionAdd;
                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            }

                        }
                        else if (strHeader[i] == ';' ) {

                            if (iSquareBracketsIndex==0) {

                                ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                                i+=iPositionAdd;
                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            }
                        }
                        else if (strHeader[i] == '=') {

                            if (iSquareBracketsIndex == 0) {

                                ClassParserFind::getFunctionBetween(strHeader, iPreviousImportantActionIndex, i, eFunctionType, &m_listClassInformation[iClassIndex], &iPositionAdd, "");
                                i+=iPositionAdd;
                                eSecondaryAction = PARSE_ACTION_SECONDARY_IN_THE_CLASS_NOTHING;
                            }
                        }
                        break;
                    }
                }
            }

            break;
        case PARSE_ACTION_COMMENTS_OUT_MULTI_LINE:
            if (strncmp(strHeader+i, "*/", 2) == 0) {
                eAction = PARSE_ACTION_NOTHING;
                i++;
            }
            break;
        case PARSE_ACTION_COMMENTS_OUT_SINGLE_LINE:
            if (strncmp(strHeader+i, "\n", 1) == 0) {
                eAction = PARSE_ACTION_NOTHING;
                i++;
            }
            break;
        }
    }

    return i;
}
Esempio n. 12
0
void
EmsMessage::parseUBAMaintenanceStatusMessage()
{
    parseEnum(5, EmsValue::WartungFaellig, EmsValue::Kessel);
}
Esempio n. 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());
}
Esempio n. 14
0
void PackageParser::parse() {
    while (stream_.hasMoreTokens()) {
        auto documentation = parseDocumentationToken();
        
        auto exported = Attribute<E_EARTH_GLOBE_EUROPE_AFRICA>().parse(&stream_);
        auto theToken = stream_.consumeToken(IDENTIFIER);
        switch (theToken.value[0]) {
            case E_PACKAGE: {
                exported.disallow();
                
                auto nameToken = stream_.consumeToken(VARIABLE);
                auto namespaceToken = stream_.consumeToken(IDENTIFIER);
                
                auto name = nameToken.value.utf8CString();
                package_->loadPackage(name, namespaceToken.value[0], theToken);
                
                continue;
            }
            case E_CROCODILE:
                parseProtocol(documentation, theToken, exported.set());
                continue;
            case E_TURKEY:
                parseEnum(documentation, exported.set());
                continue;
            case E_RADIO:
                exported.disallow();
                package_->setRequiresBinary();
                if (strcmp(package_->name(), "_") == 0) {
                    throw CompilerErrorException(theToken, "You may not set 📻 for the _ package.");
                }
                continue;
            case E_CRYSTAL_BALL: {
                exported.disallow();
                if (package_->validVersion()) {
                    throw CompilerErrorException(theToken, "Package version already declared.");
                }
                
                auto major = stream_.consumeToken(INTEGER).value.utf8CString();
                auto minor = stream_.consumeToken(INTEGER).value.utf8CString();
                
                uint16_t majori = strtol(major, nullptr, 0);
                uint16_t minori = strtol(minor, nullptr, 0);
                
                delete [] major;
                delete [] minor;
                
                package_->setPackageVersion(PackageVersion(majori, minori));
                if (!package_->validVersion()) {
                    throw CompilerErrorException(theToken, "The provided package version is not valid.");
                }
                
                continue;
            }
            case E_WALE: {
                exported.disallow();
                EmojicodeChar className, enamespace;
                bool optional;
                auto &classNameToken = parseTypeName(&className, &enamespace, &optional);
                
                if (optional) {
                    throw CompilerErrorException(classNameToken, "Optional types are not extendable.");
                }
                
                Type type = typeNothingness;
                
                if (!package_->fetchRawType(className, enamespace, optional, theToken, &type)) {
                    throw CompilerErrorException(classNameToken, "Class does not exist.");
                }
                if (type.type() != TT_CLASS) {
                    throw CompilerErrorException(classNameToken, "Only classes are extendable.");
                }
                
                // Native extensions are allowed if the class was defined in this package.
                parseClassBody(type.eclass, nullptr, type.eclass->package() == package_);
                
                continue;
            }
            case E_RABBIT:
                parseClass(documentation, theToken, exported.set());
                continue;
            case E_SCROLL: {
                exported.disallow();
                auto pathString = stream_.consumeToken(STRING);
                auto relativePath = pathString.position().file;
                auto fileString = pathString.value.utf8CString();
                
                char *str = fileString;
                const char *lastSlash = strrchr(relativePath, '/');
                if (lastSlash != nullptr) {
                    const char *directory = strndup(relativePath, lastSlash - relativePath);
                    asprintf(&str, "%s/%s", directory, fileString);
                    delete [] fileString;
                    delete [] directory;
                }
                
                PackageParser(package_, lex(str)).parse();
                
                delete [] str;
                continue;
            }
            default:
                ecCharToCharStack(theToken.value[0], f);
                throw CompilerErrorException(theToken, "Unexpected identifier %s", f);
                break;
        }
    }
}