blob: ef821a7637acc9646498f060d5a237445c967737 [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 Worth8f6a8282010-05-14 10:44:19 -070045typedef struct argument_node {
46 string_list_t *argument;
47 struct argument_node *next;
48} argument_node_t;
49
50typedef struct argument_list {
51 argument_node_t *head;
52 argument_node_t *tail;
53} argument_list_t;
54
Carl Worth33cc4002010-05-12 12:17:10 -070055typedef struct glcpp_parser glcpp_parser_t;
56
Carl Wortha807fb72010-05-18 22:10:04 -070057typedef enum {
58 TOKEN_CLASS_ARGUMENT,
59 TOKEN_CLASS_IDENTIFIER,
60 TOKEN_CLASS_FUNC_MACRO,
61 TOKEN_CLASS_OBJ_MACRO
62} token_class_t;
63
64token_class_t
65glcpp_parser_classify_token (glcpp_parser_t *parser,
66 const char *identifier,
67 int *parameter_index);
68
69typedef struct {
70 int is_function;
71 string_list_t *parameters;
72 const char *identifier;
Carl Worthaaa9acb2010-05-19 13:28:24 -070073 string_list_t *replacements;
Carl Wortha807fb72010-05-18 22:10:04 -070074} macro_t;
75
76typedef struct expansion_node {
77 macro_t *macro;
78 argument_list_t *arguments;
Carl Worthaaa9acb2010-05-19 13:28:24 -070079 string_node_t *replacements;
Carl Wortha807fb72010-05-18 22:10:04 -070080 struct expansion_node *next;
81} expansion_node_t;
82
83struct glcpp_parser {
84 yyscan_t scanner;
85 struct hash_table *defines;
86 expansion_node_t *expansions;
Carl Wortha807fb72010-05-18 22:10:04 -070087};
88
Carl Worthaaa9acb2010-05-19 13:28:24 -070089void
90glcpp_parser_push_expansion_argument (glcpp_parser_t *parser,
91 int argument_index);
92
Carl Worth33cc4002010-05-12 12:17:10 -070093glcpp_parser_t *
94glcpp_parser_create (void);
Carl Worth0b27b5f2010-05-10 16:16:06 -070095
96int
97glcpp_parser_parse (glcpp_parser_t *parser);
98
99void
Carl Worth33cc4002010-05-12 12:17:10 -0700100glcpp_parser_destroy (glcpp_parser_t *parser);
Carl Worth0b27b5f2010-05-10 16:16:06 -0700101
102/* Generated by glcpp-lex.l to glcpp-lex.c */
103
Carl Wortha1e32bc2010-05-10 13:17:25 -0700104int
Carl Worth8f38aff2010-05-19 10:01:29 -0700105glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700106
107int
Carl Worth8f38aff2010-05-19 10:01:29 -0700108glcpp_lex (yyscan_t scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700109
110int
Carl Worth8f38aff2010-05-19 10:01:29 -0700111glcpp_lex_destroy (yyscan_t scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700112
113/* Generated by glcpp-parse.y to glcpp-parse.c */
114
115int
Carl Worth0b27b5f2010-05-10 16:16:06 -0700116yyparse (glcpp_parser_t *parser);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700117
Carl Worth5070a202010-05-12 12:45:33 -0700118/* xtalloc - wrappers around talloc to check for out-of-memory */
119
120#define xtalloc(ctx, type) (type *)xtalloc_named_const(ctx, sizeof(type), #type)
121
Carl Wortha807fb72010-05-18 22:10:04 -0700122#define xtalloc_size(ctx, size) xtalloc_named_const(ctx, size, __location__)
123
Carl Worth5070a202010-05-12 12:45:33 -0700124void *
125xtalloc_named_const (const void *context, size_t size, const char *name);
126
127char *
128xtalloc_strdup (const void *t, const char *p);
129
Carl Wortha807fb72010-05-18 22:10:04 -0700130char *
131xtalloc_strndup (const void *t, const char *p, size_t n);
132
Carl Wortha1e32bc2010-05-10 13:17:25 -0700133#endif