MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / compile

Method compile

src/Gui/PythonConsole.cpp:179–199  ·  view source on GitHub ↗

* Compile a command and determine whether it is incomplete. * * The source string may contain line feeds and/or carriage returns. \n * Return value / exceptions raised: * - Return a code object if the command is complete and valid * - Return None if the command is incomplete * - Raise SyntaxError, ValueError or OverflowError if the command is a * syntax error (OverflowError and Value

Source from the content-addressed store, hash-verified

177 * malformed literals).
178 */
179PyObject* InteractiveInterpreter::compile(const char* source) const
180{
181 Base::PyGILStateLocker lock;
182 PyObject* func = PyObject_GetAttrString(d->interpreter, "compile");
183 PyObject* args = Py_BuildValue("(s)", source);
184 PyObject* eval = PyObject_CallObject(func, args); // must decref later
185
186 Py_XDECREF(args);
187 Py_XDECREF(func);
188
189 if (eval) {
190 return eval;
191 }
192 else {
193 // do not throw Base::PyException as this clears the error indicator
194 throw Base::RuntimeError("Code evaluation failed");
195 }
196
197 // can never happen
198 return nullptr;
199}
200
201/**
202 * Compile a command and determine whether it is incomplete.

Callers 15

params_utils.pyFile · 0.80
SetUpFilterFunction · 0.80
SetupFilterFunction · 0.80
SetupFilterFunction · 0.80
SetUpFilterFunction · 0.80
model.pyFile · 0.80
replaceFunction · 0.80
generateTools.pyFile · 0.80
rename_groupsMethod · 0.80
versionMethod · 0.80

Calls

no outgoing calls