Ejemplo n.º 1
0
void FunctionVisitor::visitFunction(Function *function) {
    listarg.clear();
    function->listarg_->accept(this);
    JFunction *jf = new JFunction(function, listarg);
    function->ident_ = jf->getObfuscatedName();
    _visitFunction(jf);
}
JIndex
JAbsValue::PrepareToRender
	(
	const JExprRenderer&	renderer,
	const JPoint&			upperLeft,
	const JSize				fontSize,
	JExprRectList*			rectList
	)
{
	const JSize barWidth = renderer.GetVertBarWidth();

	// get rectangle for our argument

	JPoint argUpperLeft = upperLeft;
	argUpperLeft.x += barWidth;

	JFunction* arg = GetArg();
	const JIndex argIndex =
		arg->PrepareToRender(renderer, argUpperLeft, fontSize, rectList);

	// calculate our rectangle

	JRect ourRect  = rectList->GetRect(argIndex);
	ourRect.left  -= barWidth;
	ourRect.right += barWidth;

	// save our rectangle

	const JCoordinate ourMidline = rectList->GetMidline(argIndex);
	return rectList->AddRect(ourRect, ourMidline, fontSize, this);
}
Ejemplo n.º 3
0
JIndex
JConjugate::PrepareToRender
	(
	const JExprRenderer&	renderer,
	const JPoint&			upperLeft,
	const JSize				fontSize,
	JExprRectList*			rectList
	)
{
	const JSize barHeight = renderer.GetHorizBarHeight();

	// get rectangle for our argument

	JPoint argUpperLeft = upperLeft;
	argUpperLeft.y += barHeight;

	JFunction* arg = GetArg();
	const JIndex argIndex =
		arg->PrepareToRender(renderer, argUpperLeft, fontSize, rectList);

	// calculate our rectangle

	JRect ourRect  = rectList->GetRect(argIndex);
	ourRect.top   -= barHeight;

	// save our rectangle

	const JCoordinate ourMidline = rectList->GetMidline(argIndex);
	return rectList->AddRect(ourRect, ourMidline, fontSize, this);
}
JBoolean
SCCircuitVarList::AddFunction
	(
	const JCharacter*	name,
	const JFunction&	f,
	const JBoolean		visible
	)
{
	JIndex index;
	if (!JNameValid(name))
		{
		return kJFalse;
		}
	else if (ParseVariableName(name, strlen(name), &index))
		{
		(JGetUserNotification())->ReportError("This variable name is already used.");
		return kJFalse;
		}
	else
		{
		VarInfo info;

		info.name = new JString(name);
		assert( info.name != NULL );

		info.f       = f.Copy();
		info.visible = visible;

		itsVars->AppendElement(info);
		Broadcast(VarInserted(GetElementCount()));
		return kJTrue;
		}
}
JNaryFunction::JNaryFunction
	(
	const JNaryFunction& source
	)
	:
	JFunctionWithArgs(source)
{
	itsArgList = new JPtrArray<JFunction>(JPtrArrayT::kDeleteAll, kMaxReasonableArgCount);
	assert( itsArgList != NULL );

	const JSize argCount = (source.itsArgList)->GetElementCount();

	for (JIndex i=1; i<=argCount; i++)
		{
		JFunction* sourceArg = (source.itsArgList)->GetElement(i);
		JFunction* arg       = sourceArg->Copy();
		itsArgList->Append(arg);
		}
}
void
SCPlotDirector::AddFunction
	(
	const JFunction&	f,
	const JCharacter*	name,
	const JFloat		xMin,
	const JFloat		xMax
	)
{
	AddFunction(f.Copy(), name, xMin, xMax);
}
Ejemplo n.º 7
0
	//Call a javascript function, store the found function in a local cache for faster access
	v8::Handle<v8::Value> BeaContext::call(const char *fnName, int argc, v8::Handle<v8::Value> argv[]){
		
		HandleScope scope;
		Context::Scope context_scope(m_context);

		//Lookup function in cache
		JFunction fn;
		CacheMap::iterator iter = m_fnCached.find(std::string(fnName));

		if (iter != m_fnCached.end())
			fn = iter->second;
		else {
			//Lookup function in the script 
			v8::Handle<v8::Value> fnv = m_context->Global()->Get(v8::String::New(fnName));

			if (!fnv->IsFunction()) {
				std::stringstream strstr;
				strstr << "Error: " << fnName << " is not a function";
				lastError = strstr.str();
				return v8::False();
			} else {

				//Store found function in our cache
				fn = Persistent<Function>::New(v8::Handle<Function>::Cast(fnv));
				m_fnCached[std::string(fnName)] = fn;
			}
		}

		//Call the function
		TryCatch try_catch;
		v8::Handle<v8::Value> result = fn->Call(m_context->Global(), argc, argv);

		if (result.IsEmpty())
			reportError(try_catch);

		return scope.Close(result);
	}
JFunctionParenType
GetParenType
	(
	const JFunction& f
	)
{
	const JFunctionType fnType = f.GetType();

	if (fnType == kJExponentType)
		{
		return kExponentParenType;
		}
	else if (fnType == kJParallelType)
		{
		return kParallelParenType;
		}
	else if (fnType == kJProductType)
		{
		return kProductParenType;
		}
	else if (fnType == kJDivisionType)
		{
		return kDivisionParenType;
		}
	else if (fnType == kJNegationType)
		{
		return kNegationParenType;
		}
	else if (fnType == kJSummationType)
		{
		return kSummationParenType;
		}
	else if (fnType == kJConstantValueType &&
			 ((const JConstantValue&) f).GetValue() < 0.0)
		{
		return kNegativeConstantType;
		}
	else
		{
		return kValueParenType;
		}
}
JBoolean
SCCircuitVarList::SetFunction
	(
	const JIndex		index,
	const JFunction&	f
	)
{
	if (IsFunction(index))
		{
		VarInfo info = itsVars->GetElement(index);
		delete (info.f);
		info.f = f.Copy();
		itsVars->SetElement(index, info);
		Broadcast(VarValueChanged(index,1));
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
Ejemplo n.º 10
0
JIndex
JLogB::PrepareToRender
	(
	const JExprRenderer&	renderer,
	const JPoint&			upperLeft,
	const JSize				fontSize,
	JExprRectList*			rectList
	)
{
	// intialize our rectangle

	const JCharacter* name = GetName();
	const JSize nameLength = strlen(name);
	assert( nameLength > 1 );
	assert( name[ nameLength-1 ] == '(' );
	const JString fnName = JString(name, nameLength-1);

	JRect ourRect;
	ourRect.top    = upperLeft.y;
	ourRect.left   = upperLeft.x;
	ourRect.bottom = upperLeft.y + renderer.GetLineHeight(fontSize);
	ourRect.right  = upperLeft.x + renderer.GetStringWidth(fontSize, fnName);

	// get rectangle for base

	JPoint argUpperLeft(ourRect.right, ourRect.top);
	const JSize baseFontSize = renderer.GetSuperSubFontSize(fontSize);

	JFunction* base = GetArg1();
	const JIndex baseIndex =
		base->PrepareToRender(renderer, argUpperLeft, baseFontSize, rectList);
	const JRect baseRect = rectList->GetRect(baseIndex);
	argUpperLeft.x = baseRect.right;

	// get rectangle for argument -- gives our midline

	JFunction* arg = GetArg2();
	const JIndex argIndex =
		arg->PrepareToRender(renderer, argUpperLeft, fontSize, rectList);
	const JRect argRect          = rectList->GetRect(argIndex);
	ourRect                      = JCovering(ourRect, argRect);
	const JCoordinate ourMidline = rectList->GetMidline(argIndex);

	// shift argument to make space for left parenthesis

	const JSize parenWidth = renderer.GetParenthesisWidth(argRect.height());
	rectList->ShiftRect(argIndex, parenWidth, 0);

	// we need space for two parentheses

	ourRect.right += 2*parenWidth;

	// shift the base down

	rectList->ShiftRect(baseIndex, 0, ourMidline - ourRect.top);
	ourRect = JCovering(ourRect, rectList->GetRect(baseIndex));

	// save our rectangle

	return rectList->AddRect(ourRect, ourMidline, fontSize, this);
}
JIndex
JParallel::PrepareToRender
	(
	const JExprRenderer&	renderer,
	const JPoint&			upperLeft,
	const JSize				fontSize,
	JExprRectList*			rectList
	)
{
	// intialize our rectangle and midline

	JPoint argUpperLeft = upperLeft;

	JRect ourRect(upperLeft, argUpperLeft);
	ourRect.bottom += renderer.GetLineHeight(fontSize);
	JCoordinate ourMidline = (ourRect.top + ourRect.bottom)/2;
	const JCoordinate origMidline = ourMidline;

	// get rectangle for each argument

	const JSize opWidth =
		2*(renderer.GetStringWidth(fontSize, " ") + renderer.GetVertBarWidth());
	const JSize argCount = GetArgCount();
	{
	for (JIndex i=1; i<=argCount; i++)
		{
		JFunction* arg = GetArg(i);
		const JIndex argIndex =
			arg->PrepareToRender(renderer, argUpperLeft, fontSize, rectList);
		JRect argRect  = rectList->GetRect(argIndex);
		argUpperLeft.x = argRect.right + opWidth;

		if (ParenthesizeArgForRender(*this, *arg))
			{
			const JSize parenWidth = renderer.GetParenthesisWidth(argRect.height());
			rectList->ShiftRect(argIndex, parenWidth, 0);
			argRect = rectList->GetRect(argIndex);
			argUpperLeft.x += 2*parenWidth;
			ourRect.right   = argRect.right + parenWidth;
			}

		ourRect = JCovering(ourRect, argRect);
		const JCoordinate argMidline = rectList->GetMidline(argIndex);
		if (argMidline > ourMidline)
			{
			ourMidline = argMidline;
			}
		}
	}

	// adjust the argument rectangles so all the midlines are the same
	// (ourMidline is guaranteed to stay constant)

	if (argCount > 1 && ourMidline > origMidline)
		{
		for (JIndex i=1; i<=argCount; i++)
			{
			const JFunction* arg = GetArg(i);
			JIndex argIndex;
			const JBoolean found = rectList->FindFunction(arg, &argIndex);
			assert( found );
			rectList->SetMidline(argIndex, ourMidline);
			ourRect = JCovering(ourRect, rectList->GetRect(argIndex));
			}
		}

	// save our rectangle

	return rectList->AddRect(ourRect, ourMidline, fontSize, this);
}
Ejemplo n.º 12
0
JIndex
JSummation::PrepareToRender
	(
	const JExprRenderer&	renderer,
	const JPoint&			upperLeft,
	const JSize				fontSize,
	JExprRectList*			rectList
	)
{
	// intialize our rectangle and midline

	JPoint argUpperLeft = upperLeft;

	JRect ourRect(upperLeft, argUpperLeft);
	ourRect.bottom += renderer.GetLineHeight(fontSize);
	JCoordinate ourMidline = ourRect.ycenter();
	const JCoordinate origMidline = ourMidline;

	// get rectangle for each argument

	const JSize spaceWidth = renderer.GetStringWidth(fontSize, " ");
	const JSize plusWidth  = renderer.GetStringWidth(fontSize, JPGetAdditionString());
	const JSize minusWidth = renderer.GetStringWidth(fontSize, JPGetSubtractionString());

	const JSize argCount = GetArgCount();
	{
	for (JIndex i=1; i<=argCount; i++)
		{
		JFunction* f   = this;
		JFunction* arg = GetArg(i);
		if (arg->GetType() == kJNegationType)
			{
			argUpperLeft.x += minusWidth + spaceWidth;
			if (i > 1)
				{
				argUpperLeft.x += spaceWidth;
				}
			f = arg;
			JNegation* neg = dynamic_cast<JNegation*>(arg);
			assert( neg != NULL );
			arg = neg->GetArg();
			}
		else if (i > 1)
			{
			argUpperLeft.x += plusWidth + 2*spaceWidth;
			}

		const JIndex argIndex =
			arg->PrepareToRender(renderer, argUpperLeft, fontSize, rectList);
		JRect argRect = rectList->GetRect(argIndex);
		argUpperLeft.x = argRect.right;

		if (ParenthesizeArgForRender(*f, *arg))
			{
			const JSize parenWidth = renderer.GetParenthesisWidth(argRect.height());
			rectList->ShiftRect(argIndex, parenWidth, 0);
			argRect = rectList->GetRect(argIndex);
			argUpperLeft.x += 2*parenWidth;
			ourRect.right   = argRect.right + parenWidth;
			}

		ourRect = JCovering(ourRect, argRect);
		const JCoordinate argMidline = rectList->GetMidline(argIndex);
		if (argMidline > ourMidline)
			{
			ourMidline = argMidline;
			}
		}
	}

	// adjust the argument rectangles so all the midlines are the same
	// (ourMidline is guaranteed to stay constant)

	if (argCount > 1 && ourMidline > origMidline)
		{
		for (JIndex i=1; i<=argCount; i++)
			{
			const JFunction* arg = GetArg(i);
			if (arg->GetType() == kJNegationType)
				{
				const JNegation* neg = dynamic_cast<const JNegation*>(arg);
				assert( neg != NULL );
				arg = neg->GetArg();
				}

			JIndex argIndex;
			const JBoolean found = rectList->FindFunction(arg, &argIndex);
			assert( found );
			rectList->SetMidline(argIndex, ourMidline);
			ourRect = JCovering(ourRect, rectList->GetRect(argIndex));
			}
		}

	// save our rectangle

	return rectList->AddRect(ourRect, ourMidline, fontSize, this);
}