1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "sl_pp_context.h"
31 #include "sl_pp_macro.h"
32 #include "sl_pp_public.h"
33 #include "sl_pp_process.h"
34 #include "sl_pp_token.h"
38 sl_pp_process_line(struct sl_pp_context
*context
,
39 struct sl_pp_token_buffer
*buffer
,
40 struct sl_pp_process_state
*pstate
)
42 struct sl_pp_process_state state
;
49 memset(&state
, 0, sizeof(state
));
51 struct sl_pp_token_info input
;
53 sl_pp_token_buffer_get(buffer
, &input
);
54 switch (input
.token
) {
55 case SL_PP_WHITESPACE
:
58 case SL_PP_IDENTIFIER
:
59 sl_pp_token_buffer_unget(buffer
, &input
);
60 if (sl_pp_macro_expand(context
, buffer
, NULL
, &state
, sl_pp_macro_expand_normal
)) {
72 if (sl_pp_process_out(&state
, &input
)) {
73 strcpy(context
->error_msg
, "out of memory");
80 if (state
.out_len
> 0 && state
.out
[0].token
== SL_PP_UINT
) {
81 line_number
= state
.out
[0].data
._uint
;
83 strcpy(context
->error_msg
, "expected a number after `#line'");
88 if (state
.out_len
> 1) {
89 if (state
.out
[1].token
== SL_PP_UINT
) {
90 file_number
= state
.out
[1].data
._uint
;
92 strcpy(context
->error_msg
, "expected a number after line number");
97 if (state
.out_len
> 2) {
98 strcpy(context
->error_msg
, "expected an end of line after file number");
106 line
= atoi(sl_pp_context_cstr(context
, line_number
));
107 if (file_number
!= -1) {
108 file
= atoi(sl_pp_context_cstr(context
, file_number
));
110 file
= context
->file
;
113 if (context
->line
!= line
|| context
->file
!= file
) {
114 struct sl_pp_token_info ti
;
116 ti
.token
= SL_PP_LINE
;
117 ti
.data
.line
.lineno
= line
;
118 ti
.data
.line
.fileno
= file
;
119 if (sl_pp_process_out(pstate
, &ti
)) {
120 strcpy(context
->error_msg
, "out of memory");
124 context
->line
= line
;
125 context
->file
= file
;