本文整理汇总了C++中TypeChecker::binder方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeChecker::binder方法的具体用法?C++ TypeChecker::binder怎么用?C++ TypeChecker::binder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeChecker
的用法示例。
在下文中一共展示了TypeChecker::binder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: typeCheck
void MemberCallExpressionAST::typeCheck(TypeChecker& checker) {
mAccessExpression->typeCheck(checker);
if (auto varRef = std::dynamic_pointer_cast<VariableReferenceExpressionAST>(mAccessExpression)) {
auto varSymbol = std::dynamic_pointer_cast<VariableSymbol>(mSymbolTable->find(varRef->name()));
auto varRefType = checker.findType(varSymbol->variableType());
std::string objName = varRefType->name();
if (!checker.objectExists(objName)) {
checker.typeError(varRefType->name() + " is not an object type.");
}
auto classSymbol = std::dynamic_pointer_cast<ClassSymbol>(Helpers::findSymbolInNamespace(mSymbolTable, objName));
mMemberCallExpression->setCallTable(classSymbol->symbolTable());
mMemberCallExpression->generateSymbols(checker.binder(), mSymbolTable);
mMemberCallExpression->typeCheck(checker);
} else {
auto varRefType = mAccessExpression->expressionType(checker);
std::string objName = varRefType->name();
if (!checker.objectExists(objName)) {
checker.typeError(varRefType->name() + " is not an object type.");
}
auto classSymbol = std::dynamic_pointer_cast<ClassSymbol>(Helpers::findSymbolInNamespace(mSymbolTable, objName));
mMemberCallExpression->setCallTable(classSymbol->symbolTable());
mMemberCallExpression->generateSymbols(checker.binder(), mSymbolTable);
mMemberCallExpression->typeCheck(checker);
}
}
示例2: typeCheck
void BinaryOpExpressionAST::typeCheck(TypeChecker& checker) {
mRightHandSide->typeCheck(checker);
mLeftHandSide->typeCheck(checker);
auto lhsType = mLeftHandSide->expressionType(checker);
auto rhsType = mRightHandSide->expressionType(checker);
if (lhsType->name() != "Auto") {
checker.assertSameType(
*lhsType,
*rhsType,
asString());
} else {
//Infer the type
auto lhsVarDec = std::dynamic_pointer_cast<VariableDeclarationExpressionAST>(mLeftHandSide);
if (lhsVarDec != nullptr) {
if (lhsType->name() == "Auto" && *rhsType == NullReferenceType()) {
checker.typeError("Implicitly type of a null variable is not allowed.");
}
mLeftHandSide = std::make_shared<VariableDeclarationExpressionAST>(
rhsType->name(),
lhsVarDec->name(),
lhsVarDec->isFunctionParameter());
//Update the symbol
mSymbolTable->remove(lhsVarDec->name());
mLeftHandSide->generateSymbols(checker.binder(), mSymbolTable);
} else {
//Should never happen
checker.typeError("Auto type is only allowed in variable declaration.");
}
}
}