File Coverage

lib/SPVM/Builder/src/spvm_class_file.c
Criterion Covered Total %
statement 48 68 70.5
branch 16 16 100.0
condition n/a
subroutine n/a
pod n/a
total 64 84 76.1


line stmt bran cond sub pod time code
1             // Copyright (c) 2023 Yuki Kimoto
2             // MIT License
3              
4             #include
5             #include
6              
7             #include "spvm_class_file.h"
8              
9             #include "spvm_allocator.h"
10             #include "spvm_compiler.h"
11             #include "spvm_string.h"
12              
13 0           SPVM_CLASS_FILE* SPVM_CLASS_FILE_new(SPVM_COMPILER* compiler) {
14            
15 0           return SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->class_file_allocator, sizeof(SPVM_CLASS_FILE));
16             }
17              
18 0           SPVM_CLASS_FILE* SPVM_CLASS_FILE_clone(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
19            
20 0           SPVM_CLASS_FILE* class_file_clone = SPVM_CLASS_FILE_new(compiler);
21            
22 0           class_file_clone->class_name = class_file->class_name;
23            
24 0           SPVM_CLASS_FILE_set_file(compiler, class_file_clone, class_file->file);
25            
26 0           SPVM_CLASS_FILE_set_dir(compiler, class_file_clone, class_file->dir);
27            
28 0           SPVM_CLASS_FILE_set_rel_file(compiler, class_file_clone, class_file->rel_file);
29            
30 0           SPVM_CLASS_FILE_set_content(compiler, class_file_clone, class_file->content);
31            
32 0           class_file_clone->content_length = class_file->content_length;
33            
34 0           return class_file_clone;
35             }
36              
37 0           const char* SPVM_CLASS_FILE_get_class_name(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
38 0           const char* class_name = class_file->class_name;
39 0           return class_name;
40             }
41              
42 0           const char* SPVM_CLASS_FILE_get_file(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
43 0           const char* file = class_file->file;
44 0           return file;
45             }
46              
47 42882           void SPVM_CLASS_FILE_set_file(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file, const char* file) {
48 42882 100         if (class_file->file) {
49 12075           SPVM_ALLOCATOR_free_memory_block_tmp(compiler->class_file_allocator, (void*)class_file->file);
50 12075           class_file->file = NULL;
51             }
52            
53 42882 100         if (file) {
54 16923           int32_t file_length = strlen(file);
55 16923           class_file->file = SPVM_ALLOCATOR_alloc_memory_block_tmp(compiler->class_file_allocator, file_length + 1);
56 16923           memcpy((void*)class_file->file, file, file_length);
57             }
58 42882           }
59              
60 0           const char* SPVM_CLASS_FILE_get_dir(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
61 0           const char* dir = class_file->dir;
62 0           return dir;
63             }
64              
65 42882           void SPVM_CLASS_FILE_set_dir(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file, const char* dir) {
66 42882 100         if (class_file->dir) {
67 12075           SPVM_ALLOCATOR_free_memory_block_tmp(compiler->class_file_allocator, (void*)class_file->dir);
68 12075           class_file->dir = NULL;
69             }
70            
71 42882 100         if (dir) {
72 16923           int32_t dir_length = strlen(dir);
73 16923           class_file->dir = SPVM_ALLOCATOR_alloc_memory_block_tmp(compiler->class_file_allocator, dir_length + 1);
74 16923           memcpy((void*)class_file->dir, dir, dir_length);
75             }
76 42882           }
77              
78 99           const char* SPVM_CLASS_FILE_get_rel_file(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
79 99           const char* rel_file = class_file->rel_file;
80 99           return rel_file;
81             }
82              
83 60894           void SPVM_CLASS_FILE_set_rel_file(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file, const char* rel_file) {
84 60894 100         if (class_file->rel_file) {
85 25959           SPVM_ALLOCATOR_free_memory_block_tmp(compiler->class_file_allocator, (void*)class_file->rel_file);
86 25959           class_file->rel_file = NULL;
87             }
88            
89 60894 100         if (rel_file) {
90 34935           int32_t rel_file_length = strlen(rel_file);
91 34935           class_file->rel_file = SPVM_ALLOCATOR_alloc_memory_block_tmp(compiler->class_file_allocator, rel_file_length + 1);
92 34935           memcpy((void*)class_file->rel_file, rel_file, rel_file_length);
93             }
94 60894           }
95              
96 99           const char* SPVM_CLASS_FILE_get_content(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
97 99           const char* content = class_file->content;
98 99           return content;
99             }
100              
101 60894           void SPVM_CLASS_FILE_set_content(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file, const char* content) {
102 60894 100         if (class_file->content) {
103 25959           SPVM_ALLOCATOR_free_memory_block_tmp(compiler->class_file_allocator, (void*)class_file->content);
104 25959           class_file->content = NULL;
105             }
106            
107 60894 100         if (content) {
108 34935           int32_t content_length = strlen(content);
109 34935           class_file->content = SPVM_ALLOCATOR_alloc_memory_block_tmp(compiler->class_file_allocator, content_length + 1);
110 34935           memcpy((void*)class_file->content, content, content_length);
111             }
112 60894           }
113              
114 99           int32_t SPVM_CLASS_FILE_get_content_length(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file) {
115 99           int32_t content_length = class_file->content_length;
116 99           return content_length;
117             }
118              
119 34935           void SPVM_CLASS_FILE_set_content_length(SPVM_COMPILER* compiler, SPVM_CLASS_FILE* class_file, int32_t content_length) {
120 34935           class_file->content_length = content_length;
121 34935           }