blob: 33ece8f92b114fa5165a2700811128826d7113b1 [file] [log] [blame]
Carl Wortha1e32bc2010-05-10 13:17:25 -07001/*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#ifndef GLCPP_H
25#define GLCPP_H
26
Carl Wortha807fb72010-05-18 22:10:04 -070027#include <talloc.h>
28
Carl Worth0b27b5f2010-05-10 16:16:06 -070029#include "hash_table.h"
Carl Wortha1e32bc2010-05-10 13:17:25 -070030
31#define yyscan_t void*
32
Carl Wortha807fb72010-05-18 22:10:04 -070033/* Some data types used for parser values. */
Carl Worth0b27b5f2010-05-10 16:16:06 -070034
Carl Worth610053b2010-05-14 10:05:11 -070035typedef struct string_node {
Carl Worth33cc4002010-05-12 12:17:10 -070036 const char *str;
Carl Worth610053b2010-05-14 10:05:11 -070037 struct string_node *next;
38} string_node_t;
Carl Worth33cc4002010-05-12 12:17:10 -070039
Carl Worth610053b2010-05-14 10:05:11 -070040typedef struct string_list {
41 string_node_t *head;
42 string_node_t *tail;
43} string_list_t;
Carl Worth33cc4002010-05-12 12:17:10 -070044
Carl Worthb5693832010-05-20 08:01:44 -070045typedef struct token {
46 int type;
47 char *value;
48} token_t;
49
Carl Worth47252442010-05-19 13:54:37 -070050typedef struct token_node {
51 int type;
52 const char *value;
53 struct token_node *next;
54} token_node_t;
55
56typedef struct token_list {
57 token_node_t *head;
58 token_node_t *tail;
59} token_list_t;
60
Carl Worth8f6a8282010-05-14 10:44:19 -070061typedef struct argument_node {
Carl Worth47252442010-05-19 13:54:37 -070062 token_list_t *argument;
Carl Worth8f6a8282010-05-14 10:44:19 -070063 struct argument_node *next;
64} argument_node_t;
65
66typedef struct argument_list {
67 argument_node_t *head;
68 argument_node_t *tail;
69} argument_list_t;
70
Carl Worth33cc4002010-05-12 12:17:10 -070071typedef struct glcpp_parser glcpp_parser_t;
72
Carl Wortha807fb72010-05-18 22:10:04 -070073typedef enum {
Carl Wortha807fb72010-05-18 22:10:04 -070074 TOKEN_CLASS_IDENTIFIER,
Carl Worthb5693832010-05-20 08:01:44 -070075 TOKEN_CLASS_IDENTIFIER_FINALIZED,
Carl Wortha807fb72010-05-18 22:10:04 -070076 TOKEN_CLASS_FUNC_MACRO,
77 TOKEN_CLASS_OBJ_MACRO
78} token_class_t;
79
80token_class_t
81glcpp_parser_classify_token (glcpp_parser_t *parser,
82 const char *identifier,
83 int *parameter_index);
84
85typedef struct {
86 int is_function;
87 string_list_t *parameters;
88 const char *identifier;
Carl Worth47252442010-05-19 13:54:37 -070089 token_list_t *replacements;
Carl Wortha807fb72010-05-18 22:10:04 -070090} macro_t;
91
92typedef struct expansion_node {
93 macro_t *macro;
Carl Worth47252442010-05-19 13:54:37 -070094 token_node_t *replacements;
Carl Wortha807fb72010-05-18 22:10:04 -070095 struct expansion_node *next;
96} expansion_node_t;
97
Carl Worthb20d33c2010-05-20 22:27:07 -070098typedef enum skip_type {
99 SKIP_NO_SKIP,
100 SKIP_TO_ELSE,
101 SKIP_TO_ENDIF
102} skip_type_t;
103
104typedef struct skip_node {
105 skip_type_t type;
106 struct skip_node *next;
107} skip_node_t;
108
Carl Wortha807fb72010-05-18 22:10:04 -0700109struct glcpp_parser {
110 yyscan_t scanner;
111 struct hash_table *defines;
112 expansion_node_t *expansions;
Carl Worth5a6b9a22010-05-20 14:29:43 -0700113 int just_printed_separator;
Carl Worth876e5102010-05-20 14:38:06 -0700114 int need_newline;
Carl Worthb20d33c2010-05-20 22:27:07 -0700115 skip_node_t *skip_stack;
Carl Wortha807fb72010-05-18 22:10:04 -0700116};
117
Carl Worthaaa9acb2010-05-19 13:28:24 -0700118void
119glcpp_parser_push_expansion_argument (glcpp_parser_t *parser,
120 int argument_index);
121
Carl Worth33cc4002010-05-12 12:17:10 -0700122glcpp_parser_t *
123glcpp_parser_create (void);
Carl Worth0b27b5f2010-05-10 16:16:06 -0700124
125int
126glcpp_parser_parse (glcpp_parser_t *parser);
127
128void
Carl Worth33cc4002010-05-12 12:17:10 -0700129glcpp_parser_destroy (glcpp_parser_t *parser);
Carl Worth0b27b5f2010-05-10 16:16:06 -0700130
131/* Generated by glcpp-lex.l to glcpp-lex.c */
132
Carl Wortha1e32bc2010-05-10 13:17:25 -0700133int
Carl Worth8f38aff2010-05-19 10:01:29 -0700134glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700135
136int
Carl Worth8f38aff2010-05-19 10:01:29 -0700137glcpp_lex (yyscan_t scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700138
139int
Carl Worth8f38aff2010-05-19 10:01:29 -0700140glcpp_lex_destroy (yyscan_t scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700141
142/* Generated by glcpp-parse.y to glcpp-parse.c */
143
144int
Carl Worth0b27b5f2010-05-10 16:16:06 -0700145yyparse (glcpp_parser_t *parser);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700146
Carl Worth5070a202010-05-12 12:45:33 -0700147/* xtalloc - wrappers around talloc to check for out-of-memory */
148
149#define xtalloc(ctx, type) (type *)xtalloc_named_const(ctx, sizeof(type), #type)
150
Carl Wortha807fb72010-05-18 22:10:04 -0700151#define xtalloc_size(ctx, size) xtalloc_named_const(ctx, size, __location__)
152
Carl Worth5070a202010-05-12 12:45:33 -0700153void *
154xtalloc_named_const (const void *context, size_t size, const char *name);
155
156char *
157xtalloc_strdup (const void *t, const char *p);
158
Carl Wortha807fb72010-05-18 22:10:04 -0700159char *
160xtalloc_strndup (const void *t, const char *p, size_t n);
161
Carl Worthb8945832010-05-20 15:02:03 -0700162char *
163xtalloc_asprintf (const void *t, const char *fmt, ...);
164
Carl Wortha1e32bc2010-05-10 13:17:25 -0700165#endif