]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Tools/framer/framer/template.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / framer / framer / template.py
1 """framer's C code templates.
2
3 Templates use the following variables:
4
5 FileName: name of the file that contains the C source code
6 ModuleName: name of the module, as in "import ModuleName"
7 ModuleDocstring: C string containing the module doc string
8 """
9
10 module_start = '#include "Python.h"'
11 member_include = '#include "structmember.h"'
12
13 module_doc = """\
14 PyDoc_STRVAR(%(ModuleName)s_doc,
15 %(ModuleDocstring)s);
16 """
17
18 methoddef_start = """\
19 static struct PyMethodDef %(MethodDefName)s[] = {"""
20
21 methoddef_def = """\
22 {"%(PythonName)s", (PyCFunction)%(CName)s, %(MethType)s},"""
23
24 methoddef_def_doc = """\
25 {"%(PythonName)s", (PyCFunction)%(CName)s, %(MethType)s,
26 %(DocstringVar)s},"""
27
28 methoddef_end = """\
29 {NULL, NULL}
30 };
31 """
32
33 memberdef_start = """\
34 #define OFF(X) offsetof(%(StructName)s, X)
35
36 static struct PyMemberDef %(MemberDefName)s[] = {"""
37
38 memberdef_def_doc = """\
39 {"%(PythonName)s", %(Type)s, OFF(%(CName)s), %(Flags)s,
40 %(Docstring)s},"""
41
42 memberdef_def = """\
43 {"%(PythonName)s", %(Type)s, OFF(%(CName)s), %(Flags)s},"""
44
45 memberdef_end = """\
46 {NULL}
47 };
48
49 #undef OFF
50 """
51
52 dealloc_func = """static void
53 %(name)s(PyObject *ob)
54 {
55 }
56 """
57
58 docstring = """\
59 PyDoc_STRVAR(%(DocstringVar)s,
60 %(Docstring)s);
61 """
62
63 funcdef_start = """\
64 static PyObject *
65 %(name)s(%(args)s)
66 {"""
67
68 funcdef_end = """\
69 }
70 """
71
72 varargs = """\
73 if (!PyArg_ParseTuple(args, \"%(ArgParse)s:%(PythonName)s\",
74 %(ArgTargets)s))
75 return NULL;"""
76
77 module_init_start = """\
78 PyMODINIT_FUNC
79 init%(ModuleName)s(void)
80 {
81 PyObject *mod;
82
83 mod = Py_InitModule3("%(ModuleName)s", %(MethodDefName)s,
84 %(ModuleName)s_doc);
85 if (mod == NULL)
86 return;
87 """
88
89 type_init_type = " %(CTypeName)s.ob_type = &PyType_Type;"
90 module_add_type = """\
91 if (!PyObject_SetAttrString(mod, "%(TypeName)s",
92 (PyObject *)&%(CTypeName)s))
93 return;
94 """
95
96 type_struct_start = """\
97 static PyTypeObject %(CTypeName)s = {
98 PyObject_HEAD_INIT(0)"""
99
100 type_struct_end = """\
101 };
102 """