| author | |
| committer | |
| log | f537c51f2560564042da690e8fe3b6e85d9592c8 |
| tree | 8c1570ea09a4978047bb45bd889f0f4dd989bb9c |
| parent | 1ab84a27d374e666463c606dc1cd1c4972b52a74 |
| parent | 57049b95b3fe183ea995f212b18e70212eaac23e |
5 files changed, 70 insertions(+), 7 deletions(-)
src/c_tokenizer.cpp+4-3| ... | ... | @@ -216,9 +216,8 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) { |
| 216 | 216 | buf_append_char(&ctok->buf, '0'); |
| 217 | 217 | break; |
| 218 | 218 | case '.': |
| 219 | begin_token(ctok, CTokIdNumLitFloat); | |
| 220 | ctok->state = CTokStateFloat; | |
| 221 | buf_init_from_str(&ctok->buf, "0."); | |
| 219 | begin_token(ctok, CTokIdDot); | |
| 220 | end_token(ctok); | |
| 222 | 221 | break; |
| 223 | 222 | case '(': |
| 224 | 223 | begin_token(ctok, CTokIdLParen); |
| ... | ... | @@ -238,6 +237,8 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) { |
| 238 | 237 | break; |
| 239 | 238 | case CTokStateFloat: |
| 240 | 239 | switch (*c) { |
| 240 | case '.': | |
| 241 | break; | |
| 241 | 242 | case 'e': |
| 242 | 243 | case 'E': |
| 243 | 244 | buf_append_char(&ctok->buf, 'e'); |
src/c_tokenizer.hpp+1| ... | ... | @@ -21,6 +21,7 @@ enum CTokId { |
| 21 | 21 | CTokIdLParen, |
| 22 | 22 | CTokIdRParen, |
| 23 | 23 | CTokIdEOF, |
| 24 | CTokIdDot, | |
| 24 | 25 | }; |
| 25 | 26 | |
| 26 | 27 | enum CNumLitSuffix { |
src/ir.cpp+2-1| ... | ... | @@ -6302,8 +6302,9 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char |
| 6302 | 6302 | buf_appendf(name, ")"); |
| 6303 | 6303 | return name; |
| 6304 | 6304 | } else { |
| 6305 | //Note: C-imports do not have valid location information | |
| 6305 | 6306 | return buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", kind_name, |
| 6306 | buf_ptr(source_node->owner->path), source_node->line + 1, source_node->column + 1); | |
| 6307 | (source_node->owner->path != nullptr) ? buf_ptr(source_node->owner->path) : "(null)", source_node->line + 1, source_node->column + 1); | |
| 6307 | 6308 | } |
| 6308 | 6309 | } |
| 6309 | 6310 | } |
src/translate_c.cpp+27-3| ... | ... | @@ -3517,7 +3517,6 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) { |
| 3517 | 3517 | } |
| 3518 | 3518 | |
| 3519 | 3519 | const char *raw_name = decl_name(record_decl); |
| 3520 | ||
| 3521 | 3520 | const char *container_kind_name; |
| 3522 | 3521 | ContainerKind container_kind; |
| 3523 | 3522 | if (record_decl->isUnion()) { |
| ... | ... | @@ -3869,9 +3868,33 @@ static AstNode *parse_ctok(Context *c, CTokenize *ctok, size_t *tok_i) { |
| 3869 | 3868 | return parse_ctok_num_lit(c, ctok, tok_i, false); |
| 3870 | 3869 | case CTokIdSymbol: |
| 3871 | 3870 | { |
| 3872 | *tok_i += 1; | |
| 3871 | bool need_symbol = false; | |
| 3872 | CTokId curr_id = CTokIdSymbol; | |
| 3873 | 3873 | Buf *symbol_name = buf_create_from_buf(&tok->data.symbol); |
| 3874 | return trans_create_node_symbol(c, symbol_name); | |
| 3874 | AstNode *curr_node = trans_create_node_symbol(c, symbol_name); | |
| 3875 | AstNode *parent_node = curr_node; | |
| 3876 | do { | |
| 3877 | *tok_i += 1; | |
| 3878 | CTok* curr_tok = &ctok->tokens.at(*tok_i); | |
| 3879 | if (need_symbol) { | |
| 3880 | if (curr_tok->id == CTokIdSymbol) { | |
| 3881 | symbol_name = buf_create_from_buf(&curr_tok->data.symbol); | |
| 3882 | curr_node = trans_create_node_field_access(c, parent_node, buf_create_from_buf(symbol_name)); | |
| 3883 | parent_node = curr_node; | |
| 3884 | need_symbol = false; | |
| 3885 | } else { | |
| 3886 | return nullptr; | |
| 3887 | } | |
| 3888 | } else { | |
| 3889 | if (curr_tok->id == CTokIdDot) { | |
| 3890 | need_symbol = true; | |
| 3891 | continue; | |
| 3892 | } else { | |
| 3893 | break; | |
| 3894 | } | |
| 3895 | } | |
| 3896 | } while (curr_id != CTokIdEOF); | |
| 3897 | return curr_node; | |
| 3875 | 3898 | } |
| 3876 | 3899 | case CTokIdLParen: |
| 3877 | 3900 | { |
| ... | ... | @@ -3885,6 +3908,7 @@ static AstNode *parse_ctok(Context *c, CTokenize *ctok, size_t *tok_i) { |
| 3885 | 3908 | *tok_i += 1; |
| 3886 | 3909 | return inner_node; |
| 3887 | 3910 | } |
| 3911 | case CTokIdDot: | |
| 3888 | 3912 | case CTokIdEOF: |
| 3889 | 3913 | case CTokIdRParen: |
| 3890 | 3914 | // not able to make sense of this |
test/translate_c.zig+36| ... | ... | @@ -1046,6 +1046,42 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1046 | 1046 | \\ return x + 13; |
| 1047 | 1047 | \\} |
| 1048 | 1048 | ); |
| 1049 | ||
| 1050 | cases.add("macros with field targets", | |
| 1051 | \\typedef unsigned int GLbitfield; | |
| 1052 | \\typedef void (*PFNGLCLEARPROC) (GLbitfield mask); | |
| 1053 | \\typedef void(*OpenGLProc)(void); | |
| 1054 | \\union OpenGLProcs { | |
| 1055 | \\ OpenGLProc ptr[1]; | |
| 1056 | \\ struct { | |
| 1057 | \\ PFNGLCLEARPROC Clear; | |
| 1058 | \\ } gl; | |
| 1059 | \\}; | |
| 1060 | \\extern union OpenGLProcs glProcs; | |
| 1061 | \\#define glClearUnion glProcs.gl.Clear | |
| 1062 | \\#define glClearPFN PFNGLCLEARPROC | |
| 1063 | , | |
| 1064 | \\pub const GLbitfield = c_uint; | |
| 1065 | , | |
| 1066 | \\pub const PFNGLCLEARPROC = ?extern fn(GLbitfield); | |
| 1067 | , | |
| 1068 | \\pub const OpenGLProc = ?extern fn(); | |
| 1069 | , | |
| 1070 | \\pub const union_OpenGLProcs = extern union { | |
| 1071 | \\ ptr: [1]OpenGLProc, | |
| 1072 | \\ gl: extern struct { | |
| 1073 | \\ Clear: PFNGLCLEARPROC, | |
| 1074 | \\ }, | |
| 1075 | \\}; | |
| 1076 | , | |
| 1077 | \\pub extern var glProcs: union_OpenGLProcs; | |
| 1078 | , | |
| 1079 | \\pub const glClearPFN = PFNGLCLEARPROC; | |
| 1080 | , | |
| 1081 | \\pub const glClearUnion = glProcs.gl.Clear; | |
| 1082 | , | |
| 1083 | \\pub const OpenGLProcs = union_OpenGLProcs; | |
| 1084 | ); | |
| 1049 | 1085 | |
| 1050 | 1086 | cases.add("switch statement with no default", |
| 1051 | 1087 | \\int foo(int x) { |