Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
"""Render Error Data.
 
Writes the error type declarations and definitions. The definitions include the list the C indexes by code, which is why an error
can be removed from the declaration but its code should not be reused."""
 
####################################################################################################################################
import os
 
from common.render import bld_comment_block, bld_enum, bld_header
from common.storage import file_write_differs
 
_MODULE = "error"
_DESCRIPTION = "Error Type Definition"
 
 
####################################################################################################################################
def _err_name(name):
    """Build the C name of an error, e.g. "file-open" becomes "FileOpenError"."""
 
    return bld_enum("", name) + "Error"
 
 
####################################################################################################################################
def _render_error_auto_h(err_list):
    """Render error.auto.h, which declares every error type."""
 
    result = bld_header(_MODULE, _DESCRIPTION) + "#ifndef COMMON_ERROR_ERROR_AUTO_H\n#define COMMON_ERROR_ERROR_AUTO_H\n"
 
    result += "\n" + bld_comment_block("Error type declarations")
 
    for err in err_list:
        result += "ERROR_DECLARE(%s);\n" % _err_name(err.name)
 
    return result + "\n#endif\n"
 
 
####################################################################################################################################
def _render_error_auto_c(err_list):
    """Render error.auto.c.inc, which defines every error type and the array the C looks them up in."""
 
    result = bld_header(_MODULE, _DESCRIPTION)
 
    result += "\n" + bld_comment_block("Error type definitions")
 
    for err in err_list:
        result += "ERROR_DEFINE(%3u, %s, %s, RuntimeError);\n" % (err.code, _err_name(err.name), "true" if err.fatal else "false")
 
    result += "\n" + bld_comment_block("Error type array")
    result += "static const ErrorType *const errorTypeList[] =\n{\n"
 
    for err in err_list:
        result += "    &%s,\n" % _err_name(err.name)
 
    return result + "    NULL,\n};\n"
 
 
####################################################################################################################################
def bld_err_render(path_build, err_list):
    """Render the error files."""
 
    file_write_differs(os.path.join(path_build, "src/common/error/error.auto.h"), _render_error_auto_h(err_list))
    file_write_differs(os.path.join(path_build, "src/common/error/error.auto.c.inc"), _render_error_auto_c(err_list))