Skip to content

Commit

Permalink
Replace TypePointer with Type const*
Browse files Browse the repository at this point in the history
  • Loading branch information
Marenz committed Mar 23, 2021
1 parent 8c58378 commit e197ebb
Show file tree
Hide file tree
Showing 50 changed files with 347 additions and 353 deletions.
4 changes: 2 additions & 2 deletions libsolidity/analysis/ConstantEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
if (!value)
return;

TypePointer resultType = value->type->unaryOperatorResult(_operation.getOperator());
Type const* resultType = value->type->unaryOperatorResult(_operation.getOperator());
if (!resultType)
return;
value = convertType(value, *resultType);
Expand Down Expand Up @@ -340,7 +340,7 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
if (TokenTraits::isCompareOp(_operation.getOperator()))
return;

TypePointer resultType = left->type->binaryOperatorResult(_operation.getOperator(), right->type);
Type const* resultType = left->type->binaryOperatorResult(_operation.getOperator(), right->type);
if (!resultType)
{
m_errorReporter.fatalTypeError(
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/ConstantEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ConstantEvaluator: private ASTConstVisitor
public:
struct TypedRational
{
TypePointer type;
Type const* type;
rational value;
};

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/ContractLevelChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ void ContractLevelChecker::checkBaseABICompatibility(ContractDefinition const& _

auto const& currentLoc = func.second->declaration().location();

for (TypePointer const& paramType: func.second->parameterTypes() + func.second->returnParameterTypes())
for (Type const* paramType: func.second->parameterTypes() + func.second->returnParameterTypes())
if (!TypeChecker::typeSupportedByOldABIEncoder(*paramType, false))
{
errors.append("Type only supported by ABIEncoderV2", currentLoc);
Expand Down
8 changes: 4 additions & 4 deletions libsolidity/analysis/DeclarationTypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ void DeclarationTypeChecker::endVisit(Mapping const& _mapping)
else
solAssert(dynamic_cast<ElementaryTypeName const*>(&_mapping.keyType()), "");

TypePointer keyType = _mapping.keyType().annotation().type;
TypePointer valueType = _mapping.valueType().annotation().type;
Type const* keyType = _mapping.keyType().annotation().type;
Type const* valueType = _mapping.valueType().annotation().type;

// Convert key type to memory.
keyType = TypeProvider::withLocationIfReference(DataLocation::Memory, keyType);
Expand All @@ -255,7 +255,7 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
if (_typeName.annotation().type)
return;

TypePointer baseType = _typeName.baseType().annotation().type;
Type const* baseType = _typeName.baseType().annotation().type;
if (!baseType)
{
solAssert(!m_errorReporter.errors().empty(), "");
Expand Down Expand Up @@ -405,7 +405,7 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
solAssert(!_variable.hasReferenceOrMappingType(), "Data location not properly set.");
}

TypePointer type = _variable.typeName().annotation().type;
Type const* type = _variable.typeName().annotation().type;
if (auto ref = dynamic_cast<ReferenceType const*>(type))
{
bool isPointer = !_variable.isStateVariable();
Expand Down
60 changes: 30 additions & 30 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ bool TypeChecker::checkTypeRequirements(SourceUnit const& _source)
return Error::containsOnlyWarnings(m_errorReporter.errors());
}

TypePointer const& TypeChecker::type(Expression const& _expression) const
Type const* TypeChecker::type(Expression const& _expression) const
{
solAssert(!!_expression.annotation().type, "Type requested but not present.");
return _expression.annotation().type;
}

TypePointer const& TypeChecker::type(VariableDeclaration const& _variable) const
Type const* TypeChecker::type(VariableDeclaration const& _variable) const
{
solAssert(!!_variable.annotation().type, "Type requested but not present.");
return _variable.annotation().type;
Expand Down Expand Up @@ -183,7 +183,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
solAssert(typeArgument, "");
if (TypeType const* argTypeType = dynamic_cast<TypeType const*>(type(*typeArgument)))
{
TypePointer actualType = argTypeType->actualType();
Type const* actualType = argTypeType->actualType();
solAssert(actualType, "");
// We force memory because the parser currently cannot handle
// data locations. Furthermore, storage can be a little dangerous and
Expand Down Expand Up @@ -237,7 +237,7 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
toString(arguments.size()) +
" were provided."
);
TypePointer firstArgType = type(*arguments.front());
Type const* firstArgType = type(*arguments.front());

bool wrongType = false;
if (firstArgType->category() == Type::Category::TypeType)
Expand Down Expand Up @@ -502,7 +502,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)

// type is filled either by ReferencesResolver directly from the type name or by
// TypeChecker at the VariableDeclarationStatement level.
TypePointer varType = _variable.annotation().type;
Type const* varType = _variable.annotation().type;
solAssert(!!varType, "Variable type not provided.");

if (_variable.value())
Expand Down Expand Up @@ -1152,7 +1152,7 @@ void TypeChecker::endVisit(Return const& _return)
m_errorReporter.typeError(8863_error, _return.location(), "Different number of arguments in return statement than in returns declaration.");
else
{
TypePointer const& expected = type(*params->parameters().front());
Type const* expected = type(*params->parameters().front());
BoolResult result = type(*_return.expression())->isImplicitlyConvertibleTo(*expected);
if (!result)
m_errorReporter.typeErrorConcatenateDescriptions(
Expand Down Expand Up @@ -1236,7 +1236,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
continue;
VariableDeclaration const& var = *variables[i];
solAssert(!var.value(), "Value has to be tied to statement.");
TypePointer const& valueComponentType = valueTypes[i];
Type const* valueComponentType = valueTypes[i];
solAssert(!!valueComponentType, "");
solAssert(var.annotation().type, "");

Expand Down Expand Up @@ -1322,10 +1322,10 @@ bool TypeChecker::visit(Conditional const& _conditional)
_conditional.trueExpression().accept(*this);
_conditional.falseExpression().accept(*this);

TypePointer trueType = type(_conditional.trueExpression())->mobileType();
TypePointer falseType = type(_conditional.falseExpression())->mobileType();
Type const* trueType = type(_conditional.trueExpression())->mobileType();
Type const* falseType = type(_conditional.falseExpression())->mobileType();

TypePointer commonType = nullptr;
Type const* commonType = nullptr;

if (!trueType)
m_errorReporter.typeError(9717_error, _conditional.trueExpression().location(), "Invalid mobile type in true expression.");
Expand Down Expand Up @@ -1387,7 +1387,7 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const&
m_errorReporter.typeError(5547_error, _expression.location(), "Empty tuple on the left hand side.");

auto const* tupleType = dynamic_cast<TupleType const*>(&_type);
auto const& types = tupleType && tupleExpression->components().size() != 1 ? tupleType->components() : vector<TypePointer> { &_type };
auto const& types = tupleType && tupleExpression->components().size() != 1 ? tupleType->components() : vector<Type const*> { &_type };

solAssert(
tupleExpression->components().size() == types.size() || m_errorReporter.hasErrors(),
Expand Down Expand Up @@ -1419,7 +1419,7 @@ bool TypeChecker::visit(Assignment const& _assignment)
_assignment.leftHandSide(),
_assignment.assignmentOperator() == Token::Assign
);
TypePointer t = type(_assignment.leftHandSide());
Type const* t = type(_assignment.leftHandSide());
_assignment.annotation().type = t;
_assignment.annotation().isPure = false;
_assignment.annotation().isLValue = false;
Expand Down Expand Up @@ -1450,7 +1450,7 @@ bool TypeChecker::visit(Assignment const& _assignment)
{
// compound assignment
_assignment.rightHandSide().accept(*this);
TypePointer resultType = t->binaryOperatorResult(
Type const* resultType = t->binaryOperatorResult(
TokenTraits::AssignmentToBinaryOp(_assignment.assignmentOperator()),
type(_assignment.rightHandSide())
);
Expand Down Expand Up @@ -1489,7 +1489,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
types.push_back(type(*component));
}
else
types.push_back(TypePointer());
types.push_back(nullptr);
if (components.size() == 1)
_tuple.annotation().type = type(*components[0]);
else
Expand All @@ -1501,7 +1501,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
else
{
bool isPure = true;
TypePointer inlineArrayType = nullptr;
Type const* inlineArrayType = nullptr;

for (size_t i = 0; i < components.size(); ++i)
{
Expand Down Expand Up @@ -1581,8 +1581,8 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
requireLValue(_operation.subExpression(), false);
else
_operation.subExpression().accept(*this);
TypePointer const& subExprType = type(_operation.subExpression());
TypePointer t = type(_operation.subExpression())->unaryOperatorResult(op);
Type const* subExprType = type(_operation.subExpression());
Type const* t = type(_operation.subExpression())->unaryOperatorResult(op);
if (!t)
{
string description = "Unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->toString();
Expand All @@ -1604,10 +1604,10 @@ bool TypeChecker::visit(UnaryOperation const& _operation)

void TypeChecker::endVisit(BinaryOperation const& _operation)
{
TypePointer const& leftType = type(_operation.leftExpression());
TypePointer const& rightType = type(_operation.rightExpression());
Type const* leftType = type(_operation.leftExpression());
Type const* rightType = type(_operation.rightExpression());
TypeResult result = leftType->binaryOperatorResult(_operation.getOperator(), rightType);
TypePointer commonType = result.get();
Type const* commonType = result.get();
if (!commonType)
{
m_errorReporter.typeError(
Expand Down Expand Up @@ -1669,17 +1669,17 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
}
}

TypePointer TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
FunctionCall const& _functionCall
)
{
solAssert(*_functionCall.annotation().kind == FunctionCallKind::TypeConversion, "");
TypePointer const& expressionType = type(_functionCall.expression());
Type const* expressionType = type(_functionCall.expression());

vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
bool const isPositionalCall = _functionCall.names().empty();

TypePointer resultType = dynamic_cast<TypeType const&>(*expressionType).actualType();
Type const* resultType = dynamic_cast<TypeType const&>(*expressionType).actualType();
if (arguments.size() != 1)
m_errorReporter.typeError(
2558_error,
Expand Down Expand Up @@ -2358,7 +2358,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
case Type::Category::TypeType:
{
// Determine type for type conversion or struct construction expressions
TypePointer const& actualType = dynamic_cast<TypeType const&>(*expressionType).actualType();
Type const* actualType = dynamic_cast<TypeType const&>(*expressionType).actualType();
solAssert(!!actualType, "");

if (actualType->category() == Type::Category::Struct)
Expand Down Expand Up @@ -2610,7 +2610,7 @@ bool TypeChecker::visit(FunctionCallOptions const& _functionCallOptions)

void TypeChecker::endVisit(NewExpression const& _newExpression)
{
TypePointer type = _newExpression.typeName().annotation().type;
Type const* type = _newExpression.typeName().annotation().type;
solAssert(!!type, "Type name not resolved.");

_newExpression.annotation().isConstant = false;
Expand Down Expand Up @@ -2684,7 +2684,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
bool TypeChecker::visit(MemberAccess const& _memberAccess)
{
_memberAccess.expression().accept(*this);
TypePointer exprType = type(_memberAccess.expression());
Type const* exprType = type(_memberAccess.expression());
ASTString const& memberName = _memberAccess.memberName();

auto& annotation = _memberAccess.annotation();
Expand Down Expand Up @@ -2972,8 +2972,8 @@ bool TypeChecker::visit(IndexAccess const& _access)
{
_access.annotation().isConstant = false;
_access.baseExpression().accept(*this);
TypePointer baseType = type(_access.baseExpression());
TypePointer resultType = nullptr;
Type const* baseType = type(_access.baseExpression());
Type const* resultType = nullptr;
bool isLValue = false;
bool isPure = *_access.baseExpression().annotation().isPure;
Expression const* index = _access.indexExpression();
Expand Down Expand Up @@ -3109,7 +3109,7 @@ bool TypeChecker::visit(IndexRangeAccess const& _access)
_access.annotation().isLValue = isLValue;
_access.annotation().isPure = isPure;

TypePointer exprType = type(_access.baseExpression());
Type const* exprType = type(_access.baseExpression());
if (exprType->category() == Type::Category::TypeType)
{
m_errorReporter.typeError(1760_error, _access.location(), "Types cannot be sliced.");
Expand Down Expand Up @@ -3157,7 +3157,7 @@ vector<Declaration const*> TypeChecker::cleanOverloadedDeclarations(
functionType = declaration->functionType(true);
solAssert(functionType, "Failed to determine the function type of the overloaded.");

for (TypePointer parameter: functionType->parameterTypes() + functionType->returnParameterTypes())
for (Type const* parameter: functionType->parameterTypes() + functionType->returnParameterTypes())
if (!parameter)
m_errorReporter.fatalDeclarationError(3893_error, _identifier.location(), "Function type can not be used in this context.");

Expand Down
6 changes: 3 additions & 3 deletions libsolidity/analysis/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class TypeChecker: private ASTConstVisitor
bool checkTypeRequirements(SourceUnit const& _source);

/// @returns the type of an expression and asserts that it is present.
TypePointer const& type(Expression const& _expression) const;
Type const* type(Expression const& _expression) const;
/// @returns the type of the given variable and throws if the type is not present
/// (this can happen for variables with non-explicit types before their types are resolved)
TypePointer const& type(VariableDeclaration const& _variable) const;
Type const* type(VariableDeclaration const& _variable) const;

static bool typeSupportedByOldABIEncoder(Type const& _type, bool _isLibraryCall);

Expand All @@ -85,7 +85,7 @@ class TypeChecker: private ASTConstVisitor
TypePointers typeCheckMetaTypeFunctionAndRetrieveReturnType(FunctionCall const& _functionCall);

/// Performs type checks and determines result types for type conversion FunctionCall nodes.
TypePointer typeCheckTypeConversionAndRetrieveReturnType(
Type const* typeCheckTypeConversionAndRetrieveReturnType(
FunctionCall const& _functionCall
);

Expand Down
20 changes: 10 additions & 10 deletions libsolidity/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ImportAnnotation& ImportDirective::annotation() const
return initAnnotation<ImportAnnotation>();
}

TypePointer ImportDirective::type() const
Type const* ImportDirective::type() const
{
solAssert(!!annotation().sourceUnit, "");
return TypeProvider::module(*annotation().sourceUnit);
Expand Down Expand Up @@ -206,7 +206,7 @@ uint32_t ContractDefinition::interfaceId() const
return result;
}

TypePointer ContractDefinition::type() const
Type const* ContractDefinition::type() const
{
return TypeProvider::typeType(TypeProvider::contract(*this));
}
Expand Down Expand Up @@ -252,7 +252,7 @@ TypeNameAnnotation& TypeName::annotation() const
return initAnnotation<TypeNameAnnotation>();
}

TypePointer StructDefinition::type() const
Type const* StructDefinition::type() const
{
solAssert(annotation().recursive.has_value(), "Requested struct type before DeclarationTypeChecker.");
return TypeProvider::typeType(TypeProvider::structType(*this, DataLocation::Storage));
Expand All @@ -263,14 +263,14 @@ StructDeclarationAnnotation& StructDefinition::annotation() const
return initAnnotation<StructDeclarationAnnotation>();
}

TypePointer EnumValue::type() const
Type const* EnumValue::type() const
{
auto parentDef = dynamic_cast<EnumDefinition const*>(scope());
solAssert(parentDef, "Enclosing Scope of EnumValue was not set");
return TypeProvider::enumType(*parentDef);
}

TypePointer EnumDefinition::type() const
Type const* EnumDefinition::type() const
{
return TypeProvider::typeType(TypeProvider::enumType(*this));
}
Expand Down Expand Up @@ -328,13 +328,13 @@ FunctionTypePointer FunctionDefinition::functionType(bool _internal) const
return {};
}

TypePointer FunctionDefinition::type() const
Type const* FunctionDefinition::type() const
{
solAssert(visibility() != Visibility::External, "");
return TypeProvider::function(*this, FunctionType::Kind::Internal);
}

TypePointer FunctionDefinition::typeViaContractName() const
Type const* FunctionDefinition::typeViaContractName() const
{
if (libraryFunction())
{
Expand Down Expand Up @@ -395,7 +395,7 @@ FunctionDefinition const& FunctionDefinition::resolveVirtual(
return *this; // not reached
}

TypePointer ModifierDefinition::type() const
Type const* ModifierDefinition::type() const
{
return TypeProvider::modifier(*this);
}
Expand Down Expand Up @@ -432,7 +432,7 @@ ModifierDefinition const& ModifierDefinition::resolveVirtual(
}


TypePointer EventDefinition::type() const
Type const* EventDefinition::type() const
{
return TypeProvider::function(*this);
}
Expand Down Expand Up @@ -672,7 +672,7 @@ string VariableDeclaration::externalIdentifierHex() const
return TypeProvider::function(*this)->externalIdentifierHex();
}

TypePointer VariableDeclaration::type() const
Type const* VariableDeclaration::type() const
{
return annotation().type;
}
Expand Down
Loading

0 comments on commit e197ebb

Please sign in to comment.