Exemplo n.º 1
0
void TypeChecker::checkInheritanceOfInners(Class* inner){
	if (inner->getBaseClassSymbol() != nullptr || inner->getInhertedFrom() == "Object") // base class found in previous check or not inheriting at all
		return;

	if (inner->getOuterClass() == nullptr)// not an inner class
		return;

	Class* bOuter = inner->getOuterClass()->getBaseClassSymbol(); // baseClass of outer
	if (bOuter == nullptr){ // outer not inhereting
		string errString = string(inner->getInhertedFrom()) + " is not defined ";
		this->errRecovery->errQ->enqueue(inner->getLineNo(), inner->getColNo(), errString.c_str(), "");
		return;
	}

	vector<Symbol*> symbols = bOuter->getBodyScope()->getSymbolTable()->symbols();
	vector<Symbol*>::iterator i;
	bool found = false;
	for (i = symbols.begin(); i != symbols.end(); ++i){
		int sType = (*i)->getSymbolType();
		if (sType == CLASS){//inner class
			Class* s = dynamic_cast<Class*>(*i);
			if (string(s->getName()) == inner->getInhertedFrom())
				found = true;

		}
	}
	if (!found){
		string errString = string(inner->getInhertedFrom()) + " is not defined ";
		this->errRecovery->errQ->enqueue(inner->getLineNo(), inner->getColNo(), errString.c_str(), "");
	}


}
Exemplo n.º 2
0
void TypeChecker::searchScopeForInners(Scope* scope){
	if (scope == nullptr)
		return;
	vector<Symbol*> symbols = scope->getSymbolTable()->symbols();
	vector<Symbol*>::iterator i;
	for (i = symbols.begin(); i != symbols.end(); ++i){
				
		int sType = (*i)->getSymbolType();
		if (sType == CLASS){//inner class
			Class* s = dynamic_cast<Class*>(*i);
			
			searchScopeForInners(s->getBodyScope());
			checkNamingOfInners(s);
			checkInheritanceOfInners(s);

		}
	}
}