OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse.cc
Go to the documentation of this file.
1 #ifdef SANDESH
2 #include <stdio.h>
3 #endif // !SANDESH
4 #include "t_type.h"
5 #include "t_typedef.h"
6 #ifdef SANDESH
7 #include "t_program.h"
8 #include "t_struct.h"
9 #endif // !SANDESH
10 
11 #include "md5.h"
12 
14  std::string material = get_fingerprint_material();
15  md5_state_t ctx;
16  md5_init(&ctx);
17  md5_append(&ctx, (md5_byte_t*)(material.data()), (int)material.size());
19 }
20 
22  t_type* type = this;
23  while (type->is_typedef()) {
24  type = ((t_typedef*)type)->get_type();
25  }
26  return type;
27 }
28 
29 #ifdef SANDESH
30 bool t_type::has_annotation(bool check_self,
31  const std::vector<t_field*> &members,
32  const t_program *program) const {
33  bool has_annotation = false;
34  // First check self annotations
35  if (check_self) {
36  has_annotation = t_type::has_key_annotation();
37  if (has_annotation) {
38  return has_annotation;
39  }
40  }
41  // Next check member annotations
42  std::vector<t_field*>::const_iterator m_iter;
43  for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
44  if (((*m_iter)->get_type())->is_struct()) {
45  const char *sname = ((*m_iter)->get_type())->get_name().c_str();
46  t_struct *cstruct = program->get_struct(sname);
47  if (!cstruct) {
48  // Check in includes
49  const std::vector<t_program*>& includes = program->get_includes();
50  std::vector<t_program*>::const_iterator iter;
51  for (iter = includes.begin(); iter != includes.end(); ++iter) {
52  cstruct = (*iter)->get_struct(sname);
53  if (cstruct) {
54  break;
55  }
56  }
57  }
58  if (!cstruct) {
59  throw "compiler error: CANNOT FIND struct: " + std::string(sname);
60  }
61  has_annotation = cstruct->has_key_annotation();
62  } else {
63  has_annotation = (*m_iter)->has_key_annotation();
64  }
65  if (has_annotation) {
66  return has_annotation;
67  }
68  }
69  return has_annotation;
70 }
71 
72 bool t_struct::has_key_annotation() const {
73  return t_type::has_annotation(true, members_, program_);
74 }
75 
76 bool t_sandesh::has_key_annotation() const {
77  return has_annotation(false, members_, program_);
78 }
79 #endif // !SANDESH
void md5_init(md5_state_t *pms)
Definition: t_type.h:48
uint8_t fingerprint_[fingerprint_len]
Definition: t_type.h:203
const std::vector< t_program * > & get_includes() const
Definition: t_program.h:126
virtual std::string get_fingerprint_material() const =0
virtual bool is_typedef() const
Definition: t_type.h:71
void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
uint8_t type
Definition: load_balance.h:109
t_type * get_true_type()
Definition: parse.cc:21
members_type members_
virtual void generate_fingerprint()
Definition: parse.cc:13
unsigned char md5_byte_t
Definition: md5.h:63
virtual const std::string & get_name() const
Definition: t_type.h:56
virtual bool has_key_annotation() const
virtual bool is_struct() const
Definition: t_type.h:73
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
t_program * program_
Definition: t_type.h:200