Exemple #1
0
static void
channm(Lextok *n)
{	char lbuf[512];

	if (n->sym->type == CHAN)
		strcat(Buf, n->sym->name);
	else if (n->sym->type == NAME)
		strcat(Buf, lookup(n->sym->name)->name);
	else if (n->sym->type == STRUCT)
	{	Symbol *r = n->sym;
		if (r->context)
		{	r = findloc(r);
			if (!r)
			{	strcat(Buf, "*?*");
				return;
		}	}
		ini_struct(r);
		printf("%s", r->name);
		strcpy(lbuf, "");
		struct_name(n->lft, r, 1, lbuf);
		strcat(Buf, lbuf);
	} else
		strcat(Buf, "-");
	if (n->lft->lft)
	{	sprintf(lbuf, "[%d]", eval(n->lft->lft));
		strcat(Buf, lbuf);
	}
}
Exemple #2
0
void
struct_name(Lextok *n, Symbol *v, int xinit, char *buf)
{	Symbol *tl;
	Lextok *tmp;
	char lbuf[512];

	if (!n || !(tl = do_same(n, v, xinit)))
		return;
	tmp = n->rgt->lft;
	if (tmp->sym->type == STRUCT)
	{	strcat(buf, ".");
		struct_name(tmp, tl, 0, buf);
		return;
	}
	sprintf(lbuf, ".%s", tl->name);
	strcat(buf, lbuf);
	if (tmp->sym->nel > 1)
	{	sprintf(lbuf, "[%d]", eval(tmp->lft));
		strcat(buf, lbuf);
	}
}
Exemple #3
0
void
FE_Utils::create_uses_multiple_stuff (AST_Component *c,
                                      AST_Uses *u,
                                      const char *prefix)
{
  ACE_CString struct_name (prefix);

  if (!struct_name.empty ())
    {
      struct_name += '_';
    }

  struct_name += u->local_name ()->get_string ();
  struct_name += "Connection";
  Identifier struct_id (struct_name.c_str ());
  UTL_ScopedName sn (&struct_id, 0);

  // In case this call comes from the backend. We
  // will pop the scope before returning.
  idl_global->scopes ().push (c);

  AST_Structure *connection =
    idl_global->gen ()->create_structure (&sn, 0, 0);

  struct_id.destroy ();

  /// If the field type is a param holder, we want
  /// to use the lookup to create a fresh one,
  /// since the field will own it and destroy it.
  UTL_ScopedName *fn = u->uses_type ()->name ();
  AST_Decl *d =
    idl_global->root ()->lookup_by_name (fn, true, false);
  AST_Type *ft = AST_Type::narrow_from_decl (d);

  Identifier object_id ("objref");
  UTL_ScopedName object_name (&object_id,
                              0);
  AST_Field *object_field =
    idl_global->gen ()->create_field (ft,
                                      &object_name,
                                      AST_Field::vis_NA);
  (void) DeclAsScope (connection)->fe_add_field (object_field);
  object_id.destroy ();

  Identifier local_id ("Cookie");
  UTL_ScopedName local_name (&local_id,
                             0);
  Identifier module_id ("Components");
  UTL_ScopedName scoped_name (&module_id,
                              &local_name);

  d = c->lookup_by_name (&scoped_name, true);
  local_id.destroy ();
  module_id.destroy ();

  if (d == 0)
    {
      // This would happen if we haven't included Components.idl.
      idl_global->err ()->lookup_error (&scoped_name);
      return;
    }

  AST_ValueType *cookie = AST_ValueType::narrow_from_decl (d);

  Identifier cookie_id ("ck");
  UTL_ScopedName cookie_name (&cookie_id,
                              0);
  AST_Field *cookie_field =
    idl_global->gen ()->create_field (cookie,
                                      &cookie_name,
                                      AST_Field::vis_NA);
  (void) DeclAsScope (connection)->fe_add_field (cookie_field);
  cookie_id.destroy ();

  (void) c->fe_add_structure (connection);

  ACE_CDR::ULong bound = 0;
  AST_Expression *bound_expr =
    idl_global->gen ()->create_expr (bound,
                                     AST_Expression::EV_ulong);
  AST_Sequence *sequence =
    idl_global->gen ()->create_sequence (bound_expr,
                                         connection,
                                         0,
                                         0,
                                         0);

  ACE_CString seq_string (struct_name);
  seq_string += 's';
  Identifier seq_id (seq_string.c_str ());
  UTL_ScopedName seq_name (&seq_id,
                           0);
  AST_Typedef *connections =
    idl_global->gen ()->create_typedef (sequence,
                                        &seq_name,
                                        0,
                                        0);
  seq_id.destroy ();

  (void) c->fe_add_typedef (connections);

  // In case this call comes from the backend.
  idl_global->scopes ().pop ();
}
Exemple #4
0
void Msg_Struct::build_http_msg_buffer(Isolate* isolate, v8::Local<v8::Object> object, std::string &str) {
    std::stringstream stream;
    for(std::vector<Field_Info>::const_iterator iter = field_vec().begin();
            iter != field_vec().end(); iter++) {
        stream.str("");
        stream << "\"" << iter->field_name << "\":";
        Local<Value> value = object->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked()).ToLocalChecked();
        if(iter->field_type == "int8" || iter->field_type == "int16" ||
                iter->field_type == "int32") {
            int32_t val = 0;
            if (value->IsInt32()) {
                val = value->Int32Value(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "int64") {
            int64_t val = 0;
            if (value->IsNumber()) {
                val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "double") {
            double val = 0;
            if (value->IsNumber()) {
                val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "bool") {
            bool val = 0;
            if (value->IsBoolean()) {
                val = value->BooleanValue(isolate->GetCurrentContext()).FromJust();
            }
            stream << val << ",";
        }
        else if(iter->field_type == "string") {
            if (value->IsString()) {
                String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked());
                stream << "\"" << ToCString(str) << "\",";
            } else {
                stream << "\"\",";
            }
        }
        else {
            LOG_ERROR("Can not find the field_type:%s, struct_name:%s", iter->field_type.c_str(), struct_name().c_str());
        }

        str += stream.str();
    }
}
Exemple #5
0
void Msg_Struct::build_buffer_struct(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) {
    Struct_Name_Map::iterator it = MSG_MANAGER->msg_struct_name_map().find(field_info.field_type);
    if(it == MSG_MANAGER->msg_struct_name_map().end()) {
        LOG_ERROR("Can not find the struct_name:%s", field_info.field_type.c_str());
        return;
    }

    if (!value->IsObject()) {
        LOG_ERROR("field_type:%s field_name:%s is not object, struct_name:%s", field_info.field_type.c_str(), field_info.field_name.c_str(), struct_name().c_str());
        return;
    }

    Local<Object> object = value->ToObject(isolate->GetCurrentContext()).ToLocalChecked();
    std::vector<Field_Info> field_vec = it->second->field_vec();
    for(std::vector<Field_Info>::const_iterator iter = field_vec.begin();
            iter != field_vec.end(); iter++) {
        Local<Value> element = object->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked()).ToLocalChecked();
        if(iter->field_label == "arg") {
            build_buffer_arg(*iter, buffer, isolate, element);
        }
        else if(iter->field_label == "vector") {
            build_buffer_vector(*iter, buffer, isolate, element);
        }
        else if(iter->field_label == "map") {
            build_buffer_map(*iter, buffer, isolate, element);
        }
        else if(iter->field_label == "struct") {
            build_buffer_struct(*iter, buffer, isolate, element);
        }
    }
}
Exemple #6
0
void Msg_Struct::build_buffer_map(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) {
    if (!value->IsMap()) {
        LOG_ERROR("field_name:%s is not map, struct_name:%s", field_info.field_name.c_str(), struct_name().c_str());
        buffer.write_uint16(0);
        return;
    }

    Local<Map> map = Local<Map>::Cast(value);
    int16_t len = map->Size();
    buffer.write_uint16(len);
    Local<Array> array = map->AsArray();
    //index N is the Nth key and index N + 1 is the Nth value.
    if(is_struct(field_info.field_type)) {
        for (int i = 0; i < len * 2; i = i + 2) {
            Local<Value> element = array->Get(isolate->GetCurrentContext(), i + 1).ToLocalChecked();
            build_buffer_struct(field_info, buffer, isolate, element);
        }
    }
    else {
        Field_Info key_info;
        key_info.field_label = "args";
        key_info.field_type = field_info.key_type;
        key_info.field_name = field_info.key_name;
        for (int i = 0; i < len * 2; i = i + 2) {
            Local<Value> key = array->Get(isolate->GetCurrentContext(), i).ToLocalChecked();
            Local<Value> element = array->Get(isolate->GetCurrentContext(), i + 1).ToLocalChecked();
            build_buffer_struct(key_info, buffer, isolate, key);
            build_buffer_struct(field_info, buffer, isolate, element);
        }
    }
}
Exemple #7
0
void Msg_Struct::build_buffer_vector(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) {
    if (!value->IsArray()) {
        LOG_ERROR("field_name:%s is not array, struct_name:%s", field_info.field_name.c_str(), struct_name().c_str());
        buffer.write_uint16(0);
        return;
    }

    Local<Array> array = Local<Array>::Cast(value);
    int16_t len = array->Length();
    buffer.write_uint16(len);
    for (int i = 0; i < len; ++i) {
        Local<Value> element = array->Get(isolate->GetCurrentContext(), i).ToLocalChecked();
        if(is_struct(field_info.field_type)) {
            build_buffer_struct(field_info, buffer, isolate, element);
        }
        else {
            build_buffer_arg(field_info, buffer, isolate, element);
        }
    }
}
Exemple #8
0
void Msg_Struct::build_buffer_arg(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) {
    if(field_info.field_type == "int8") {
        int8_t val = 0;
        if (value->IsInt32()) {
            val = value->Int32Value(isolate->GetCurrentContext()).FromJust();
        }
        buffer.write_int8(val);
    }
    else if(field_info.field_type == "int16") {
        int16_t val = 0;
        if (value->IsInt32()) {
            val = value->Int32Value(isolate->GetCurrentContext()).FromJust();
        }
        buffer.write_int16(val);
    }
    else if(field_info.field_type == "int32") {
        int32_t val = 0;
        if (value->IsInt32()) {
            val = value->Int32Value(isolate->GetCurrentContext()).FromJust();
        }
        buffer.write_int32(val);
    }
    else if(field_info.field_type == "int64") {
        int64_t val = 0;
        if (value->IsNumber()) {
            val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
        }
        buffer.write_int64(val);
    }
    else if(field_info.field_type == "double") {
        double val = 0;
        if (value->IsNumber()) {
            val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
        }
        buffer.write_double(val);
    }
    else if(field_info.field_type == "bool") {
        bool val = 0;
        if (value->IsBoolean()) {
            val = value->BooleanValue(isolate->GetCurrentContext()).FromJust();
        }
        buffer.write_bool(val);
    }
    else if(field_info.field_type == "string") {
        std::string val = "";
        if (value->IsString()) {
            String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked());
            std::stringstream stream;
            stream << ToCString(str);
            val = stream.str();
        }
        buffer.write_string(val);
    }
    else {
        LOG_ERROR("Can not find the field_type:%s, struct_name:%s", field_info.field_type.c_str(), struct_name().c_str());
    }
}
Exemple #9
0
v8::Local<v8::Value> Msg_Struct::build_object_arg(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate) {
    EscapableHandleScope handle_scope(isolate);

    Local<Value> value;
    if(field_info.field_type == "int8") {
        int8_t val = 0;
        buffer.read_int8(val);
        value = Int32::New(isolate, val);
    }
    else if(field_info.field_type == "int16") {
        int16_t val = 0;
        buffer.read_int16(val);
        value = Int32::New(isolate, val);
    }
    else if(field_info.field_type == "int32") {
        int32_t val = 0;
        buffer.read_int32(val);
        value = Int32::New(isolate, val);
    }
    else if(field_info.field_type == "int64") {
        int64_t val = 0;
        buffer.read_int64(val);
        value = Number::New(isolate, val);
    }
    else if(field_info.field_type == "double") {
        double val = 0;
        buffer.read_double(val);
        value = Number::New(isolate, val);
    }
    else if(field_info.field_type == "bool") {
        bool val = false;
        buffer.read_bool(val);
        value = Boolean::New(isolate, val);
    }
    else if(field_info.field_type == "string") {
        std::string val = "";
        buffer.read_string(val);
        value = String::NewFromUtf8(isolate, val.c_str(), NewStringType::kNormal).ToLocalChecked();
    }
    else {
        LOG_ERROR("Can not find the field_type:%s, struct_name:%s", field_info.field_type.c_str(), struct_name().c_str());
        return handle_scope.Escape(Local<Value>());
    }
    return handle_scope.Escape(value);
}
Exemple #10
0
v8::Local<v8::Object> Msg_Struct::build_http_msg_object(Isolate* isolate, int cid, int msg_id, const Json::Value &value) {
    EscapableHandleScope handle_scope(isolate);

    Local<ObjectTemplate> localTemplate = ObjectTemplate::New(isolate);
    Local<Object> buf_obj = localTemplate->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
    buf_obj->Set(isolate->GetCurrentContext(),
                 String::NewFromUtf8(isolate, "cid", NewStringType::kNormal).ToLocalChecked(),
                 Int32::New(isolate, cid)).FromJust();
    buf_obj->Set(isolate->GetCurrentContext(),
                 String::NewFromUtf8(isolate, "msg_id", NewStringType::kNormal).ToLocalChecked(),
                 Int32::New(isolate, msg_id)).FromJust();

    for(std::vector<Field_Info>::const_iterator iter = field_vec().begin();
            iter != field_vec().end(); iter++) {
        Local<Value> js_value = Local<Value>();
        if((iter->field_type == "int8" || iter->field_type == "int16"
                || iter->field_type == "int32") && value[iter->field_name].isInt()) {
            int32_t val = value[iter->field_name].asInt();
            js_value = Int32::New(isolate, val);
        }
        else if((iter->field_type == "int64" || iter->field_type == "double") &&
                value[iter->field_name].isDouble()) {
            double val = value[iter->field_name].asDouble();
            js_value = Number::New(isolate, val);
        }
        else if(iter->field_type == "bool" && value[iter->field_name].isBool()) {
            bool val = value[iter->field_name].asBool();
            js_value = Boolean::New(isolate, val);
        }
        else if(iter->field_type == "string" && value[iter->field_name].isString()) {
            std::string val = value[iter->field_name].asString();
            js_value = String::NewFromUtf8(isolate, val.c_str(), NewStringType::kNormal).ToLocalChecked();
        }
        else {
            LOG_ERROR("Can not find the field_type:%s, struct_name:%s", iter->field_type.c_str(), struct_name().c_str());
        }

        buf_obj->Set(isolate->GetCurrentContext(),
                     String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked(),
                     js_value).FromJust();
    }
    return handle_scope.Escape(buf_obj);
}
Exemple #11
0
      void read_annot (const std::string& path, label_vector_type& labels, Connectome::LUT& lut)
      {
        std::ifstream in (path.c_str(), std::ios_base::in | std::ios_base::binary);
        if (!in)
          throw Exception ("Error opening input file!");

        const int32_t num_vertices = get_BE<int32_t> (in);
        vector<int32_t> vertices, vertex_labels;
        vertices.reserve (num_vertices);
        vertex_labels.reserve (num_vertices);
        for (int32_t i = 0; i != num_vertices; ++i) {
          vertices.push_back (get_BE<int32_t> (in));
          vertex_labels.push_back (get_BE<int32_t> (in));
        }

        const int32_t colortable_present = get_BE<int32_t> (in);
        if (!in.good()) {
          WARN ("FreeSurfer annotation file \"" + Path::basename (path) + "\" does not contain colortable information");
          labels = label_vector_type::Zero (num_vertices);
          for (size_t i = 0; i != vertices.size(); ++i)
            labels[vertices[i]] = vertex_labels[i];
          return;
        }
        if (!colortable_present)
          throw Exception ("Error reading FreeSurfer annotation file \"" + Path::basename (path) + "\": Unexpected colortable flag");

        // Structure that will map from the colour-based structure identifier to a more sensible index
        std::map<int32_t, Connectome::node_t> rgb2index;

        int32_t num_entries = get_BE<int32_t> (in);
        if (num_entries > 0) {

          const int32_t orig_lut_name_length = get_BE<int32_t> (in);
          std::unique_ptr<char[]> orig_lut_name (new char[orig_lut_name_length]);
          in.read (orig_lut_name.get(), orig_lut_name_length);
          for (int32_t i = 0; i != num_entries; ++i) {
            const int32_t struct_name_length = get_BE<int32_t> (in);
            std::unique_ptr<char[]> struct_name (new char[struct_name_length]);
            in.read (struct_name.get(), struct_name_length);
            const int32_t r    = get_BE<int32_t> (in);
            const int32_t g    = get_BE<int32_t> (in);
            const int32_t b    = get_BE<int32_t> (in);
            const int32_t flag = get_BE<int32_t> (in);
            const int32_t id   = r + (g << 8) + (b << 16) + (flag << 24);
            lut.insert (std::make_pair (i, Connectome::LUT_node (std::string (struct_name.get()), r, g, b)));
            rgb2index[id] = i;
          }

        } else {

          const int32_t version = -num_entries;
          if (version != 2)
            throw Exception ("Error reading FreeSurfer annotation file \"" + Path::basename (path) + "\": Unsupported file version (" + str(version) + ")");

          num_entries = get_BE<int32_t> (in);
          const int32_t orig_lut_name_length = get_BE<int32_t> (in);
          std::unique_ptr<char[]> orig_lut_name (new char[orig_lut_name_length]);
          in.read (orig_lut_name.get(), orig_lut_name_length);

          const int32_t num_entries_to_read = get_BE<int32_t> (in);
          for (int32_t i = 0; i != num_entries_to_read; ++i) {
            const int32_t structure = get_BE<int32_t> (in) + 1;
            if (structure < 0)
              throw Exception ("Error reading FreeSurfer annotation file \"" + Path::basename (path) + "\": Negative structure index");
            if (lut.find (structure) != lut.end())
              throw Exception ("Error reading FreeSurfer annotation file \"" + Path::basename (path) + "\": Duplicate structure index");
            const int32_t struct_name_length = get_BE<int32_t> (in);
            std::unique_ptr<char[]> struct_name (new char[struct_name_length]);
            in.read (struct_name.get(), struct_name_length);
            const int32_t r    = get_BE<int32_t> (in);
            const int32_t g    = get_BE<int32_t> (in);
            const int32_t b    = get_BE<int32_t> (in);
            const int32_t flag = get_BE<int32_t> (in);
            const int32_t id   = r + (g << 8) + (b << 16) + (flag << 24);
            lut.insert (std::make_pair (structure, Connectome::LUT_node (std::string (struct_name.get()), r, g, b)));
            rgb2index[id] = structure;
          }

        }

        labels = label_vector_type::Zero (num_vertices);
        for (size_t i = 0; i != vertices.size(); ++i)
          labels[vertices[i]] = rgb2index[vertex_labels[i]];
      }