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_process.h"
31 #include "sl_pp_public.h"
35 sl_pp_context_add_extension(struct sl_pp_context
*context
,
37 const char *name_string
)
39 struct sl_pp_extension ext
;
41 if (context
->num_extensions
== SL_PP_MAX_EXTENSIONS
) {
45 ext
.name
= sl_pp_context_add_unique_str(context
, name
);
50 ext
.name_string
= sl_pp_context_add_unique_str(context
, name_string
);
51 if (ext
.name_string
== -1) {
55 context
->extensions
[context
->num_extensions
++] = ext
;
60 sl_pp_process_extension(struct sl_pp_context
*context
,
61 const struct sl_pp_token_info
*input
,
64 struct sl_pp_process_state
*state
)
66 int extension_name
= -1;
68 struct sl_pp_token_info out
;
70 /* Grab the extension name. */
71 if (first
< last
&& input
[first
].token
== SL_PP_IDENTIFIER
) {
72 extension_name
= input
[first
].data
.identifier
;
75 if (extension_name
== -1) {
76 strcpy(context
->error_msg
, "expected identifier after `#extension'");
80 /* Make sure the extension is supported. */
81 if (extension_name
== context
->dict
.all
) {
82 out
.data
.extension
= extension_name
;
86 out
.data
.extension
= -1;
87 for (i
= 0; i
< context
->num_extensions
; i
++) {
88 if (extension_name
== context
->extensions
[i
].name_string
) {
89 out
.data
.extension
= extension_name
;
95 /* Grab the colon separating the extension name and behavior. */
96 while (first
< last
&& input
[first
].token
== SL_PP_WHITESPACE
) {
99 if (first
< last
&& input
[first
].token
== SL_PP_COLON
) {
102 strcpy(context
->error_msg
, "expected `:' after extension name");
105 while (first
< last
&& input
[first
].token
== SL_PP_WHITESPACE
) {
109 /* Grab the behavior name. */
110 if (first
< last
&& input
[first
].token
== SL_PP_IDENTIFIER
) {
111 behavior
= input
[first
].data
.identifier
;
114 if (behavior
== -1) {
115 strcpy(context
->error_msg
, "expected identifier after `:'");
119 if (behavior
== context
->dict
.require
) {
120 if (out
.data
.extension
== -1) {
121 strcpy(context
->error_msg
, "the required extension is not supported");
124 if (out
.data
.extension
== context
->dict
.all
) {
125 strcpy(context
->error_msg
, "invalid behavior for `all' extension: `require'");
128 out
.token
= SL_PP_EXTENSION_REQUIRE
;
129 } else if (behavior
== context
->dict
.enable
) {
130 if (out
.data
.extension
== -1) {
131 /* Warning: the extension cannot be enabled. */
134 if (out
.data
.extension
== context
->dict
.all
) {
135 strcpy(context
->error_msg
, "invalid behavior for `all' extension: `enable'");
138 out
.token
= SL_PP_EXTENSION_ENABLE
;
139 } else if (behavior
== context
->dict
.warn
) {
140 if (out
.data
.extension
== -1) {
141 /* Warning: the extension is not supported. */
144 out
.token
= SL_PP_EXTENSION_WARN
;
145 } else if (behavior
== context
->dict
.disable
) {
146 if (out
.data
.extension
== -1) {
147 /* Warning: the extension is not supported. */
150 out
.token
= SL_PP_EXTENSION_DISABLE
;
152 strcpy(context
->error_msg
, "unrecognised behavior name");
156 /* Grab the end of line. */
157 while (first
< last
&& input
[first
].token
== SL_PP_WHITESPACE
) {
161 strcpy(context
->error_msg
, "expected end of line after behavior name");
165 if (sl_pp_process_out(state
, &out
)) {