File: csdbparser.h

package info (click to toggle)
codequery 0.21.1%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,012 kB
  • sloc: cpp: 114,603; xml: 16,576; python: 6,512; ansic: 3,262; perl: 444; makefile: 324; sql: 160; sh: 43; objc: 19; ruby: 6; php: 1
file content (169 lines) | stat: -rw-r--r-- 3,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

/*
 * CodeQuery
 * Copyright (C) 2013-2017 ruben2020 https://github.com/ruben2020/
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */


// Cscope database parser

#ifndef CSDBPARSER_H_CQ
#define CSDBPARSER_H_CQ

#include <string>
#include <memory>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CSDBP_MINIM_BUFSIZE      (20000)
#define CSDBP_SUPPORTED_VER      "15"
#define CSDBP_SUPPORTED_VER_NUM  (15)
#define CSDBP_SUP_PARAM          " -c               "
#define CSDBP_SUP_PARAM2         " -c "

typedef std::vector<std::string> strvect;


// sym_data ///////////////////////////////////////////////////

class sym_data
{
public:

enum enSymType
  {
   symNone = 0,
   symFuncDef,
   symFuncCall,
   symMacroDef,
   symIncl,
   symDrctAssgnIncrDecr,
   symClass,
   symEnum,
   symGlobal,
   symLocalFuncBlockDef,
   symGlobalEnumStructUnion,
   symFuncParam,
   symStruct,
   symTypeDef,
   symUnion,
   symFile
  };

sym_data();
sym_data(const sym_data& copy);
sym_data& operator= (const sym_data& copy);
~sym_data() { /* nothing to do */ }
void clear(void);
std::string symbname_escaped(void);
const char* getTypeDesc(void);
const char getTypeChar(void);

bool valid;
std::string symbname;
enSymType sym_type;
std::string calling_func;
std::string calling_macro;
}; // class sym_data

typedef std::vector<sym_data> symdatalist;


// symdata_pack ///////////////////////////////////////////////////

class symdata_pack
{
public:
bool valid;
std::string filename;
long int line_num;
std::string line_text;
symdatalist symbols;

symdata_pack();
symdata_pack(const symdata_pack& copy);
symdata_pack& operator= (const symdata_pack& copy);
~symdata_pack() { /* nothing to do */ }
void clear(void);
std::string line_num_str(void);
std::string line_text_escaped(void);
std::string line_text_blob(void);
std::string line_text_replacetab(void);
}; // class symdata_pack


// csdbparser ///////////////////////////////////////////////////

class csdbparser
{

public:

enum enResult
  {
   resOK = 0,
   resFILE_NOT_FOUND,
   resFILE_ACCESS_ERR,
   resUNRECOG_FORMAT,
   resINCORRECT_VER,
   resUNSUPPORTED_PARAM,
   resOTHER_ERR,
   resUNKNOWN_ERR,
   resFILE_NOT_OPEN
  };

enum enState
  {
   stIDLE = 0,
   stSYMB_SETUP_DONE
  };


csdbparser();
~csdbparser();

enResult open_file(const char *fn);
bool isFileOpen(void) {return (m_fp != NULL);}
void close_file(void);
static enResult file_sanity_check(const char *fn);

enResult setup_srcfil_read(void);
enResult get_next_srcfil(std::string* srcfil);

enResult setup_symbol_read(void);
enResult get_next_symbol(symdata_pack* pack);

const char* getBasePath(void);
void setDebug(bool val);

private:
FILE *m_fp;
char *m_buf;
long int m_bufsize;
enState m_state;
long int m_trailer_start;
std::string m_base_path;
std::string m_calling_func;
std::string m_calling_macro;
std::string m_current_srcfile;
bool m_debug;

void create_buf(long int size = CSDBP_MINIM_BUFSIZE);
void destroy_buf(void);
enResult parse_headers(void);
enResult single_line_symbol(bool& endOfSymbData, bool& foundSomething);
enResult symbolread(sym_data* data, symdata_pack* pack);

}; // class csdbparser


#endif //CSDBPARSER_H_CQ