Ejemplo n.º 1
0
int main(int argc, const char *argv[]) {
  throws();
  try {
    unreachable(1);
  } catch (int) {}
  return 0;
}
Ejemplo n.º 2
0
static void test_exceptions(void) {
  throws("", "Syntax error", 0);
  throws("[1)", "Expected comma or closing bracket", 2);
  throws("{\"x\":1)", "Expected comma or closing brace", 6);
  throws("{\"x\")", "Missing colon", 4);
  throws("\"\\u\"", "Bad escape", 1);
  throws("triffic", "Expected true or false", 0);
  throws("nice", "Expected null", 0);
  throws("!!", "Syntax error", 0);
}
Ejemplo n.º 3
0
        virtual void test() override // define this function to run tests
        {
            plan(17); // Run 17 tests.

            ok([]() { return true; }, "ok() succeeds on true");
            ok([]() { return false; }, "ok() fails on false");
            ok([]() { throw 0; return true; }, "ok() fails on throw");

            ok(true, "ok() with just boolean arguments works");

            throws([]() { throw 0; }, "throws() detects int throw");
            throws([]() { }, "throws() fails on no throw");

            throws<int>([]() { throw 0; }, "throws<int>() detects int throw");
            throws<int>([]() { throw 'a'; },
                       "throws<int>() fails on char throw");
            throws<int>([]() { }, "throws<int>() fails on no throw");

            nothrows([]() { }, "nothrows() accepts no throw");
            nothrows([]() { throw 0; }, "nothrows() fails on int throw");

            nothrows<int>([]() { throw 'a'; },
                         "nothrows<int>() accepts char throw");
            nothrows<int>([]() {}, "nothrows<int>() accepts no throw");
            nothrows<int>([]() { throw 0; },
                         "nothrows<int>() fails on int throw");

            // See the file variadic.cpp for examples of the
            // new_ok<>() function.

            pass("Will pass automatically.");
            pass("No matter what.");
            fail("Always fails.");

            is(5, 5, "5 == 5");
            is(5, 6, "5 == 6; this should fail.");
            is(std::string("cipra"), std::string("cipra"), "String equality");

            isnt(5, 6, "5 != 6");
            isnt(5, 5, "5 != 5; this should fail.");
            isnt(std::string(";,.pyfgcrl"), std::string("qwertyuiop"),
                 "Programmer Dvorak is not QWERTY");
        }
Ejemplo n.º 4
0
void assembler_t::disasm() {

    for (uint32_t i = 0; i < head_;) {
        printf("%04d ", i);

        uint8_t op = code_[i];
        i += 1;

        switch (op) {
        case(INS_ADD) : print("INS_ADD   "); continue;
        case(INS_SUB) : print("INS_SUB   "); continue;
        case(INS_MUL) : print("INS_MUL   "); continue;
        case(INS_DIV) : print("INS_DIV   "); continue;
        case(INS_MOD) : print("INS_MOD   "); continue;
        case(INS_AND) : print("INS_AND   "); continue;
        case(INS_OR)  : print("INS_OR    "); continue;
        case(INS_NOT) : print("INS_NOT   "); continue;
        case(INS_LT)  : print("INS_LT    "); continue;
        case(INS_GT)  : print("INS_GT    "); continue;
        case(INS_LEQ) : print("INS_LEQ   "); continue;
        case(INS_GEQ) : print("INS_GEQ   "); continue;
        case(INS_EQ)  : print("INS_EQ    "); continue;
        case(INS_NOP) : print("INS_NOP   "); continue;
        }

        if (op == INS_SCALL) {
            void * ptr = 0;
            memcpy(&ptr, code_ + i, sizeof(void*));
            i += sizeof(void*);
            printf("INS_SCALL  %p\n", ptr);
            continue;
        }

        int32_t val = *(int32_t*)(code_ + i);
        i += 4;

        switch (op) {
        case(INS_JMP  ): print("INS_CJMP  ", val); continue;
        case(INS_CALL ): print("INS_CALL  ", val); continue;
        case(INS_RET  ): print("INS_RET   ", val); continue;
        case(INS_POP  ): print("INS_POP   ", val); continue;
        case(INS_CONST): print("INS_CONST ", val); continue;
        case(INS_GETV ): print("INS_GETV  ", val); continue;
        case(INS_SETV ): print("INS_SETV  ", val); continue;
        }


        throws("unknown opcode");
    }
}
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
  if (!getLangOpts().CPlusPlus || !getLangOpts().CXXExceptions)
    return;

  Finder->addMatcher(
      functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
                         cxxConstructorDecl(isMoveConstructor()),
                         cxxMethodDecl(isMoveAssignmentOperator()),
                         hasName("main"), hasName("swap"),
                         isEnabled(FunctionsThatShouldNotThrow)),
                   throws(unless(isIgnored(IgnoredExceptions))))
          .bind("thrower"),
      this);
}
Ejemplo n.º 6
0
void assembler_t::emit(instruction_e ins, int32_t v) {
    switch (ins) {
    case(INS_JMP  ):
    case(INS_CALL ):
    case(INS_RET  ):
    case(INS_POP  ):
    case(INS_CONST):
    case(INS_GETV ):
    case(INS_SETV ): write8(ins);
                     write32(v);
                     break;
    default:
        throws("unknown instruction");
    }
}
Ejemplo n.º 7
0
void assembler_t::emit(token_e tok) {
    switch (tok) {
    case(TOK_ADD): emit(INS_ADD); break;
    case(TOK_SUB): emit(INS_SUB); break;
    case(TOK_MUL): emit(INS_MUL); break;
    case(TOK_DIV): emit(INS_DIV); break;
    case(TOK_MOD): emit(INS_MOD); break;
    case(TOK_AND): emit(INS_AND); break;
    case(TOK_OR ): emit(INS_OR ); break;
    case(TOK_NOT): emit(INS_NOT); break;
    case(TOK_EQ ): emit(INS_EQ ); break;
    case(TOK_LT ): emit(INS_LT ); break;
    case(TOK_GT ): emit(INS_GT ); break;
    case(TOK_LEQ): emit(INS_LEQ); break;
    case(TOK_GEQ): emit(INS_GEQ); break;
    default:
        throws("cant emit token type");
    }
}
Ejemplo n.º 8
0
void assembler_t::emit(instruction_e ins) {
    switch (ins) {
    case(INS_ADD) :
    case(INS_SUB) :
    case(INS_MUL) :
    case(INS_DIV) :
    case(INS_MOD) :
    case(INS_AND) :
    case(INS_OR)  :
    case(INS_NOT) :
    case(INS_LT)  :
    case(INS_GT)  :
    case(INS_LEQ) :
    case(INS_GEQ) :
    case(INS_EQ)  :
    case(INS_NOP) : write8(ins);
                    break;
    default:
        throws("unknown instruction");
    }
}
Ejemplo n.º 9
0
int main(int argc, const char *argv[]) {
  throws();
  return 0;
}