Example #1
0
/**
 * Cast the element to a container.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Container CastToContainer(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Container_* container = dynamic_cast<Container_*>(element_);
    success = (0 != container);
    return success ? Container(container, element.GetSourceLocation()) : Container();
}
Example #2
0
/**
 * Cast to variable.
 *
 * @param element The element we want to cast.
 * @param success is this cast successful?
 */
Variable CastToVariable(Element const& element ,bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Variable_* s = dynamic_cast<Variable_*>(element_);
    success = (0 != s);
    return success ? Variable(s, element.GetSourceLocation()) : Variable("");
}
Example #3
0
/**
 * Cast the element to a container.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Container CastToContainer(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<Container_> container = std::dynamic_pointer_cast<Container_>(element_);
    success = (0 != container.get());
    return success ? Container(container, element.GetSourceLocation()) : Container();
}
Example #4
0
/**
 * Cast to tail recursion element.
 *
 * @param element The element we want to cast.
 * @param success is this cast successful?
 */
TailRecurse CastToTailRecurse(Element const& element ,bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    TailRecurse_* s = dynamic_cast<TailRecurse_*>(element_);
    success = (0 != s);
    return success ? TailRecurse(s) : TailRecurse();
}
Example #5
0
/**
 * Cast the element to a True.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
True CastToTrue(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    True_* f = dynamic_cast<True_*>(element_);
    success = (0 != f);
    return True();
}
Example #6
0
/**
 * Cast to a set.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Set CastToSet(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Set_* s = dynamic_cast<Set_*>(element_);
    success = (0 != s);
    return success ? Set(s, element.GetSourceLocation()) : Set();
}
Example #7
0
/**
 * Cast to a super string.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
SuperString CastToSuperString(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    SuperString_* s = dynamic_cast<SuperString_*>(element_);
    success = (0 != s);
    return success ? SuperString(s, element.GetSourceLocation()) : SuperString();
}
Example #8
0
/**
 * Cast the element to an if.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
If CastToIf(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    If_* i = dynamic_cast<If_*>(element_);
    success = (0 != i);
    return success ? If(i, element.GetSourceLocation()) : If();
}
Example #9
0
/**
 * Cast to a number.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Number CastToNumber(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Number_* number = dynamic_cast<Number_*>(element_);
    success = (0 != number);
    return success ? Number(number, element.GetSourceLocation()) : Number();
}
Example #10
0
/**
 * Cast the element to an imperative.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Imperative CastToImperative(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Imperative_* imperative = dynamic_cast<Imperative_*>(element_);
    success = (0 != imperative);
    return success ? Imperative(imperative, element.GetSourceLocation()) : Imperative();
}
Example #11
0
/**
 * Cast the element to a False.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
False CastToFalse(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    False_* f = dynamic_cast<False_*>(element_);
    success = (0 != f);
    return False();
}
Example #12
0
/**
 * Cast the element to a Function.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Function CastToFunction(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Function_* function = dynamic_cast<Function_*>(element_);
    success = (0 != function);
    return success ? Function(function, element.GetSourceLocation()) : Function();
}
/**
 * The following method takes the path and elements passed in and creates a 
 * new ExecutorProcess_ element that will be in charge of running the 
 * program.
 *
 * @version 
 * - JR Lewis       2012.03.05
 *   - Initial version.
 */
Element ExecutorBuiltinImplementation::InterpretParsed_( Environment& environment
                                                       , Element& path_element
                                                       , std::vector<Element> const& parms) 
{
    String_* path = dynamic_cast<String_*>(path_element.ElementHandle());
    Element out;

    std::vector<Element> parameters;
    Funcall_::InterpretParameters( environment
                                 , parms
                                 , parameters );  

    if (  0 != path )
    {
        Container container;
        size_t const PARMS_SIZE = parameters.size();
        for(size_t i=0; i<PARMS_SIZE; ++i)
        {
            container.Add(parameters[i]);
        }
 
        ExecutorProcessing_* processing = new ExecutorProcessing_( this->strine
                                                                 , QString::fromStdString(path->Value())
                                                                 , container);
        out = Processing(processing); 
    } 
    return out;
}
Example #14
0
/**
 * Cast the element to a case expression.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Case CastToCase(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Case_* c = dynamic_cast<Case_*>(element_);
    success = (0 != c);
    return success ? Case(c, element.GetSourceLocation()) : Case();
}
Example #15
0
/**
 * Interpret a builtin call. Yes, this can be slow because each time we invoke
 * this we must query the mapping in the builtins table to see if it can be 
 * executed (builtin implementation). HOWEVER, this also allows us to swap out
 * builtin implementations on the fly.
 *
 * @return The interpreted element.
 */
Element Builtin_::InterpretCall( Environment& environment
                               , Element const& builtin_element
                               , std::vector<Element> const& parms )
{
    std::shared_ptr<Builtin_> builtin(std::dynamic_pointer_cast<Builtin_>(builtin_element.ElementHandle()));
    BuiltinsTable& table = *(builtin->table);
    BuiltinImplementation* impl = table.Get(builtin->Name());

    Element result;

    if (0 != builtin && 0 != impl)
    {
        std::vector<Element> output_parameters; 
        GlobalEnvironment globals(environment.Globals());
        Environment output_environment = Environment::Create(globals);
        bool success = Funcall_::CreateEnvironment( environment
                                                  , parms
                                                  , output_parameters);


        if (success && (0 != impl))
        {
            result = impl->Interpret( output_environment
                                    , output_parameters 
                                    , builtin->AdditionalParameter() );
        }
    }

    return result;
}
Example #16
0
/**
 * Cast the element to a True.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
True CastToTrue(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<True_> f = std::dynamic_pointer_cast<True_>(element_);
    success = (0 != f.get());
    return True();
}
Example #17
0
/**
 * Cast to variable.
 *
 * @param element The element we want to cast.
 * @param success is this cast successful?
 */
Variable CastToVariable(Element const& element ,bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<Variable_> s = std::dynamic_pointer_cast<Variable_>(element_);
    success = (0 != s.get());
    return success ? Variable(s, element.GetSourceLocation()) : Variable("");
}
Example #18
0
/**
 * Cast to a super string.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
SuperString CastToSuperString(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<SuperString_> s = std::dynamic_pointer_cast<SuperString_>(element_);
    success = (0 != s.get());
    return success ? SuperString(s, element.GetSourceLocation()) : SuperString();
}
Example #19
0
/**
 * Cast to tail recursion element.
 *
 * @param element The element we want to cast.
 * @param success is this cast successful?
 */
TailRecurse CastToTailRecurse(Element const& element ,bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<TailRecurse_> s = std::dynamic_pointer_cast<TailRecurse_>(element_);
    success = (0 != s.get());
    return success ? TailRecurse(s) : TailRecurse();
}
Example #20
0
/**
 * Cast to a number.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Number CastToNumber(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<Number_> number = std::dynamic_pointer_cast<Number_>(element_);
    success = (0 != number.get());
    return success ? Number(number, element.GetSourceLocation()) : Number();
}
Example #21
0
/**
 * Cast the element to an if.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
If CastToIf(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<If_> i = std::dynamic_pointer_cast<If_>(element_);
    success = (0 != i.get());
    return success ? If(i, element.GetSourceLocation()) : If();
}
Example #22
0
/**
 * Cast the element to an imperative.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Imperative CastToImperative(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<Imperative_> imperative = std::dynamic_pointer_cast<Imperative_>(element_);
    success = (0 != imperative.get());
    return success ? Imperative(imperative, element.GetSourceLocation()) : Imperative();
}
Example #23
0
/**
 * Cast the element to a Function.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Function CastToFunction(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<Function_> function = std::dynamic_pointer_cast<Function_>(element_);
    success = (0 != function.get());
    return success ? Function(function, element.GetSourceLocation()) : Function();
}
Example #24
0
void perform_cast(std::string& out, Element const& element)
{
    std::shared_ptr<String_> s = std::dynamic_pointer_cast<String_>(element.ElementHandle());
    if (s)
    {
        out = s->Value();
        return;
    }

    std::shared_ptr<SuperString_> ss = std::dynamic_pointer_cast<SuperString_>(element.ElementHandle());
    if (ss)
    {
        out = ss->Value();
        return;
    }

    out = element.ToString();
}
Example #25
0
/**
 * Interpret the element that will be again evaluated through the string 
 * engine.
 */
Element Evaluate_::Interpret_(Environment& environment)
{
    // Interpret the condition first. 
    Element E = this->element.Interpret(environment);

    if (strine::Types::STRING == E.Type())    
    {
        std::shared_ptr<String_> str = std::dynamic_pointer_cast<String_>(E.ElementHandle());
        E = this->strine.Interpret(str->Value());
    }
    else if (strine::Types::SUPERSTRING == E.Type())
    {
        std::shared_ptr<SuperString_> str = std::dynamic_pointer_cast<SuperString_>(E.ElementHandle());
        E = this->strine.Interpret(str->Value());
    }

    return E;
}
Element RemoteBuiltinImplementation::InterpretParsed_( Environment& environment
                                                     , Element& method_name_element
                                                     , Element& ip_address_element
                                                     , Element& port_element 
                                                     , std::vector<Element> const& parms) 
{
    String_* method_name = dynamic_cast<String_*>(method_name_element.ElementHandle());
    String_* ip_address = dynamic_cast<String_*>(ip_address_element.ElementHandle());
    Number_* port = dynamic_cast<Number_*>(port_element.ElementHandle());
    Element out;

    std::vector<Element> parameters;
    Funcall_::InterpretParameters( environment
                                 , parms
                                 , parameters );  

    if (  0 != method_name
       && 0 != ip_address
       && 0 != port )
    {
        std::stringstream ss;
        ss << '(' << method_name->Value();
        
        for(size_t i=0; i<parameters.size(); ++i)
        {
            ss << ' ';
            Printer printer(ss);
            parameters[i].Write(printer);
        }

        ss << ')';
 
        RemoteProcessing_* processing = new RemoteProcessing_( this->strine
                                                             , QString::fromStdString(ss.str())
                                                             , QString::fromStdString(ip_address->Value())
                                                             , port->IntValue() );
        out = Processing(processing); 
    } 
    return out;
}
Example #27
0
/**
 * Cast the element to a Builtin.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Builtin CastToBuiltin(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    Builtin_* builtin = dynamic_cast<Builtin_*>(element_);
    success = (0 != builtin);
    if (success)
    {
        return Builtin(builtin, element.GetSourceLocation());
    }
    else
    {
        return Builtin(static_cast<BuiltinsTable*>(0));
    }
}
Example #28
0
/**
 * Cast the element to a Builtin.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
Builtin CastToBuiltin(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<Builtin_> builtin = std::dynamic_pointer_cast<Builtin_>(element_);
    success = (0 != builtin.get());
    if (success)
    {
        return Builtin(builtin, element.GetSourceLocation());
    }
    else
    {
        return Builtin(static_cast<BuiltinsTable*>(0));
    }
}