openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

context.h (3760B)


      1 /* 
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        context.h
      8  * Purpose:     API mode contextualizer interface
      9  */
     10 
     11 #ifndef   _CONTEXT_H_
     12 #define   _CONTEXT_H_
     13 
     14 #include "tokenizer.h"
     15 #include "api_mode_yy.h"
     16 #include "api_grammar.tab.h"
     17 #include "api_grammar.tab.h"
     18 #include "cint_variables.h"
     19 
     20 /* Return TRUE if 'c' is an uppercase letter */
     21 #define UPPERCASE(c) (((c) >= 'A') && ((c) <= 'Z'))
     22 
     23 #define CONTEXT_MAX_PFX 10
     24 #define CONTEXT_MAX_BUFFER 256
     25 
     26 typedef enum api_mode_context_qual_e {
     27     api_mode_context_qual_unknown,      /* Unknown grammar */
     28     api_mode_context_qual_function,     /* Function grammar */
     29     api_mode_context_qual_variable,     /* variable assignment grammar */
     30     api_mode_context_qual_print,        /* print grammar */
     31     api_mode_context_qual_create        /* type construction grammar */
     32 } api_mode_context_qual_t;
     33 
     34 typedef struct api_mode_private_s {
     35     const char *name;                   /* func name */
     36     enum yytokentype grammar_type;      /* grammar type */
     37     api_mode_context_qual_t qual;       /* qualification */
     38 } api_mode_private_t;
     39 
     40 /* Note - dt is a *copy*, not a pointer, because the dt passed to
     41    the traverse is constructed 'on the fly' and on the stack of the
     42    CINT traverse. */
     43 
     44 typedef struct api_mode_cint_dt_db_entry_s {
     45     const char *name;                   /* CINT name */
     46     api_mode_private_t *private;        /* private API mode command */
     47     const cint_datatype_t dt;           /* CINT dt entry */
     48 } api_mode_cint_dt_db_entry_t;
     49 
     50 typedef struct api_mode_cint_dt_db_s {
     51     int count;                  /* total number of entries */
     52     int alloc;                  /* entried allocated */
     53     int idx;                    /* insertion index */
     54     int max;                    /* maximum length */
     55     api_mode_cint_dt_db_entry_t *entry;
     56 } api_mode_cint_dt_db_t;
     57 
     58 typedef struct api_mode_cint_var_db_s {
     59     int count;                  /* total number of entries */
     60     int alloc;                  /* entried allocated */
     61     int idx;                    /* insertion index */
     62     int max;                    /* maximum length */
     63     cint_variable_t *entry;
     64 } api_mode_cint_var_db_t;
     65 
     66 typedef struct api_mode_context_s {
     67     api_mode_context_qual_t qual; /* Context grammar qualification */
     68     char        *alloc;         /* allocation buffer */
     69     char        *match;         /* context match buffer */
     70     char        *join;          /* arg join pointer in match buffer */
     71     int         idx;            /* name table index */
     72     int         exact;          /* exact match */
     73     int         more;           /* overmatch */
     74     int         partial;        /* partial match */
     75     api_mode_cint_dt_db_entry_t *dt0; /* first DT match */
     76     api_mode_cint_dt_db_t *db;  /* function database */
     77     int         len;            /* number of info records */
     78     int         jlen;           /* join buffer length */
     79     int         mlen;           /* max match buffer length */
     80     int         num_ident;      /* number of leading identifiers */
     81     int         num_arg;        /* number of arguments */
     82     struct {
     83         enum yytokentype grammar_type;
     84         const cint_datatype_t *dt;
     85     } *info;
     86 } api_mode_context_t;
     87 
     88 
     89 extern int api_mode_contextualizer(api_mode_tokens_t *tokens,
     90                                    api_mode_context_t *ctx);
     91 
     92 extern int api_mode_contextualizer_free(api_mode_context_t *ctx);
     93 
     94 extern char *api_mode_bcm_prefix(char *buffer, int len, const char *name);
     95 
     96 extern int api_mode_context_initialize(void);
     97 extern int api_mode_context_uninitialize(void);
     98 
     99 #endif /* _CONTEXT_H_ */