blob: c25e29c6883db64b5bfd61075f95f2fba4896da0 [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 {
74 TOKEN_CLASS_ARGUMENT,
75 TOKEN_CLASS_IDENTIFIER,
Carl Worthb5693832010-05-20 08:01:44 -070076 TOKEN_CLASS_IDENTIFIER_FINALIZED,
Carl Wortha807fb72010-05-18 22:10:04 -070077 TOKEN_CLASS_FUNC_MACRO,
78 TOKEN_CLASS_OBJ_MACRO
79} token_class_t;
80
81token_class_t
82glcpp_parser_classify_token (glcpp_parser_t *parser,
83 const char *identifier,
84 int *parameter_index);
85
86typedef struct {
87 int is_function;
88 string_list_t *parameters;
89 const char *identifier;
Carl Worth47252442010-05-19 13:54:37 -070090 token_list_t *replacements;
Carl Wortha807fb72010-05-18 22:10:04 -070091} macro_t;
92
93typedef struct expansion_node {
94 macro_t *macro;
95 argument_list_t *arguments;
Carl Worth47252442010-05-19 13:54:37 -070096 token_node_t *replacements;
Carl Wortha807fb72010-05-18 22:10:04 -070097 struct expansion_node *next;
98} expansion_node_t;
99
100struct glcpp_parser {
101 yyscan_t scanner;
102 struct hash_table *defines;
103 expansion_node_t *expansions;
Carl Worth5a6b9a22010-05-20 14:29:43 -0700104 int just_printed_separator;
Carl Wortha807fb72010-05-18 22:10:04 -0700105};
106
Carl Worthaaa9acb2010-05-19 13:28:24 -0700107void
108glcpp_parser_push_expansion_argument (glcpp_parser_t *parser,
109 int argument_index);
110
Carl Worth33cc4002010-05-12 12:17:10 -0700111glcpp_parser_t *
112glcpp_parser_create (void);
Carl Worth0b27b5f2010-05-10 16:16:06 -0700113
114int
115glcpp_parser_parse (glcpp_parser_t *parser);
116
117void
Carl Worth33cc4002010-05-12 12:17:10 -0700118glcpp_parser_destroy (glcpp_parser_t *parser);
Carl Worth0b27b5f2010-05-10 16:16:06 -0700119
120/* Generated by glcpp-lex.l to glcpp-lex.c */
121
Carl Wortha1e32bc2010-05-10 13:17:25 -0700122int
Carl Worth8f38aff2010-05-19 10:01:29 -0700123glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700124
125int
Carl Worth8f38aff2010-05-19 10:01:29 -0700126glcpp_lex (yyscan_t scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700127
128int
Carl Worth8f38aff2010-05-19 10:01:29 -0700129glcpp_lex_destroy (yyscan_t scanner);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700130
131/* Generated by glcpp-parse.y to glcpp-parse.c */
132
133int
Carl Worth0b27b5f2010-05-10 16:16:06 -0700134yyparse (glcpp_parser_t *parser);
Carl Wortha1e32bc2010-05-10 13:17:25 -0700135
Carl Worth5070a202010-05-12 12:45:33 -0700136/* xtalloc - wrappers around talloc to check for out-of-memory */
137
138#define xtalloc(ctx, type) (type *)xtalloc_named_const(ctx, sizeof(type), #type)
139
Carl Wortha807fb72010-05-18 22:10:04 -0700140#define xtalloc_size(ctx, size) xtalloc_named_const(ctx, size, __location__)
141
Carl Worth5070a202010-05-12 12:45:33 -0700142void *
143xtalloc_named_const (const void *context, size_t size, const char *name);
144
145char *
146xtalloc_strdup (const void *t, const char *p);
147
Carl Wortha807fb72010-05-18 22:10:04 -0700148char *
149xtalloc_strndup (const void *t, const char *p, size_t n);
150
Carl Wortha1e32bc2010-05-10 13:17:25 -0700151#endif