Esempio n. 1
0
void RegExp::compileMatchOnly(VM* vm, Yarr::YarrCharSize charSize)
{
    Yarr::YarrPattern pattern(m_patternString, ignoreCase(), multiline(), &m_constructionError);
    if (m_constructionError) {
        RELEASE_ASSERT_NOT_REACHED();
#if COMPILER_QUIRK(CONSIDERS_UNREACHABLE_CODE)
        m_state = ParseError;
        return;
#endif
    }
    ASSERT(m_numSubpatterns == pattern.m_numSubpatterns);

    if (!hasCode()) {
        ASSERT(m_state == NotCompiled);
        vm->regExpCache()->addToStrongCache(this);
        m_state = ByteCode;
    }

#if ENABLE(YARR_JIT)
    if (!pattern.m_containsBackreferences && !pattern.containsUnsignedLengthPattern() && vm->canUseRegExpJIT()) {
        Yarr::jitCompile(pattern, charSize, vm, m_regExpJITCode, Yarr::MatchOnly);
        if (!m_regExpJITCode.isFallBack()) {
            m_state = JITCode;
            return;
        }
    }
#else
    UNUSED_PARAM(charSize);
#endif

    m_state = ByteCode;
    m_regExpBytecode = Yarr::byteCompile(pattern, &vm->m_regExpAllocator);
}
Esempio n. 2
0
RegExp::RegExpState RegExp::compile(JSGlobalData* globalData)
{
    Yarr::YarrPattern pattern(m_patternString, ignoreCase(), multiline(), &m_constructionError);
    if (m_constructionError)
        return ParseError;

    m_numSubpatterns = pattern.m_numSubpatterns;

    RegExpState res = ByteCode;

#if ENABLE(YARR_JIT)
    if (!pattern.m_containsBackreferences && globalData->canUseJIT()) {
        Yarr::jitCompile(pattern, globalData, m_representation->m_regExpJITCode);
#if ENABLE(YARR_JIT_DEBUG)
        if (!m_representation->m_regExpJITCode.isFallBack())
            res = JITCode;
        else
            res = ByteCode;
#else
        if (!m_representation->m_regExpJITCode.isFallBack())
            return JITCode;
#endif
    }
#endif

    m_representation->m_regExpBytecode = Yarr::byteCompile(pattern, &globalData->m_regExpAllocator);

    return res;
}
Esempio n. 3
0
void RegExp::finishCreation(VM& vm)
{
    Base::finishCreation(vm);
    Yarr::YarrPattern pattern(m_patternString, ignoreCase(), multiline(), &m_constructionError);
    if (m_constructionError)
        m_state = ParseError;
    else
        m_numSubpatterns = pattern.m_numSubpatterns;
}
Esempio n. 4
0
 RegExpImpl(const void* pattern, int len, unsigned flags)
     : RegExpBase(flags) {
     const char* errorMessage = NULL;
     re_ = jsRegExpCompile(
         static_cast<const uint16_t*>(pattern),
         len,
         ignoreCase()
             ? dart::jscre::JSRegExpIgnoreCase
             : dart::jscre::JSRegExpDoNotIgnoreCase,
         multiline()
             ? dart::jscre::JSRegExpMultiline
             : dart::jscre::JSRegExpSingleLine,
         &numSubpatterns_,
         &errorMessage,
         malloc,
         free);
 }
QString ExprParamElement::toString()
{
    QString str = "";
    if (isStringSearchExpression())
    {
        str = QString("\"") + getStrSearchValue() + QString("\""); 
        // we don't bother with case if hash search
	if (searchType != HashSearch) {
	    str += (ignoreCase() ? QString(" (ignore case)") 
                            : QString(" (case sensitive)")); 
	}
    } else 
    {
        if (searchType ==  DateSearch) {
            QDateEdit * dateEdit =  qFindChild<QDateEdit *> (internalframe, "param1");
            str = dateEdit->text();
            if (inRangedConfig)
            {
                str += QString(" ") + tr("to") + QString(" ");
                dateEdit = qFindChild<QDateEdit *> (internalframe, "param2");
                str += dateEdit->text();
            }
        } else if (searchType == SizeSearch) 
        {
            QLineEdit * lineEditSize =  qFindChild<QLineEdit*>(internalframe, "param1");
            str = ("" == lineEditSize->text()) ? "0"
                                               : lineEditSize->text();
            QComboBox * cb = qFindChild<QComboBox*> (internalframe, "unitsCb1");
            str += QString(" ") + cb->itemText(cb->currentIndex());
            if (inRangedConfig)
            {
                str += QString(" ") + tr("to") + QString(" ");
                lineEditSize =  qFindChild<QLineEdit*>(internalframe, "param2");
                str += ("" == lineEditSize->text()) ? "0"
                                                    : lineEditSize->text();
                cb = qFindChild<QComboBox*> (internalframe, "unitsCb2");
                str += QString(" ") + cb->itemText(cb->currentIndex());
            }
        }
    }
    return str;
}
Esempio n. 6
0
void RegExp::compile(JSGlobalData* globalData, Yarr::YarrCharSize charSize)
{
    Yarr::YarrPattern pattern(m_patternString, ignoreCase(), multiline(), &m_constructionError);
    if (m_constructionError) {
        ASSERT_NOT_REACHED();
        m_state = ParseError;
        return;
    }
    ASSERT(m_numSubpatterns == pattern.m_numSubpatterns);

    if (!m_representation) {
        ASSERT(m_state == NotCompiled);
        m_representation = adoptPtr(new RegExpRepresentation);
        globalData->regExpCache()->addToStrongCache(this);
        m_state = ByteCode;
    }

#if ENABLE(YARR_JIT)
    if (!pattern.m_containsBackreferences && globalData->canUseJIT()) {
        Yarr::jitCompile(pattern, charSize, globalData, m_representation->m_regExpJITCode);
#if ENABLE(YARR_JIT_DEBUG)
        if (!m_representation->m_regExpJITCode.isFallBack())
            m_state = JITCode;
        else
            m_state = ByteCode;
#else
        if (!m_representation->m_regExpJITCode.isFallBack()) {
            m_state = JITCode;
            return;
        }
#endif
    }
#else
    UNUSED_PARAM(charSize);
#endif

    m_representation->m_regExpBytecode = Yarr::byteCompile(pattern, &globalData->m_regExpAllocator);
}
Esempio n. 7
0
int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector)
{
    if (startOffset < 0)
        startOffset = 0;
    if (ovector)
        ovector->clear();

    if (startOffset > s.size() || s.isNull())
        return -1;

#if ENABLE(YARR_JIT)
    if (!!m_regExpJITCode) {
#else
    if (m_regExpBytecode) {
#endif
        int offsetVectorSize = (m_numSubpatterns + 1) * 3; // FIXME: should be 2 - but adding temporary fallback to pcre.
        int* offsetVector;
        Vector<int, 32> nonReturnedOvector;
        if (ovector) {
            ovector->resize(offsetVectorSize);
            offsetVector = ovector->data();
        } else {
            nonReturnedOvector.resize(offsetVectorSize);
            offsetVector = nonReturnedOvector.data();
        }

        ASSERT(offsetVector);
        for (int j = 0; j < offsetVectorSize; ++j)
            offsetVector[j] = -1;


#if ENABLE(YARR_JIT)
        int result = Yarr::executeRegex(m_regExpJITCode, s.data(), startOffset, s.size(), offsetVector, offsetVectorSize);
#else
        int result = Yarr::interpretRegex(m_regExpBytecode.get(), s.data(), startOffset, s.size(), offsetVector);
#endif

        if (result < 0) {
#ifndef NDEBUG
            // TODO: define up a symbol, rather than magic -1
            if (result != -1)
                fprintf(stderr, "jsRegExpExecute failed with result %d\n", result);
#endif
            if (ovector)
                ovector->clear();
        }
        return result;
    }

    return -1;
}

#else

void RegExp::compile(JSGlobalData* globalData)
{
    m_regExp = 0;
#if ENABLE(WREC)
    m_wrecFunction = Generator::compileRegExp(globalData, m_pattern, &m_numSubpatterns, &m_constructionError, m_executablePool, ignoreCase(), multiline());
    if (m_wrecFunction || m_constructionError)
        return;
    // Fall through to non-WREC case.
#else
    UNUSED_PARAM(globalData);
#endif

    JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase;
    JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine;
    m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.data()), m_pattern.size(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
}