Beispiel #1
0
int testType(TypePoint type1,TypePoint type2){
	//return -1 when type1 and type2 are different kind type.
	//otherwise, return 1;
	
	if(type1 == NULL || type2 == NULL)
		return -1;
	if(type1->kind == type2->kind){
		if(type1->kind == BASIC){
			return (type1->data.basic == type2->data.basic) ? 1 : -1;
		}
		else if(type1->kind == STRUCTURE){
			return (type1->data.structure->name == type2->data.structure->name) ? 1 : -1;
		}
		else if(type1->kind == FUNCTION){
			FieldListPoint a = type1->data.structure,
						   b = type2->data.structure;
			while (a != NULL && b != NULL){
				if(testType(a->type,b->type) == -1)
					return -1;
				a = a->tail;
				b = b->tail;
			}
			return (a != NULL || b != NULL) ? -1 : 1;
		}
		else{
			return testType(type1->data.array.elem, type2->data.array.elem);
		}
	}
	else
		return -1;
}
Beispiel #2
0
void getExtDef(TreeNode *head){
	TreeNode *child = head->firstChild, *temp = child;
	TypePoint specifier = getSpecifier(child);
	if(specifier == NULL)
		return;
	child = child->nextSibling;
	if(child->name == ExtDecList){
		//ExtDef->Specifier ExtDecList SEMI;
		getExtDecList(specifier,child);
	}
	else if (child->name == FunDec){
		//Extdef -> Specifier FunDec CompSt | Specifier FunDec SEMI;
		TypePoint type = getFunDec(specifier,child);
		TableNode *result = NULL;
		TableNode *findResult = findTableNode(type->data.structure->name);
		if (findResult == NULL){
			result = insertTableNode(type->data.structure->name, type);	//insert into the table
			FieldListPoint fp = type->data.structure->tail;
			for(;fp!=NULL;fp=fp->tail){
				if(insertTableNode(fp->name,fp->type)==NULL){
					printf("Error type 3 at Line %d: Redefine variable \"%s\".\n",fp->lineno,fp->name);
				}
			}
			if(child->nextSibling->name == SEMI){
				// 将声明的函数加入“声明表”以待后续检验
				result->def_state = -1;		//声明
				insertFuncDefTable(child->lineno, result);
			}
			else{
				result->def_state = 1;
				getCompSt(specifier,child->nextSibling);
			}
		}
		else { //findResult != NULL
			// 判断在表中的类型,如果不符合,返回
			//printf(">>>>%d\n", testType(findResult->type, type));
			if (testType(findResult->type, type) == -1) {
				printf("Errot type 19 at Line %d: Conflict between function declarations.\n", child->lineno);
				return;
			}	
			if(child->nextSibling->name == CompSt){
				// set def_state to 1 and judge redefinition
				if (findResult->def_state == -1) {
					findResult->def_state = 1;
				}
				else {
					printf("Error type 4 at Line %d: Redefined function name \"%s\".\n",root->lineno,type->data.structure->name);
					return;
				}
				getCompSt(specifier,child->nextSibling);
			}

		}
		//getCompSt(specifier,child->nextSibling);
	}
	else{
		//ExtDef -> Specifier SEMI;
	}
	return;
}
AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
{
	if(words->size() < 1)
		return AnyType(TypeNull, NULL);
	std::string word = words->front(); words->pop_front();
	char * rawWord = (char *)word.c_str();
	ValueType wordType = testType(word);
	switch(wordType)
	{
	case TypeFunction:
		if(word == "set")
			return tptS_set(words);
		else if(word == "create")
			return tptS_create(words);
		else if(word == "delete" || word == "kill")
			return tptS_delete(words);
		else if(word == "load")
			return tptS_load(words);
		else if(word == "reset")
			return tptS_reset(words);
		else if(word == "bubble")
			return tptS_bubble(words);
		break;
	case TypeNumber:
		return NumberType(atoi(rawWord));
	case TypePoint:
	{
		int pointX, pointY;
		sscanf(rawWord, "%d,%d", &pointX, &pointY);
		return PointType(pointX, pointY);
	}
	case TypeString:
		return StringType(word);
	}
}
String TPTScriptInterface::FormatCommand(String command)
{
	std::deque<String> words;
	std::deque<AnyType> commandWords;
	String outputData;

	//Split command into words, put them on the stack
	for(String word : command.PartitionBy(' '))
		words.push_back(word);
	while(!words.empty())
	{
		ValueType cType = testType(words.front());
		switch(cType)
		{
		case TypeFunction:
			outputData += "\bt";
			break;
		case TypeNumber:
		case TypePoint:
			outputData += "\bo";
			break;
		case TypeString:
			outputData += "\bg";
			break;
		default:
			outputData += "\bw";
			break;
		}
		outputData += words.front() + " ";
		words.pop_front();
	}
	return outputData;
}
Beispiel #5
0
 	void LLSDMessageReaderTestObject::test<4>()
 		// S8
 	{
 		S8 outValue, inValue = -3;
 		LLSDMessageReader msg = testType(inValue);
 		msg.getS8("block", "var", outValue);
 		ensure_equals("Ensure S8", outValue, inValue);
 	}
Beispiel #6
0
	void LLSDMessageReaderTestObject::test<20>()
		// IPPort
	{
		U16 outValue, inValue = 80;
		LLSDMessageReader msg = testType(inValue);
		msg.getIPPort("block", "var", outValue);
		ensure_equals("Ensure IPPort", outValue, inValue);
	}
Beispiel #7
0
	void LLSDMessageReaderTestObject::test<9>()
		// F32
	{
		F32 outValue, inValue = 121.44f;
		LLSDMessageReader msg = testType(inValue);
		msg.getF32("block", "var", outValue);
		ensure_equals("Ensure F32", outValue, inValue);
	}
Beispiel #8
0
	void LLSDMessageReaderTestObject::test<7>()
		// U16
	{
		U16 outValue, inValue = 3;
		LLSDMessageReader msg = testType(inValue);
		msg.getU16("block", "var", outValue);
		ensure_equals("Ensure S16", outValue, inValue);
	}
Beispiel #9
0
	void LLSDMessageReaderTestObject::test<12>()
		// F64
	{
		F64 outValue, inValue = 3232143.33;
		LLSDMessageReader msg = testType(inValue);
		msg.getF64("block", "var", outValue);
		ensure_equals("Ensure F64", outValue, inValue);
	}
Beispiel #10
0
	void LLSDMessageReaderTestObject::test<8>()
		// S32
	{
		S32 outValue, inValue = 44;
		LLSDMessageReader msg = testType(inValue);
		msg.getS32("block", "var", outValue);
		ensure_equals("Ensure S32", outValue, inValue);
	}
Beispiel #11
0
 	void 
	LLSDMessageReaderTestObject::test<5>()
		// U8
	{
		U8 outValue, inValue = 2;
		LLSDMessageReader msg = testType(inValue);
		msg.getU8("block", "var", outValue);
		ensure_equals("Ensure U8", outValue, inValue);
	}
Beispiel #12
0
	void LLSDMessageReaderTestObject::test<19>()
		// IPAddr
	{
		U32 outValue, inValue = 12344556;
		LLSD sdValue = ll_sd_from_ipaddr(inValue);
		LLSDMessageReader msg = testType(sdValue);
		msg.getIPAddr("block", "var", outValue);
		ensure_equals("Ensure IPAddr", outValue, inValue);
	}
Beispiel #13
0
	void LLSDMessageReaderTestObject::test<17>()
		// Quaternion
	{
		 LLQuaternion outValue, inValue = LLQuaternion(1,2,3,4);
		LLSD sdValue = ll_sd_from_quaternion(inValue);
		LLSDMessageReader msg = testType(sdValue);
		msg.getQuat("block", "var", outValue);
		ensure_equals("Ensure Quaternion", outValue, inValue);
	}
Beispiel #14
0
	void LLSDMessageReaderTestObject::test<18>()
		// UUID
	{
		LLUUID outValue, inValue;
		inValue.generate();
		LLSDMessageReader msg = testType(inValue);
		msg.getUUID("block", "var", outValue);
		ensure_equals("Ensure UUID", outValue, inValue);
	}
Beispiel #15
0
	void LLSDMessageReaderTestObject::test<10>()
		// U32
	{
		U32 outValue, inValue = 88;
		LLSD sdValue = ll_sd_from_U32(inValue);
		LLSDMessageReader msg = testType(sdValue);
		msg.getU32("block", "var", outValue);
		ensure_equals("Ensure U32", outValue, inValue);
	}
Beispiel #16
0
	void LLSDMessageReaderTestObject::test<16>()
		// Vector3d
	{
		 LLVector3d outValue, inValue = LLVector3d(1,2,3);
		 LLSD sdValue = ll_sd_from_vector3d(inValue);
		LLSDMessageReader msg = testType(sdValue);
		msg.getVector3d("block", "var", outValue);
		ensure_equals("Ensure Vector3d", outValue, inValue);
	}
Beispiel #17
0
	void LLSDMessageReaderTestObject::test<11>()
		// U64
	{
		U64 outValue, inValue = 121;
		LLSD sdValue = ll_sd_from_U64(inValue);
		LLSDMessageReader msg = testType(sdValue);
		msg.getU64("block", "var", outValue);
		ensure_equals("Ensure U64", outValue, inValue);
	}
Beispiel #18
0
	void LLSDMessageReaderTestObject::test<21>()
		// Binary 
	{
		std::vector<U8> outValue(2), inValue(2);
		inValue[0] = 0;
		inValue[1] = 1;
	  
		LLSDMessageReader msg = testType(inValue);
		msg.getBinaryData("block", "var", &(outValue[0]), inValue.size());
		ensure_equals("Ensure Binary", outValue, inValue);
	}
Beispiel #19
0
void testParseSan() {
  try {
    testType("O-O", SanProps::KING_CASTLE);
    testCheckType("O-O+", SanProps::KING_CASTLE);
    testType("O-O-O", SanProps::QUEEN_CASTLE);
    testCheckType("O-O-O+", SanProps::QUEEN_CASTLE);
    testType("1/2-1/2", SanProps::DRAW);
    testType("1-0", SanProps::WHITE_WINS);
    testType("0-1", SanProps::BLACK_WINS);
    testMove("Be5", SanProps::BISHOP, 'e', 5);
    testMove("Nf3", SanProps::KNIGHT, 'f', 3);
    testMove("c5", SanProps::PAWN, 'c', 5);
    testCapture("Bxe5", SanProps::BISHOP, 'e', 5);
    testCapture("B:e5", SanProps::BISHOP, 'e', 5);
    testCapture("Be5:", SanProps::BISHOP, 'e', 5);
    testCapture("exd5", SanProps::PAWN, 'd', 5, 'e');
    testEnPassant("exd6e.p.", 'd', 6, 'e');
    testMove("Ngf3", SanProps::KNIGHT, 'f', 3, 'g');
    testMove("Ndf3", SanProps::KNIGHT, 'f', 3, 'd');
    testMove("N5f3", SanProps::KNIGHT, 'f', 3, 0, 5);
    testMove("N1f3", SanProps::KNIGHT, 'f', 3, 0, 1);
    testCapture("N5xf3", SanProps::KNIGHT, 'f', 3, 0, 5);
    testMove("Rdd5", SanProps::ROOK, 'd', 5, 'd');
    testMove("R3d5", SanProps::ROOK, 'd', 5, 0, 3);
    testCapture("Rdxd5", SanProps::ROOK, 'd', 5, 'd');
    testPromotion("e8Q", 'e', 8, SanProps::QUEEN);
    testPromotion("e8=Q", 'e', 8, SanProps::QUEEN);
    testCheck("Nd7+", SanProps::KNIGHT, 'd', 7);
    testCheck("Rb7+", SanProps::ROOK, 'b', 7);
    testCheck("Ba6+", SanProps::BISHOP, 'a', 6);
    testCheckmate("Rg7#", SanProps::ROOK, 'g', 7);
    testCheckmateCapture("Nxh6#", SanProps::KNIGHT, 'h', 6);
    testCheckmate("Rh4#", SanProps::ROOK, 'h', 4);
  } catch (std::runtime_error const & err) {
    std::cerr << "caught error while parsing san " << err.what() << std::endl;
  }
}
Beispiel #20
0
FieldListPoint getDef(TreeNode *head){
	TreeNode* child = head->firstChild;
	TypePoint type = getSpecifier(child);
	if(type == NULL)
		return NULL;
	FieldListPoint r = NULL;
	child = child->nextSibling->firstChild;//child->name = Dec
	for(;;){
		TreeNode *dec = child->firstChild;//dec->name = VarDec;
		FieldListPoint result = getVarDec(type,dec);//Here may exist error type 5:Type mismatched for assignment; Aslo  set dec inital.
		if(opType == 0 || opType == 1){
			if(dec->nextSibling!=NULL){//Dec->VarDec ASSIGNOP Exp{
				if(opType == 0){
					printf("Error type 15 at Line %d: Illegal initial in structure for variable \"%s\".\n",result->lineno,result->name);
					child = child->nextSibling;
					if(child != NULL)
						child = child->nextSibling->firstChild;
					else
						break;
					continue;
					printf("Never arrive this in %s at Line%d.\n",__FILE__,__LINE__);
				}
				else{
					TypePoint t = getExp(dec->nextSibling->nextSibling);
					if(t != NULL && testType(t,type) == -1){
						printf("Error type 7 at Line %d: Type mismatched for \"=\".\n",dec->lineno);
					}
				}
			}
			FieldListPoint newField = (FieldListPoint)malloc(sizeof(FieldList));
			newField->name = result->name;
			newField->type = result->type;
			newField->lineno = dec->lineno;
			newField->tail = r;
			r = newField;
		}
		child = child->nextSibling;
		if(child!=NULL){
			child = child->nextSibling->firstChild;
		}
		else
			break;
	}
	return r;
}
std::string TPTScriptInterface::FormatCommand(std::string command)
{
	std::deque<std::string> words;
	std::deque<AnyType> commandWords;
	std::string outputData;

	//Split command into words, put them on the stack
	char * rawCommand;
	rawCommand = (char*)calloc(command.length()+1, 1);
	memcpy(rawCommand, (char*)command.c_str(), command.length());
	char * currentWord = rawCommand;
	char * currentCommand = rawCommand;
	while((currentCommand = strchr(currentCommand, ' ')))
	{
		currentCommand[0] = 0;
		words.push_back(std::string(currentWord));
		currentWord = ++currentCommand;
	}
	words.push_back(std::string(currentWord));
	free(rawCommand);
	while(!words.empty())
	{
		ValueType cType = testType(words.front());
		switch(cType)
		{
		case TypeFunction:
			outputData += "\bt";
			break;
		case TypeNumber:
		case TypePoint:
			outputData += "\bo";
			break;
		case TypeString:
			outputData += "\bg";
			break;
		default:
			outputData += "\bw";
			break;
		}
		outputData += words.front() + " ";
		words.pop_front();
	}
	return outputData;
}
AnyType TPTScriptInterface::eval(std::deque<String> * words)
{
	if(words->size() < 1)
		return AnyType(TypeNull, ValueValue());
	String word = words->front(); words->pop_front();
	ValueType wordType = testType(word);
	switch(wordType)
	{
	case TypeFunction:
		if(word == "set")
			return tptS_set(words);
		else if(word == "create")
			return tptS_create(words);
		else if(word == "delete" || word == "kill")
			return tptS_delete(words);
		else if(word == "load")
			return tptS_load(words);
		else if(word == "reset")
			return tptS_reset(words);
		else if(word == "bubble")
			return tptS_bubble(words);
		else if(word == "quit")
			return tptS_quit(words);
		break;
	case TypeNumber:
		return NumberType(parseNumber(word));
	case TypeFloat:
		return FloatType(atof(word.ToUtf8().c_str()));
	case TypePoint:
	{
		int x, y;
		if(String::Split comma = word.SplitNumber(x))
			if(comma.After().BeginsWith(","))
				if(comma.After().Substr(1).SplitNumber(y))
					return PointType(x, y);
		return PointType(0, 0);
	}
	case TypeString:
		return StringType(word);
	default:
		break;
	}
	return StringType(word);
}
Beispiel #23
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setupUi(this);
    ::CoInitialize(NULL);
    ::CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE,
                           RPC_C_IMP_LEVEL_DELEGATE, NULL, 0, NULL);

    ldsmnTypeModel = new TypeLoodsmanModel();    
    ldsmnLinkModel = new LinkLoodsmanModel();
    ldsmnAttrModel = new AttrLoodsmanModel();
    ldsmnEditAttrModel = new AttrEditLoodsmanModel();

    connect(pshBtnTestProject,SIGNAL(clicked()),this, SLOT(listProject()));
    connect(pshBtnModelTest,SIGNAL(clicked()),this, SLOT(testModel()));
    connect(pshBtnTypeTest,SIGNAL(clicked()),this, SLOT(testType()));
    connect(pshBtnLinkTest,SIGNAL(clicked()),this, SLOT(testLink()));
    connect(pshBtnStatTest,SIGNAL(clicked()),this, SLOT(testStat()));
    connect(pshBtnAttrTest,SIGNAL(clicked()),this, SLOT(testAttr()));
}
Beispiel #24
0
void getStmt(TypePoint returnType,TreeNode *head){
	TreeNode *child = head->firstChild;
	if(child->name == Exp){
		getExp(child);
	}
	else if(child->name == CompSt)
		getCompSt(returnType,child);
	else if(child->name == RETURN){
		TypePoint expType = getExp(child->nextSibling);
		if(testType(expType,returnType)==-1){
			printf("Error type 8 at Line %d: Type mismatched for return.\n",child->nextSibling->lineno);
			return;
		}
	}
	else if(child->name == WHILE){
		child = child->nextSibling->nextSibling;
		TypePoint p = getExp(child);
		if(!(p->kind==BASIC && p->data.basic==INT)){
			printf("Error type 7 at Line %d: Type mismatched for while condition.\n",child->lineno);
			return;
		}
		child = child->nextSibling->nextSibling;
		getStmt(returnType,child);
	}
	else{
		child = child->nextSibling->nextSibling;
		TypePoint p = getExp(child);
		if(!(p->kind == BASIC && p->data.basic == INT)){
			printf("Error type 7 at Line %d: Type mismatched for if condition.\n",child->lineno);
			return;
		}
		child = child->nextSibling->nextSibling;
		getStmt(returnType,child);
		child = child->nextSibling;
		if(child != NULL){
			getStmt(returnType,child->nextSibling);
		}
	}
}
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
	//Arguments from stack
	StringType property = eval(words);
	AnyType selector = eval(words);
	AnyType value = eval(words);

	Simulation * sim = m->GetSimulation();
	unsigned char * partsBlock = (unsigned char*)&sim->parts[0];

	int returnValue = 0;

	FormatType propertyFormat;
	int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat);

	if(propertyOffset==-1)
		throw GeneralException("Invalid property");

	//Selector
	int newValue;
	if(value.GetType() == TypeNumber)
		newValue = ((NumberType)value).Value();
	else if(value.GetType() == TypeString)
	{
		std::string newString = ((StringType)value).Value();
		ValueType asdf = testType(newString.substr(0, newString.length()-1));
		if (newString[newString.length()-1] == 'C' && asdf == TypeNumber)
		{
			newValue = ((NumberType)(atoi(newString.substr(0, newString.length()-1).c_str()))).Value()+273;
		}
		else if (newString[newString.length()-1] == 'F' && asdf == TypeNumber)
		{
			newValue = (int)((((NumberType)(atoi(newString.substr(0, newString.length()-1).c_str()))).Value()-32.0f)*5/9+273.15f);
		}
		else
		{
			newValue = GetParticleType(newString);
			if (newValue < 0 || newValue >= PT_NUM)
				if (newString == "GOLD" || ((StringType)value).Value() == "gold")
					throw GeneralException("No, GOLD will not be an element");
				else
					throw GeneralException("Invalid element");
		}
	}
	else
		throw GeneralException("Invalid value for assignment");
	if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM))
		throw GeneralException("Invalid element");

	if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
	{
		int partIndex = -1;
		if(selector.GetType() == TypePoint)
		{
			ui::Point tempPoint = ((PointType)selector).Value();
			if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
				throw GeneralException("Invalid position");

		}
		else
			partIndex = ((NumberType)selector).Value();
		if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0)
			throw GeneralException("Invalid particle");

		switch(propertyFormat)
		{
		case FormatInt:
			*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		case FormatFloat:
			*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		}
		returnValue = 1;
	}
	else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all")
	{
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		}
	}
	else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber)
	{
		int type;
		if(selector.GetType() == TypeNumber)
			type = ((NumberType)selector).Value();
		else if(selector.GetType() == TypeString)
			type = GetParticleType(((StringType)selector).Value());

		if(type<0 || type>=PT_NUM)
			throw GeneralException("Invalid particle type");
		std::cout << propertyOffset << std::endl;
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type == type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type == type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		}
	}
	else
		throw GeneralException("Invalid selector");
	return NumberType(returnValue);
}
Beispiel #26
0
TypePoint getExp(TreeNode *head){
	TreeNode *child = head->firstChild;
	if(child->name == Exp && child->nextSibling->name == LB){
		//Exp -> Exp LB Exp RB
		TypePoint type1 = getExp(child);
		if(type1 == NULL)
			return NULL;
		if(type1->kind != ARRAY){
			printf("Error type 10 at Line %d: The variable isn't an array.\n",child->lineno);
			return NULL;
		}
		else{
			child = child->nextSibling->nextSibling;
			TypePoint type2 = getExp(child);
			if(type2 == NULL)
				return NULL;
			if(!(type2->kind == BASIC && type2->data.basic == INT)){
				printf("Error type 12 at Line %d:Array index should be an integer.\n",child->lineno);
				return NULL;
			}
			else{
				return type1->data.array.elem;
			}
		}
	}
	else if(child->name == Exp && child->nextSibling->name == DOT){
		//Exp -> Exp DOT ID
		TypePoint type1 = getExp(child);
		if(type1 == NULL)
			return NULL;
		if(type1->kind != STRUCTURE){
			printf("Error type 13 at Line %d: Illegal use of \".\".\n",child->nextSibling->lineno);
			return NULL;
		}
		else{
			child = child->nextSibling->nextSibling;
			FieldListPoint field = type1->data.structure->type->data.structure;
			for(;field!=NULL;field = field->tail){
				if(strcmp(field->name,child->data)==0)
					break;
			}
			if(field == NULL){
				printf("Error type 14 at Line %d: Non-existent field \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			else{
				return field->type;
			}
		}
	}
	else if(child->name == Exp){
		if(child->nextSibling->name == ASSIGNOP){
			//Exp -> Exp ASSIGNOP Exp
			TreeNode *node = child->firstChild;
			if(!((node->name == ID && node->nextSibling == NULL)||(node->name == Exp && node->nextSibling->name == DOT)||(node->name == Exp && node->nextSibling->name  == LB && node->nextSibling->nextSibling->name == Exp))){//When the left is a variable, return NULL;
				printf("Error type 6 at Line %d: The left-hand side of an assignment must be a variable.\n",child->lineno);
				return NULL;
			}
		}
		TypePoint type1 = getExp(child), type2 = getExp(child->nextSibling->nextSibling);

		if(type1 == NULL || type2 == NULL)
			return NULL;

		if(testType(type1,type2)==-1){
			printf("Error type 5 at Line %d: Type mismatched for \"%s\".\n",child->lineno,getName(child->nextSibling->name));
			return NULL;
		}
		if(child->nextSibling->name == ASSIGNOP)
			return type1;
		child = child->nextSibling;
		if(child->name  == AND || child->name == OR){
			//Exp -> Exp AND Exp | Exp OR Exp
			if(!(type1->kind == BASIC && type1->data.basic == INT && type2->kind == BASIC && type2->data.basic == INT)){
				printf("Error type 6 at Line %d: Type mismatched for \"%s\". Two variables' type should be int.\n",child->lineno,child->data);
				return NULL;
			}
		}
		else{
			//Exp -> Exp RELOP Exp | Exp PLUS Exp | Exp MINUS Exp | Exp DIV Exp
			if(!(type1->kind == BASIC && type2->kind == BASIC && type1->data.basic == type2->data.basic)){
				printf("Error type 6 at Line %d: Type mismatched for \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			if(child->name == RELOP){//比较结果应该返回int型的值
				TypePoint newType = (TypePoint)malloc(sizeof(Type));
				newType->kind = BASIC;
				newType->data.basic = INT;
				return newType;
		 	}
		}

		return type1;
	}
	else if(child->name == LP){
		return getExp(child->nextSibling);
	}
	else if(child->name == MINUS || child->name == NOT){
		//Exp -> MINUS Exp | NOT Exp
		TypePoint p = getExp(child->nextSibling);
		if(!(p->kind == BASIC && p->data.basic == INT)){
			printf("Error type 6 at Line %d: Type mismatched for \"%s\".\n",child->lineno,(child->name==NOT)?"!":".");
			return NULL;
		}
		return p;
	}
	else if(child->name == ID){
		if(child->nextSibling != NULL){
			//Exp -> ID LP RP | ID LP Args RP
			TableNode* find = findTableNode(child->data);
			if(find == NULL){
				printf("Error type 2 at Line %d: Undefined function \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			else if(find->type->kind != FUNCTION){
				printf("Error type 11 at Line %d: \"%s\" is not a function.\n",child->lineno,child->data);
				return NULL;
			}
			else{
				TypePoint tempType = find->type;
				if(child->nextSibling->nextSibling->name == RP){
					if(tempType->data.structure->tail == NULL){
						return tempType->data.structure->type;
					}
					else{
						printf("Error type 9 at Line %d: Too few arguments for function \"%s\".\n",child->lineno,find->name);
						return NULL;
					}
				}
				else{
					FieldListPoint argList = tempType->data.structure->tail;
					if(argList == NULL){
						printf("Error type 9 at Line %d: Too many arguments for function \"%s\".\n",child->lineno,child->data);
						return NULL;
					}
					for(child = child->nextSibling->nextSibling->firstChild;;){
						TypePoint childType = getExp(child);
						if(childType == NULL){
							return NULL;
						}
						if(testType(childType,argList->type)==-1){
							printf("Error type 9 at Line %d: Arguments type mismatched.\n",child->lineno);
							return NULL;
						}
						argList = argList->tail;
						//child = child->nextSibling;
						if(argList == NULL && child->nextSibling != NULL){
							printf("Error type 9 at Line %d: Too many arguments for function \"%s\".\n",child->lineno,find->name);
							return NULL;
						}
						if(argList != NULL && child->nextSibling == NULL){
							printf("Error type 9 at Line %d: Too few arguments for function \"%s\".\n",child->lineno,find->name);
							return NULL;
						}
						if(argList == NULL && child->nextSibling == NULL)
							return find->type->data.structure->type;
						child = child->nextSibling->nextSibling->firstChild;
					}
				}
				printf("Should never arrivs this %s %d.\n",__FILE__,__LINE__);
			return tempType->data.structure->type;
			}
		}
		TableNode *find = findTableNode(child->data);
		if(find == NULL){
			if(child->nextSibling == NULL){
				printf("Error type 1 at Line %d: Undefined variable \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			else{
				printf("Error type 2 at Line %d: Undefined function \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
		}
		else{
			if(find->type->kind == STRUCTURE && find->type->data.structure->name != NULL && strcmp(find->type->data.structure->name,find->name)==0){
				printf("Error type 13 at Line %d: \"%s\" is a struct, isn't a variable.\n",child->lineno,find->name);
				return NULL;
			}
			return find->type;
		}
	}
	else if(child->name == INT){
		TypePoint t = (TypePoint)malloc(sizeof(Type));
		t->kind = BASIC;
		t->data.basic = INT;
		return t;
	}
	else {
		if(child->name != FLOAT){
			printf("Error in %s %d.\n",__FILE__,__LINE__);
		}
		TypePoint t = (TypePoint)malloc(sizeof(Type));
		t->kind = BASIC;
		t->data.basic = FLOAT;
		return t;
	}
}
Beispiel #27
0
void PlotsBuilder::setupTypes()
{
    #define testType(tname) if (m_types.testFlag( tname )) m_widget->build##tname->show(); else m_widget->build##tname->hide();

    //2D
    testType(CartesianGraphCurve);
    testType(CartesianGraphCurve);
    testType(CartesianImplicitCurve);
    testType(CartesianParametricCurve2D);
    testType(PolarGraphCurve);
    //3D
    testType(CartesianParametricCurve3D);
    testType(CartesianGraphSurface);
    testType(CartesianImplicitSurface);
    testType(CartesianParametricSurface);
    testType(CylindricalGraphSurface);
    testType(SphericalGraphSurface);
    
    if (m_types.testFlag(CartesianGraphCurve) || m_types.testFlag(CartesianImplicitCurve) || m_types.testFlag(CartesianParametricCurve2D))
        m_widget->cartesianCurvesLinks->show();
    else
        m_widget->cartesianCurvesLinks->hide();
    
    if (m_types.testFlag(PolarGraphCurve))
        m_widget->polarCurvesLinks->show();
    else
        m_widget->polarCurvesLinks->hide();
    
    if (m_types.testFlag(CartesianParametricCurve3D))
        m_widget->spaceCurvesLinks->show();
    else
        m_widget->spaceCurvesLinks->hide();

    if (m_types.testFlag(CartesianGraphSurface) || m_types.testFlag(CartesianImplicitSurface) || m_types.testFlag(CartesianParametricSurface))
        m_widget->cartesianSurfacesLinks->show();
    else
        m_widget->cartesianSurfacesLinks->hide();

    if (m_types.testFlag(CylindricalGraphSurface))
        m_widget->cylindricalSurfacesLinks->show();
    else
        m_widget->cylindricalSurfacesLinks->hide();
    
    if (m_types.testFlag(SphericalGraphSurface))
        m_widget->sphericalSurfacesLinks->show();
    else
        m_widget->sphericalSurfacesLinks->hide();
}
Beispiel #28
0
QString AListItem::toString() const
{
	QString flags;
	flags+=isInvert() ? "!" : " ";

	switch (matcherType())
	{
	case AListItem::MatcherUnknown:
		flags+="? ";
		break;
	case AListItem::MatcherNick:
		flags+="N ";
		break;
	case AListItem::MatcherJid:
		flags+="J ";
		break;
	case AListItem::MatcherBody:
		flags+="B ";
		break;
	case AListItem::MatcherBodySize:
		flags+="Bs ";
		break;
	case AListItem::MatcherResource:
		flags+="R ";
		break;
	case AListItem::MatcherVersion:
		flags+="V ";
		break;
	case AListItem::MatcherVersionName:
		flags+="Vn";
		break;
	case AListItem::MatcherVersionClient:
		flags+="Vn";
		break;
	case AListItem::MatcherVersionOs:
		flags+="Vo";
		break;
	case AListItem::MatcherVCardPhotoSize:
		flags+="Ps";
		break;
	case AListItem::MatcherAge:
		flags+="Ag";
		break;
	case AListItem::MatcherRole:
		flags+="ro";
		break;
	};

	switch (testType())
	{
		case AListItem::TestUnknown:
			flags+="?";
			break;
		case AListItem::TestExact:
			flags+=" ";
			break;
		case AListItem::TestRegExp:
			flags+="E";
			break;
		case AListItem::TestSubstring:
			flags+="S";
			break;
		case AListItem::TestGreater:
			flags+=">";
			break;
		case AListItem::TestLesser:
			flags+="<";
			break;
	}

	QString line=QString("%1 %2").arg(flags).arg(value());
	if (expire().isValid())
	{
		int delta=QDateTime::currentDateTime().secsTo(expire());
		if (delta>0)
			line+=QString("	[%1]").arg(secsToString(delta));
		else
			line+=QString(" [EXPIRED]");
	}
	if (!reason().isEmpty())
		line+=" // "+reason();
	if (child_)
		line+="\n   && "+child_->toString();
	return line;
}