📄 svartype.cpp
字号:
return VarType_ID2Size(p->m_array.id_arrayitem) * p->m_array.arraynum;
case vtt_class:
if (p->m_class.pClass == NULL)
alert_prtf("need struc size: %s",p->m_class.classname);
return p->m_class.pClass->m_size;
case vtt_signed:
return VarType_ID2Size(p->m_signed.id_base);
case vtt_enum:
return BIT32_is_4;
case vtt_const:
return VarType_ID2Size(p->m_const.id_base);
default:
assert(0);
}
return 0;
}
VarTypeID CVarTypeMng::NewArray(PSTR item_name,SIZEOF n)
{
VarTypeID id = VarType_Name2ID(item_name);
return NewArray_id_id(id,n);
/*
VarTypeID id = if_DataType(item_name);
if (*item_name == 0)
{
SVarType* pv = id2_VarType(id);
SVarType* pnew = new SVarType;
*pnew = *pv;
pnew->id = nextfreeid++;
pnew->arraynum = n;
this->list->AddTail(pnew);
return pnew->id;
}
return 0;
*/
}
VarTypeID CVarTypeMng::VarType_Name2ID(PCSTR name)
{
// 先借用一下下面程序吧
VarTypeID id = get_DataType(name);
if (*name == 0)
return id;
return 0;
}
VarTypeID get_DataType_bare(PCSTR &p)
{ // with "unsigned char *", only parse "unsigned char"
if (memcmp(p,"unsigned __int64",16) == 0)
nop();
PCSTR savp = p;
char buf[80];
buf[0] = '\0';
while (*p && buf[0] == '\0')
{
get_1part(buf,p);
if (buf[0] == '\0')
break;
define_replace(buf);
}
if (strcmp(buf,"__declspec") == 0)
{ // skip this
assert(*p == '(');
while (*p != ')')
p++;
p++;
skip_eos(p);
return get_DataType_bare(p);
}
if (strcmp(buf,"volatile") == 0)
return get_DataType_bare(p);
// 特别要支持 struct _NewStruc * name;
if (strcmp(buf,"struct") == 0)
{
VarTypeID id = do_struct(p);
return id;
}
if (strcmp(buf,"union") == 0)
{
VarTypeID id = do_union(p);
return id;
}
if (strcmp(buf,"enum") == 0)
{
VarTypeID id = 0; //???? do_enum(p);
return id;
}
if (strcmp(buf,"unsigned") == 0 )
{
VarTypeID id = get_DataType_bare(p);
return g_VarTypeManage->Get_unsigned_id(id);
}
else if (strcmp(buf,"signed") == 0)
{
VarTypeID id = get_DataType_bare(p);
return g_VarTypeManage->Get_signed_id(id);
}
else if (strcmp(buf,"int") == 0 )
{
return id_int;
}
else if (strcmp(buf,"long") == 0)
{
return id_long;
}
else if (strcmp(buf,"short") == 0)
{
return id_short;
}
else if (strcmp(buf,"__int64") == 0)
{
return id_int64;
}
else if (strcmp(buf,"double") == 0)
{
return id_double;
}
else if (strcmp(buf,"const") == 0)
{
VarTypeID id = get_DataType_bare(p);
assert(id);
return g_VarTypeManage->GetConstOfID(id);
}
PSTR p1 = buf;
VarTypeID id = g_VarTypeManage->FirstDataType(p1);
if (id == 0)
id = g_ClassManage->if_StrucName(p1);
if (id == 0)
id = g_enum_mng->if_EnumName(p1);
if (id == 0)
p = savp;
return id;
}
VarTypeID Get_Additional_id(VarTypeID baseid, PCSTR &p)
{
// 对 "unsigned char *", 已经知道 "unsigned char" 的id,
// 期望 p 指的是一个 "*" 或 "**" 之类
VarTypeID id = baseid;
for (;;)
{
if (*p == ' ')
p++;
else if (*p == '*')
{
p++;
id = g_VarTypeManage->GetAddressOfID(id);
}
else if (memcmp(p,"far ",4) == 0)
p += 4;
else if (memcmp(p,"FAR ",4) == 0)
p += 4;
else if (memcmp(p,"near ",5) == 0)
p += 5;
else if (memcmp(p,"NEAR ",5) == 0)
p += 5;
else
{
skip_eos(p);
return id;
}
}
}
VarTypeID get_DataType(PCSTR &p)
{
VarTypeID id = get_DataType_bare(p);
if (id == 0)
return 0;
for (;;)
{
if (*p == ' ')
p++;
else if (*p == '*')
{
p++;
id = g_VarTypeManage->GetAddressOfID(id);
}
else if (memcmp(p,"const",5) == 0 && if_split_char(p[5]))
{
id = g_VarTypeManage->GetConstOfID(id);
p += 5;
}
else
break;
}
return id;
}
VarTypeID CVarTypeMng::GetConstOfID(VarTypeID id)
{
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* p = list->GetNext(pos);
if (p->type == vtt_const && p->m_const.id_base == id)
return p->id;
}
// not find, create one
assert(id);
VarTypeID idnew = nextfreeid++;
SVarType* pnew = new SVarType;
pnew->id = idnew; //
pnew->type = vtt_const;
pnew->m_const.id_base = id;
this->list->AddTail(pnew);
return idnew;
}
VarTypeID CVarTypeMng::FirstDataType(PCSTR &partern)
{
assert(list);
assert(partern);
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* pv = list->GetNext(pos);
PSTR name = NULL;
if (pv->type == vtt_base)
name = pv->m_base.name;
else if (pv->type == vtt_typedef)
name = pv->m_typedef.name;
else if (pv->type == vtt_signed)
name = pv->m_signed.name;
else
continue;
int n = strlen(name);
if (memcmp(name,partern,n))
continue;
// 只是前一部分一样,还不能说明问题
if (if_split_char(partern[n]))
{
partern += n;
return pv->id;
}
}
return 0;
}
BOOL CVarTypeMng::If_Based_on_idid(VarTypeID id, VarTypeID id0)
{
// check if id is based on id0
if (id == id0)
return TRUE;
SVarType* p = id2_VarType(id);
assert(p);
switch (p->type)
{
case vtt_const:
return If_Based_on_idid(p->m_const.id_base, id0);
case vtt_typedef:
return If_Based_on_idid(p->m_typedef.id_base, id0);
default:
return FALSE;
}
}
BOOL CVarTypeMng::If_Based_on(VarTypeID id, PSTR basename)
{
VarTypeID id0 = this->VarType_Name2ID(basename);
assert(id0);
return this->If_Based_on_idid(id, id0);
}
VarTypeID CVarTypeMng::Get_unsigned_id(VarTypeID id)
{
SVarType* p = id2_VarType(id);
assert(p);
switch (p->type)
{
case vtt_base:
return id;
case vtt_signed:
return p->m_signed.id_base;
default:
assert(0);
}
return 0;
}
VarTypeID CVarTypeMng::Get_signed_id(VarTypeID id)
{
SVarType* p = id2_VarType(id);
assert(p);
if (p->type == vtt_signed)
return id;
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* pv = list->GetNext(pos);
if (pv->type == vtt_signed && pv->m_signed.id_base == id)
return pv->id;
}
//assert(0);
return id;
}
VarTypeID CVarTypeMng::Class2VarID(Class_st *pclass)
{
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* p = list->GetNext(pos);
if (p->type == vtt_class)
{
if (p->m_class.pClass == pclass)
return p->id;
if (p->m_class.pClass == NULL
&& strcmp(p->m_class.classname,pclass->m_name) == 0)
{ // for unknown struc
p->m_class.pClass = pclass;
return p->id;
}
}
}
SVarType* pnew = new SVarType;
pnew->id = nextfreeid++;
pnew->type = vtt_class;
pnew->m_class.pClass = pclass;
this->list->AddTail(pnew);
return pnew->id;
}
VarTypeID CVarTypeMng::NewArray_id_id(VarTypeID id0, SIZEOF n)
{ // 就是已经char的id,生成一个char kkk[]的id
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* p = list->GetNext(pos);
if (p->type == vtt_array
&& p->m_array.id_arrayitem == id0
&& p->m_array.arraynum == n)
return p->id;
}
// not find, create one
assert(id0);
VarTypeID id = nextfreeid++;
SVarType* pnew = new SVarType;
pnew->id = id;
pnew->type = vtt_array;
pnew->m_array.id_arrayitem = id0;
pnew->m_array.arraynum = n;
this->list->AddTail(pnew);
return id;
}
VarTypeID CVarTypeMng::GetArrayItemID(VarTypeID id)
{
// if it is a array, return item datatype
SVarType* p = id2_VarType(id);
if (p->type == vtt_array)
return p->m_array.id_arrayitem;
return id;
}
VarTypeID CVarTypeMng::NewUnknownStruc(PCSTR strucname)
{
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* p = list->GetNext(pos);
if (p->type == vtt_class)
{
if (strcmp(p->m_class.classname,strucname) == 0)
return p->id;
if (p->m_class.pClass != NULL)
if (strcmp(p->m_class.pClass->m_name,strucname) == 0)
return p->id;
}
if (p->type == vtt_typedef
&& strcmp(p->m_typedef.name,strucname) == 0)
{
Class_st* cls = id2_Class(p->m_typedef.id_base);
if (cls)
return p->id;
}
}
SVarType* pnew = new SVarType;
pnew->type = vtt_class;
pnew->id = nextfreeid++;
strcpy(pnew->m_class.classname,strucname);
pnew->m_class.pClass = NULL;
this->list->AddTail(pnew);
return pnew->id;
}
VarTypeID CVarTypeMng::GetAddressOfID(VarTypeID id)
{ // 是说返回一个指向id类型的指针的id
// 也就是说,输入一个DWORD,要返回一个DWORD*
POSITION pos = list->GetHeadPosition();
while (pos)
{
SVarType* p = list->GetNext(pos);
if (p->type == vtt_point && p->m_point.id_pointto == id)
return p->id;
}
// not find, create one
return this->New_p(id);
}
// -------------------------------------------------------
SVarType* GG_id2_VarType(VarTypeID id)
{
return g_VarTypeManage->id2_VarType(id);
}
CString GG_VarType_ID2Name(VarTypeID id)
{
char buf[128];
g_VarTypeManage->VarType_ID2Name(id,buf);
return (CString)buf;
}
SIZEOF GG_VarType_ID2Size(VarTypeID id)
{
return g_VarTypeManage->VarType_ID2Size(id);
}
BOOL GG_is_funcpoint(VarTypeID id)
{
return g_VarTypeManage->is_funcptr(id);
}
CFuncType* GG_get_funcpoint(VarTypeID id)
{
return g_VarTypeManage->get_funcptr(id);
}
Class_st* GG_id2_Class(VarTypeID id)
{
return g_VarTypeManage->id2_Class(id);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -