Example #1
0
void printMatchError(llvm::raw_ostream &os, const MatchResultPtr& result)
{
    switch (result->matchCode) {
    case MATCH_SUCCESS :
        os << "matched";
        break;
    case MATCH_CALLABLE_ERROR : {
        MatchCallableError *e = (MatchCallableError*)result.ptr();
        os << "callable pattern \"" << shortString(e->patternExpr->asString());
        os << "\" did not match \"";
        printStaticName(os, e->callable);
        os << "\"";
        break;
    }
    case MATCH_ARITY_ERROR : {
        MatchArityError *e = (MatchArityError*)result.ptr();
        os << "incorrect number of arguments: expected ";
        if (e->variadic)
            os << "at least ";
        os << e->expectedArgs << " arguments, got " << e->gotArgs << " arguments";
        break;
    }
    case MATCH_ARGUMENT_ERROR : {
        MatchArgumentError *e = (MatchArgumentError *)result.ptr();
        os << "pattern \"" << shortString(e->arg->type->asString());
        os << "\" did not match type \"";
        printStaticName(os, e->type.ptr());
        os << "\" of argument " << e->argIndex + 1;
        break;
    }
    case MATCH_MULTI_ARGUMENT_ERROR : {
        MatchMultiArgumentError *e = (MatchMultiArgumentError *)result.ptr();
        os << "variadic argument type pattern did not match types of arguments ";
        os << "starting at " << e->argIndex + 1;
        break;
    }
    case MATCH_PREDICATE_ERROR : {
        MatchPredicateError *e = (MatchPredicateError *)result.ptr();
        os << "predicate \"" << shortString(e->predicateExpr->asString()) << "\" failed";
        break;
    }
    case MATCH_BINDING_ERROR : {
        MatchBindingError *e = (MatchBindingError *)result.ptr();
        os << "pattern \"" << shortString(e->arg->type->asString());
        os << "\" did not match type \"";
        printStaticName(os, e->type.ptr());
        os << "\" of binding " << e->argIndex + 1;
        break;
    }
    case MATCH_MULTI_BINDING_ERROR : {
        MatchMultiBindingError *e = (MatchMultiBindingError *)result.ptr();
        os << "variadic binding type pattern did not match types of values ";
        os << "starting at " << e->argIndex + 1;
        break;
    }
    default :
        assert(false);
        break;
    }
}
Example #2
0
// EndsWithI
//------------------------------------------------------------------------------
void TestAString::EndsWithI() const
{
    // empty string is handled
    {
        AString empty;
        TEST_ASSERT( empty.EndsWithI( AString( "hello" ) ) == false );
        TEST_ASSERT( empty.EndsWithI( "hello" ) == false );
    }

    // empty compare string is handled
    {
        AString empty;
        TEST_ASSERT( empty.EndsWithI( AString::GetEmpty() ) == true );
        TEST_ASSERT( empty.EndsWithI( "" ) == true );
    }

    // compare with longer string is handled
    {
        AString shortString( "short" );
        TEST_ASSERT( shortString.EndsWithI( AString( "Does not end with this" ) ) == false );
        TEST_ASSERT( shortString.EndsWithI( "Does not end with this" ) == false );
    }

    // compare with shorter string is handled
    {
        AString str( "this is a string ending with Chicken" );
        TEST_ASSERT( str.EndsWithI( "Chicken" ) == true );
        TEST_ASSERT( str.EndsWithI( "chicken" ) == true );
        TEST_ASSERT( str.EndsWithI( "ICKEN" ) == true );
        TEST_ASSERT( str.EndsWithI( "Chicken " ) == false );
        TEST_ASSERT( str.EndsWithI( "Turkey" ) == false );
    }
}
Example #3
0
void
ConfigTree::checkAndInvalidate()
{
    if (!_tree) return;

    // Note: due to a limitation in boost::property_tree it is not possible
    // to discriminate between <tag></tag> and <tag/> in the input file.
    // In both cases data() will be empty.
    if ((!_have_read_data) && !_tree->data().empty()) {
        warning("The immediate data `" + shortString(_tree->data())
                +"' of this tag has not been read.");
    }

    // iterate over children
    for (auto const& p : *_tree) {
        if (p.first != "<xmlattr>") // attributes are handled below
            markVisitedDecrement(Attr::TAG, p.first);
    }

    // iterate over attributes
    if (auto attrs = _tree->get_child_optional("<xmlattr>")) {
        for (auto const& p : *attrs) {
            markVisitedDecrement(Attr::ATTR, p.first);
        }
    }

    for (auto const& p : _visited_params)
    {
        auto const& tag   = p.first.second;
        auto const& count = p.second.count;

        switch (p.first.first) {
        case Attr::ATTR:
            if (count > 0) {
                warning("XML attribute \"" + tag + "\" has been read " + std::to_string(count)
                        + " time(s) more than it was present in the configuration tree.");
            } else if (count < 0) {
                warning("XML attribute \"" + tag + "\" has been read " + std::to_string(-count)
                        + " time(s) less than it was present in the configuration tree.");
            }
            break;
        case Attr::TAG:
            if (count > 0) {
                warning("Key <" + tag + "> has been read " + std::to_string(count)
                        + " time(s) more than it was present in the configuration tree.");
            } else if (count < 0) {
                warning("Key <" + tag + "> has been read " + std::to_string(-count)
                        + " time(s) less than it was present in the configuration tree.");
            }
        }
    }

    // The following invalidates this instance, s.t. it can not be read from it anymore,
    // but it also prevents double-checking.
    _tree = nullptr;
}
Example #4
0
static string lambdaName(LambdaPtr x)
{
    string fullName = shortString(x->asString());

    if (fullName.size() <= 80)
        return "(" + fullName + ")";
    else {
        ostringstream shortName;
        shortName << "<lambda ";
        printFileLineCol(shortName, x->location);
        shortName << ">";

        return shortName.str();
    }
}
int main()
{

  String shortString(16);


	String A("Goodbye "),B("Mary!");
//	printf("%s***%s\n", A.c_str(), B.c_str());

	//A.operator+=(B);
	//A += B;

    print(A);

	//print(A);

	//print(B.operator+(A));
	print(B+A);

return 0;

}