File: python_type.cc

package info (click to toggle)
kig 4%3A25.08.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,716 kB
  • sloc: cpp: 41,465; xml: 851; python: 486; perl: 23; sh: 17; makefile: 3
file content (187 lines) | stat: -rw-r--r-- 4,232 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// SPDX-FileCopyrightText: 2003 Dominique Devriese <devriese@kde.org>

// SPDX-License-Identifier: GPL-2.0-or-later

#include "python_type.h"

#include "python_scripter.h"

#include "../objects/bogus_imp.h"
#include "../objects/object_imp.h"

class PythonCompiledScriptImp : public BogusImp
{
    mutable CompiledPythonScript mscript;

public:
    typedef BogusImp Parent;
    static const ObjectImpType *stype();
    const ObjectImpType *type() const override;

    PythonCompiledScriptImp(const CompiledPythonScript &s);

    void visit(ObjectImpVisitor *vtor) const override;
    ObjectImp *copy() const override;
    bool equals(const ObjectImp &rhs) const override;

    bool isCache() const override;

    CompiledPythonScript &data() const
    {
        return mscript;
    };
};

PythonCompiledScriptImp::PythonCompiledScriptImp(const CompiledPythonScript &s)
    : BogusImp()
    , mscript(s)
{
}

const ObjectImpType *PythonCompiledScriptImp::stype()
{
    static const ObjectImpType t(BogusImp::stype(), "python-compiled-script-imp", {}, {}, {}, {}, {}, {}, {}, {}, {});
    return &t;
}

const ObjectImpType *PythonCompiledScriptImp::type() const
{
    return PythonCompiledScriptImp::stype();
}

void PythonCompiledScriptImp::visit(ObjectImpVisitor *) const
{
    // TODO ?
}

ObjectImp *PythonCompiledScriptImp::copy() const
{
    return new PythonCompiledScriptImp(mscript);
}

bool PythonCompiledScriptImp::equals(const ObjectImp &) const
{
    // problem ?
    return true;
}

bool PythonCompiledScriptImp::isCache() const
{
    return true;
}

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(PythonCompileType)

PythonCompileType::PythonCompileType()
    : ObjectType("PythonCompileType")
{
}

PythonCompileType::~PythonCompileType()
{
}

const PythonCompileType *PythonCompileType::instance()
{
    static const PythonCompileType t;
    return &t;
}

const ObjectImpType *PythonCompileType::impRequirement(const ObjectImp *, const Args &) const
{
    return StringImp::stype();
}

const ObjectImpType *PythonCompileType::resultId() const
{
    return PythonCompiledScriptImp::stype();
}

ObjectImp *PythonCompileType::calc(const Args &parents, const KigDocument &) const
{
    assert(parents.size() == 1);
    if (!parents[0]->inherits(StringImp::stype()))
        return new InvalidImp;

    const StringImp *si = static_cast<const StringImp *>(parents[0]);
    QString s = si->data();

    CompiledPythonScript cs = PythonScripter::instance()->compile(s.toLatin1());

    if (cs.valid())
        return new PythonCompiledScriptImp(cs);
    else
        return new InvalidImp();
}

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(PythonExecuteType)

PythonExecuteType::PythonExecuteType()
    : ObjectType("PythonExecuteType")
{
}

PythonExecuteType::~PythonExecuteType()
{
}

const PythonExecuteType *PythonExecuteType::instance()
{
    static const PythonExecuteType t;
    return &t;
}

ObjectImp *PythonExecuteType::calc(const Args &parents, const KigDocument &d) const
{
    assert(parents.size() >= 1);
    if (!parents[0]->inherits(PythonCompiledScriptImp::stype()))
        return new InvalidImp;

    CompiledPythonScript &script = static_cast<const PythonCompiledScriptImp *>(parents[0])->data();

    Args args(parents.begin() + 1, parents.end());
    return script.calc(args, d);
}

const ObjectImpType *PythonExecuteType::impRequirement(const ObjectImp *o, const Args &parents) const
{
    if (o == parents[0])
        return PythonCompiledScriptImp::stype();
    else
        return ObjectImp::stype();
}

const ObjectImpType *PythonExecuteType::resultId() const
{
    return ObjectImp::stype();
}

std::vector<ObjectCalcer *> PythonCompileType::sortArgs(const std::vector<ObjectCalcer *> &args) const
{
    return args;
}

Args PythonCompileType::sortArgs(const Args &args) const
{
    return args;
}

std::vector<ObjectCalcer *> PythonExecuteType::sortArgs(const std::vector<ObjectCalcer *> &args) const
{
    return args;
}

Args PythonExecuteType::sortArgs(const Args &args) const
{
    return args;
}

bool PythonCompileType::isDefinedOnOrThrough(const ObjectImp *, const Args &) const
{
    return false;
}

bool PythonExecuteType::isDefinedOnOrThrough(const ObjectImp *, const Args &) const
{
    return false;
}