00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00037 #include "rc_common_header.h"
00038
00039 namespace ReChannel {
00040
00041 sc_object* rc_find_object(
00042 const char* obj_name, const sc_object* rel_obj)
00043 {
00044 if (obj_name == NULL) {
00045 return NULL;
00046 }
00047 if (obj_name[0] == '.' || obj_name[0] == '#') {
00048 if (rel_obj == NULL) {
00049 return NULL;
00050 }
00051 std::string buf;
00052 if (obj_name[0] == '.') {
00053 buf.append(rel_obj->name());
00054 buf.append(obj_name);
00055 } else {
00056
00057 const char* pos_rel_name = obj_name + 1;
00058 const sc_object* base_obj = rel_obj;
00059 while(*pos_rel_name == '.') {
00060 if (base_obj == NULL) {
00061 break;
00062 }
00063 base_obj = base_obj->get_parent_object();
00064 pos_rel_name++;
00065 }
00066 if (pos_rel_name == obj_name + 1 || *pos_rel_name == '\0') {
00067 RC_REPORT_ERROR(RC_ID_RELNAME_SYNTAX_ERROR_,
00068 "Relative name '" << obj_name << "'"
00069 " could not be resolved due to"
00070 " syntax error");
00071 }
00072 if (*pos_rel_name == '.') {
00073 return NULL;
00074 } else if (base_obj == NULL) {
00075 buf.append(pos_rel_name);
00076 } else {
00077 buf.append(rel_obj->name());
00078 buf.append(pos_rel_name - 1);
00079 }
00080 }
00081 return sc_find_object(buf.c_str());
00082 } else {
00083 return sc_find_object(obj_name);
00084 }
00085 }
00086
00087 sc_module* rc_find_parent_module(sc_object* obj)
00088 {
00089 sc_module* parent = NULL;
00090 while(obj != NULL
00091 && (parent = dynamic_cast<sc_module*>(
00092 obj = obj->get_parent_object())) == NULL);
00093 return parent;
00094 }
00095
00096 }
00097
00098
00099
00100
00101