Line data Source code
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 : 13 84232 : void t_type::generate_fingerprint() { 14 84232 : std::string material = get_fingerprint_material(); 15 : md5_state_t ctx; 16 84232 : md5_init(&ctx); 17 84232 : md5_append(&ctx, (md5_byte_t*)(material.data()), (int)material.size()); 18 84232 : md5_finish(&ctx, (md5_byte_t*)fingerprint_); 19 84232 : } 20 : 21 397938 : t_type* t_type::get_true_type() { 22 397938 : t_type* type = this; 23 397938 : while (type->is_typedef()) { 24 0 : type = ((t_typedef*)type)->get_type(); 25 : } 26 397938 : return type; 27 : } 28 : 29 : #ifdef SANDESH 30 3408 : bool t_type::has_annotation(bool check_self, 31 : const std::vector<t_field*> &members, 32 : const t_program *program) const { 33 3408 : bool has_annotation = false; 34 : // First check self annotations 35 3408 : if (check_self) { 36 482 : has_annotation = t_type::has_key_annotation(); 37 482 : if (has_annotation) { 38 0 : return has_annotation; 39 : } 40 : } 41 : // Next check member annotations 42 3408 : std::vector<t_field*>::const_iterator m_iter; 43 14167 : for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { 44 11759 : if (((*m_iter)->get_type())->is_struct()) { 45 482 : const char *sname = ((*m_iter)->get_type())->get_name().c_str(); 46 482 : t_struct *cstruct = program->get_struct(sname); 47 482 : if (!cstruct) { 48 : // Check in includes 49 35 : const std::vector<t_program*>& includes = program->get_includes(); 50 35 : std::vector<t_program*>::const_iterator iter; 51 56 : for (iter = includes.begin(); iter != includes.end(); ++iter) { 52 56 : cstruct = (*iter)->get_struct(sname); 53 56 : if (cstruct) { 54 35 : break; 55 : } 56 : } 57 : } 58 482 : if (!cstruct) { 59 0 : throw "compiler error: CANNOT FIND struct: " + std::string(sname); 60 : } 61 482 : has_annotation = cstruct->has_key_annotation(); 62 : } else { 63 11277 : has_annotation = (*m_iter)->has_key_annotation(); 64 : } 65 11759 : if (has_annotation) { 66 1000 : return has_annotation; 67 : } 68 : } 69 2408 : return has_annotation; 70 : } 71 : 72 482 : bool t_struct::has_key_annotation() const { 73 482 : return t_type::has_annotation(true, members_, program_); 74 : } 75 : 76 2926 : bool t_sandesh::has_key_annotation() const { 77 2926 : return has_annotation(false, members_, program_); 78 : } 79 : #endif // !SANDESH