sharehead.cpp
来自「一个支持中文的类C语言编译器」· C++ 代码 · 共 856 行 · 第 1/2 页
CPP
856 行
return-1;
}
break;
case $INVALID:
default:
return-1;
}
}
//----------------------------"!="----------------------------------------------------------------
BOOL operator !=(const COpData &opd1,const COpData &opd2)
{
switch(opd1.VarTp)
{
case $INT:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.intconst!=opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.intconst!=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.intconst!=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $REAL:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.dbconst!=opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.dbconst!=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.dbconst!=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $BOOL:
switch(opd2.VarTp)
{
case $INT:
return(bool)((bool)opd1.VarVlue.intconst!=opd2.VarVlue.intconst);
case $REAL:
return(bool)((bool)opd1.VarVlue.intconst!=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)((bool)opd1.VarVlue.intconst!=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $STRING:
switch(opd2.VarTp)
{
case $STRING:
return (bool)strcmp(opd1.VarVlue.SignOrString,opd2.VarVlue.SignOrString);
case $INT:
case $REAL:
case $BOOL:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $INVALID:
default:
return-1;
}
}
//-------------------------------"<"--------------------------------------------------------------
BOOL operator <(const COpData &opd1,const COpData &opd2)
{
switch(opd1.VarTp)
{
case $INT:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.intconst<opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.intconst<opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.intconst<(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $REAL:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.dbconst<opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.dbconst<opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.dbconst<(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $BOOL:
switch(opd2.VarTp)
{
case $INT:
return(bool)((bool)opd1.VarVlue.intconst<opd2.VarVlue.intconst);
case $REAL:
return(bool)((bool)opd1.VarVlue.intconst<opd2.VarVlue.dbconst);
case $BOOL:
return(bool)((bool)opd1.VarVlue.intconst<(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $STRING:
switch(opd2.VarTp)
{
case $STRING:
// return (bool)strcmp(opd1.VarVlue.SignOrString,opd2.VarVlue.SignOrString);
case $INT:
case $REAL:
case $BOOL:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $INVALID:
default:
return-1;
}
}
//------------------"<="---------------------------------------------------------------------------
BOOL operator <=(const COpData &opd1,const COpData &opd2)
{
switch(opd1.VarTp)
{
case $INT:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.intconst<=opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.intconst<=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.intconst<=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $REAL:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.dbconst<=opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.dbconst<=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.dbconst<=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $BOOL:
switch(opd2.VarTp)
{
case $INT:
return(bool)((bool)opd1.VarVlue.intconst<=opd2.VarVlue.intconst);
case $REAL:
return(bool)((bool)opd1.VarVlue.intconst<=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)((bool)opd1.VarVlue.intconst<=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $STRING:
switch(opd2.VarTp)
{
case $STRING:
// return (bool)strcmp(opd1.VarVlue.SignOrString,opd2.VarVlue.SignOrString);
case $INT:
case $REAL:
case $BOOL:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $INVALID:
default:
return-1;
}
}
//-------------------------------">"---------------------------------------------------------------
BOOL operator >(const COpData &opd1,const COpData &opd2)
{
switch(opd1.VarTp)
{
case $INT:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.intconst>opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.intconst>opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.intconst>(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $REAL:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.dbconst>opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.dbconst>opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.dbconst>(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $BOOL:
switch(opd2.VarTp)
{
case $INT:
return(bool)((bool)opd1.VarVlue.intconst>opd2.VarVlue.intconst);
case $REAL:
return(bool)((bool)opd1.VarVlue.intconst>opd2.VarVlue.dbconst);
case $BOOL:
return(bool)((bool)opd1.VarVlue.intconst>(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $STRING:
switch(opd2.VarTp)
{
case $STRING:
// return (bool)strcmp(opd1.VarVlue.SignOrString,opd2.VarVlue.SignOrString);
case $INT:
case $REAL:
case $BOOL:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $INVALID:
default:
return-1;
}
}
//---------------------------------------">="-----------------------------------------------------
BOOL operator >=(const COpData &opd1,const COpData &opd2)
{
switch(opd1.VarTp)
{
case $INT:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.intconst>=opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.intconst>=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.intconst>=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $REAL:
switch(opd2.VarTp)
{
case $INT:
return(bool)(opd1.VarVlue.dbconst>=opd2.VarVlue.intconst);
case $REAL:
return(bool)(opd1.VarVlue.dbconst>=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)(opd1.VarVlue.dbconst>=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $BOOL:
switch(opd2.VarTp)
{
case $INT:
return(bool)((bool)opd1.VarVlue.intconst>=opd2.VarVlue.intconst);
case $REAL:
return(bool)((bool)opd1.VarVlue.intconst>=opd2.VarVlue.dbconst);
case $BOOL:
return(bool)((bool)opd1.VarVlue.intconst>=(bool)opd2.VarVlue.intconst);
case $STRING:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $STRING:
switch(opd2.VarTp)
{
case $STRING:
// return (bool)strcmp(opd1.VarVlue.SignOrString,opd2.VarVlue.SignOrString);
case $INT:
case $REAL:
case $BOOL:
case $INVALID:
return -1;
default:
return-1;
}
break;
case $INVALID:
default:
return-1;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
//implement of CArgInfo
bool operator ==(const CArgInfo &argInfo1,const CArgInfo &argInfo2)//比较参数个数、参数类型
{
if(argInfo1.nCount!=argInfo2.nCount) return false;//参数个数
for(UINT i=0;i<argInfo1.nCount;i++){//bool,int,real三种类型看作是相等的
//if(argInfo1.arg[i].VarTp!=argInfo2.arg[i].VarTp){
switch(argInfo1.arg[i].VarTp)
{
case $INT:
case $REAL:
case $BOOL:
switch(argInfo2.arg[i].VarTp)
{
case $INT:
case $REAL:
case $BOOL:
break;
default:
return false;
}
break;
default:
if(argInfo1.arg[i].VarTp!=argInfo2.arg[i].VarTp) return false;
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////
//全局函数 GetBits()的实现
/******************************************************************\
功能:获取某long型数据的几个连续数据位
参数说明:Data--输入参数,位操作的对象
end--终止数据位,范围:0~31
beg--起始数据位,范围:0~31,注意起始位必须不大于终止位
返回值:调用后,该函数返回位操作结果
示例:钢水液位=GetBits(-7,3,0);
表示将-7的第0位至第3位数字取出,组成新的数据,赋给变量钢水液位
结果为9(1001b),因为-7d=11111001b
\******************************************************************/
int GetBits(long Data/*操作数*/,int end/*终止位*/,int beg/*起始位*/)
{
ASSERT(sizeof(Data)==4);//long型,4个字节长
ASSERT(beg>=0&&beg<=end&&end<=31);//越界检查
//情况1,取第beg--->end位
if(beg!=end)
{
return Data>>(beg)&~(~0<<(end-beg+1));//refer to <<C.tanhaoqiang P.263(an error in this book)>>
}
else//情况2,只取第end位
{
ASSERT(beg==end);
return Data>>end&1;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?