Exemplo n.º 1
0
unsigned Signature::hash() const
{
    uint32_t sizeToHash = allocatedSize(argumentCount()) / sizeof(allocationSizeRoundsUpTo);
    // Assumes over-allocated memory was zero-initialized, and rounded-up to allocationSizeRoundsUpTo so that a wider hash can be performed.
    ASSERT(sizeToHash * sizeof(allocationSizeRoundsUpTo) == allocatedSize(argumentCount()));
    unsigned accumulator = 0xa1bcedd8u;
    const auto* pos = reinterpret_cast<const allocationSizeRoundsUpTo*>(this);
    for (uint32_t i = 0; i < sizeToHash; ++i)
        accumulator = WTF::pairIntHash(accumulator, WTF::IntHash<allocationSizeRoundsUpTo>::hash(*pos));
    return accumulator;
}
Exemplo n.º 2
0
bool ArgList_TokenData::compare(const TokenData *other) const
{
    const ArgList_TokenData *o = static_cast<const ArgList_TokenData *>(other);
    if (argumentCount() != o->argumentCount())
        return false;
    foreach (int i, bRangeD(0, argumentCount() - 1)) {
        if (!argument(i)->compare(o->argument(i)))
            return false;
    }
    return true;
}
Exemplo n.º 3
0
void SemanticAnalysisVisitor::visit(ast::FunctionCall& functionCall) {
    functionCall.visitOperand(*this);
    functionCall.visitArguments(*this);

    // FIXME: try/catch for undefined functions
    auto functionSymbol = symbolTable.findFunction(functionCall.operandSymbol()->getName());

    functionCall.setSymbol(functionSymbol);

    auto& arguments = functionCall.getArgumentList();
    if (arguments.size() == functionSymbol.argumentCount()) {
        auto& declaredArguments = functionSymbol.arguments();
        for (std::size_t i { 0 }; i < arguments.size(); ++i) {
            const auto& declaredArgument = declaredArguments.at(i);
            const auto& actualArgument = arguments.at(i)->getResultSymbol();
            typeCheck(actualArgument->getType(), *declaredArgument, functionCall.getContext());
        }

        auto& returnType = functionSymbol.returnType();
        if (!returnType.isVoid()) {
            functionCall.setResultSymbol(symbolTable.createTemporarySymbol(std::unique_ptr<ast::FundamentalType> {
                    returnType.clone() }));
        }
    } else {
        semanticError("no match for function " + functionSymbol.getType().toString(), functionCall.getContext());
    }
}
Exemplo n.º 4
0
ArgumentDesc *ActionDesc::argumentAt(NPT_Ordinal index) const
{
	if (index < argumentCount()) {
		return *m_private->m_argumentList.GetItem(index);
	}
	return NULL;
}
Exemplo n.º 5
0
Value FunSubstring::evaluate() const
{
    String s = argument(0).evaluate().toString();
    double doublePos = argument(1).evaluate().toNumber();
    if (std::isnan(doublePos))
        return emptyString();
    long pos = static_cast<long>(FunRound::round(doublePos));
    bool haveLength = argumentCount() == 3;
    long len = -1;
    if (haveLength) {
        double doubleLen = argument(2).evaluate().toNumber();
        if (std::isnan(doubleLen))
            return emptyString();
        len = static_cast<long>(FunRound::round(doubleLen));
    }

    if (pos > long(s.length())) 
        return emptyString();

    if (pos < 1) {
        if (haveLength) {
            len -= 1 - pos;
            if (len < 1)
                return emptyString();
        }
        pos = 1;
    }

    return s.substring(pos - 1, len);
}
Exemplo n.º 6
0
String ScriptCallContext::argumentStringAt(unsigned index,
                                           bool checkForNullOrUndefined)
{
    if (index >= argumentCount())
        return String();

    return ToWebCoreString(m_args[index]);
}
Exemplo n.º 7
0
/*!
  Returns the function argument at the given \a index.

  If \a index >= argumentCount(), a QScriptValue of
  the primitive type Undefined is returned.

  \sa argumentCount()
*/
QScriptValue QScriptContext::argument(int index) const
{
    if (index < 0)
        return QScriptValue();
    if (index >= argumentCount())
        return QScriptValue(QScriptValue::UndefinedValue);
    QScriptValue v = argumentsObject().property(index);
    return v;
}
Exemplo n.º 8
0
Value FunNormalizeSpace::evaluate() const
{
    if (!argumentCount()) {
        String s = Value(Expression::evaluationContext().node.get()).toString();
        return s.simplifyWhiteSpace();
    }

    String s = argument(0).evaluate().toString();
    return s.simplifyWhiteSpace();
}
Exemplo n.º 9
0
bool ScriptArguments::getFirstArgumentAsString(String& result) const
{
    if (!argumentCount())
        return false;

    const ScriptValue& value = argumentAt(0);
    ScriptState::Scope scope(m_scriptState.get());
    result = V8ValueStringBuilder::toString(value.v8Value(), value.isolate());
    return true;
}
Exemplo n.º 10
0
String Signature::toString() const
{
    String result(makeString(returnType()));
    result.append(" (");
    for (SignatureArgCount arg = 0; arg < argumentCount(); ++arg) {
        if (arg)
            result.append(", ");
        result.append(makeString(argument(arg)));
    }
    result.append(')');
    return result;
}
Exemplo n.º 11
0
Value FunConcat::evaluate() const
{
    StringBuilder result;
    result.reserveCapacity(1024);

    for (unsigned i = 0, count = argumentCount(); i < count; ++i) {
        String str(argument(i).evaluate().toString());
        result.append(str);
    }

    return result.toString();
}
Exemplo n.º 12
0
bool ScriptArguments::getFirstArgumentAsString(String& result)
{
    if (!argumentCount())
        return false;

    if (!globalState()) {
        ASSERT_NOT_REACHED();
        return false;
    }

    result = argumentAt(0).toString(globalState());
    return true;
}
Exemplo n.º 13
0
Value FunNamespaceURI::evaluate() const
{
    if (argumentCount() > 0) {
        Value a = argument(0).evaluate();
        if (!a.isNodeSet())
            return emptyString();

        Node* node = a.toNodeSet().firstNode();
        return node ? node->namespaceURI().string() : emptyString();
    }

    return evaluationContext().node->namespaceURI().string();
}
Exemplo n.º 14
0
Value FunName::evaluate() const
{
    if (argumentCount() > 0) {
        Value a = argument(0).evaluate();
        if (!a.isNodeSet())
            return emptyString();

        Node* node = a.toNodeSet().firstNode();
        return node ? expandedName(node) : emptyString();
    }

    return expandedName(evaluationContext().node.get());
}
Exemplo n.º 15
0
/*!
  \since 4.4

  Returns a string representation of this context.
  This is useful for debugging.

  \sa backtrace()
*/
QString QScriptContext::toString() const
{
    QScriptContextInfo info(this);
    QString result;

    QString functionName = info.functionName();
    if (functionName.isEmpty()) {
        if (parentContext()) {
            const JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this);
            if (info.functionType() == QScriptContextInfo::ScriptFunction)
                result.append(QLatin1String("<anonymous>"));
            else if(frame->callerFrame()->hasHostCallFrameFlag())
                result.append(QLatin1String("<eval>"));
            else
                result.append(QLatin1String("<native>"));
        } else {
            result.append(QLatin1String("<global>"));
        }
    } else {
        result.append(functionName);
    }

    QStringList parameterNames = info.functionParameterNames();
    result.append(QLatin1Char('('));
    for (int i = 0; i < argumentCount(); ++i) {
        if (i > 0)
            result.append(QLatin1String(", "));
        if (i < parameterNames.count()) {
            result.append(parameterNames.at(i));
            result.append(QLatin1String(" = "));
        }
        QScriptValue arg = argument(i);
        if (arg.isString())
            result.append(QLatin1Char('\''));
        result.append(arg.toString());
        if (arg.isString())
            result.append(QLatin1Char('\''));

    }
    result.append(QLatin1Char(')'));

    QString fileName = info.fileName();
    int lineNumber = info.lineNumber();
    result.append(QLatin1String(" at "));
    if (!fileName.isEmpty()) {
        result.append(fileName);
        result.append(QLatin1Char(':'));
    }
    result.append(QString::number(lineNumber));
    return result;
}
Exemplo n.º 16
0
bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined)
{
    if (!argumentCount())
        return false;

    const ScriptValue& value = argumentAt(0);
    ScriptState::Scope scope(m_scriptState.get());
    if (checkForNullOrUndefined && (value.isNull() || value.isUndefined()))
        return false;

    // We intentionally ignore an exception that can be thrown in ToString().
    v8::TryCatch block;
    v8::Handle<v8::String> string = value.v8Value()->ToString();
    result = string.IsEmpty() ? String() : toCoreString(string);
    return true;
}
bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined)
{
    if (!argumentCount())
        return false;

    const ScriptValue& value = argumentAt(0);
    if (checkForNullOrUndefined && (value.isNull() || value.isUndefined()))
        return false;

    if (!globalState()) {
        ASSERT_NOT_REACHED();
        return false;
    }

    result = value.toString(globalState());
    return true;
}
Exemplo n.º 18
0
/*!
  \since 4.4

  Returns a string representation of this context.
  This is useful for debugging.

  \sa backtrace()
*/
QString QScriptContext::toString() const
{
    QScriptContextInfo info(this);
    QString result;

    QString functionName = info.functionName();
    if (functionName.isEmpty()) {
        if (parentContext()) {
            if (info.functionType() == QScriptContextInfo::ScriptFunction)
                result.append(QLatin1String("<anonymous>"));
            else
                result.append(QLatin1String("<native>"));
        } else {
            result.append(QLatin1String("<global>"));
        }
    } else {
        result.append(functionName);
    }

    QStringList parameterNames = info.functionParameterNames();
    result.append(QLatin1String(" ("));
    for (int i = 0; i < argumentCount(); ++i) {
        if (i > 0)
            result.append(QLatin1String(", "));
        if (i < parameterNames.count()) {
            result.append(parameterNames.at(i));
            result.append(QLatin1Char('='));
        }
        QScriptValue arg = argument(i);
        result.append(safeValueToString(arg));
    }
    result.append(QLatin1String(")"));

    QString fileName = info.fileName();
    int lineNumber = info.lineNumber();
    result.append(QLatin1String(" at "));
    if (!fileName.isEmpty()) {
        result.append(fileName);
        result.append(QLatin1Char(':'));
    }
    result.append(QString::number(lineNumber));
    return result;
}
Exemplo n.º 19
0
void CallFrame::dump(PrintStream& out)
{
    if (CodeBlock* codeBlock = this->codeBlock()) {
        out.print(codeBlock->inferredName(), "#", codeBlock->hashAsStringIfPossible(), " [", codeBlock->jitType(), "]");

        out.print("(");
        thisValue().dumpForBacktrace(out);

        for (size_t i = 0; i < argumentCount(); ++i) {
            out.print(", ");
            JSValue value = argument(i);
            value.dumpForBacktrace(out);
        }

        out.print(")");

        return;
    }

    out.print(returnPC());
}
Exemplo n.º 20
0
Value FunNumber::evaluate() const
{
    if (!argumentCount())
        return Value(Expression::evaluationContext().node.get()).toNumber();
    return argument(0).evaluate().toNumber();
}
Exemplo n.º 21
0
Value FunStringLength::evaluate() const
{
    if (!argumentCount())
        return Value(Expression::evaluationContext().node.get()).toString().length();
    return argument(0).evaluate().toString().length();
}
Exemplo n.º 22
0
NPT_Cardinal ActionDesc::outputArgumentCount() const
{
	return argumentCount() - m_private->m_inputArgumentCount;
}