Skip to content

Commit 4c6f446

Browse files
author
robertDurst
committed
update extraction type names for clarity
1 parent 616bdee commit 4c6f446

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/semantics/TypeChecker.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ truncateType(std::string fulltype)
123123

124124
// given a primary, determine its type
125125
std::string
126-
TypeChecker::expressionHelper(ast::Expression* node)
126+
TypeChecker::getType(ast::Expression* node)
127127
{
128128
switch (node->getExpressionType())
129129
{
@@ -146,7 +146,7 @@ TypeChecker::expressionHelper(ast::Expression* node)
146146
for (ast::UDTitem* const& item : udt->getAttributes())
147147
{
148148
fullTypeName += "$" + item->getKey()->getValue() + "$" +
149-
primaryHelper(item->getValue());
149+
getType(item->getValue());
150150
}
151151

152152
return fullTypeName;
@@ -160,7 +160,7 @@ TypeChecker::expressionHelper(ast::Expression* node)
160160
ast::PrimaryExpression* subnode =
161161
dynamic_cast<ast::PrimaryExpression*>(node);
162162

163-
return primaryHelper(subnode->getPrimary());
163+
return getType(subnode->getPrimary());
164164
}
165165
case ast::Expression::UnaryExpression:
166166
return "bool";
@@ -169,7 +169,7 @@ TypeChecker::expressionHelper(ast::Expression* node)
169169

170170
// given a primary, determine the type
171171
std::string
172-
TypeChecker::primaryHelper(ast::Primary* primary)
172+
TypeChecker::getType(ast::Primary* primary)
173173
{
174174
ast::Primary::PrimaryType type = primary->getPrimaryType();
175175

@@ -378,7 +378,7 @@ TypeChecker::compareFunctions(std::vector<std::string> inputs,
378378
for (int i = 0; i < numArgs; i++)
379379
{
380380
ast::Primary* arg = args.at(i);
381-
std::string actual = primaryHelper(arg);
381+
std::string actual = getType(arg);
382382

383383
// if not primitive, see if it is a variable in the symbol table
384384
if (!isPrimitive(actual))
@@ -428,9 +428,9 @@ TypeChecker::compareFunctions(std::vector<std::string> inputs,
428428

429429
// given a right expression, determin its type
430430
std::string
431-
TypeChecker::getRightExpressionType(ast::BinaryExpression* node)
431+
TypeChecker::getType(ast::BinaryExpression* node)
432432
{
433-
return expressionHelper(node->getLeftExpr());
433+
return getType(node->getLeftExpr());
434434
}
435435

436436
// ------- Additions to the symbol table ------- //
@@ -464,7 +464,7 @@ TypeChecker::visit(ast::NewUDTDefinition* node)
464464
// visit expression
465465
visit(node->getExpression());
466466

467-
std::string exprType = expressionHelper(node->getExpression());
467+
std::string exprType = getType(node->getExpression());
468468

469469
std::string temp;
470470
std::string prev;
@@ -602,7 +602,7 @@ TypeChecker::visit(ast::PrimitiveDefition* node)
602602
// visit expression
603603
visit(node->getBinaryExpression());
604604

605-
std::string exprType = getRightExpressionType(node->getBinaryExpression());
605+
std::string exprType = getType(node->getBinaryExpression());
606606

607607
// ensure assignment is the expected type
608608
if (exprType != type)
@@ -718,7 +718,7 @@ TypeChecker::visit(ast::FunctionDefinition* node)
718718
ast::BinaryExpression* returnedExpr =
719719
subnode->getBinaryExpression();
720720

721-
std::string actualReturnType = getRightExpressionType(returnedExpr);
721+
std::string actualReturnType = getType(returnedExpr);
722722

723723
if (actualReturnType != out_type)
724724
semanticErrorHandler->handle(new Error(
@@ -870,7 +870,7 @@ TypeChecker::visit(ast::Negation* node)
870870
visit(node->getBinaryExpression());
871871

872872
// ensure that all negations are boolean
873-
std::string type = getRightExpressionType(node->getBinaryExpression());
873+
std::string type = getType(node->getBinaryExpression());
874874
if (type != "bool")
875875
semanticErrorHandler->handle(new Error(
876876
node->getLineNum(),
@@ -892,9 +892,9 @@ TypeChecker::visit(ast::BinaryExpression* node)
892892
visit(node->getLeftExpr());
893893
visit(node->getRightExpr());
894894

895-
std::string lType = expressionHelper(node->getLeftExpr());
895+
std::string lType = getType(node->getLeftExpr());
896896

897-
std::string rType = getRightExpressionType(node->getRightExpr());
897+
std::string rType = getType(node->getRightExpr());
898898

899899
switch (node->getBinaryExpressionType())
900900
{

src/semantics/TypeChecker.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ class TypeChecker : public Visitor
2424
// hacks: REMOVE ASAP
2525
std::string curUDT;
2626

27-
// helpers that need to know the internals of type checker
28-
std::string primaryHelper(ast::Primary*);
29-
std::string expressionHelper(ast::Expression*);
30-
void compareFunctions(std::vector<std::string>, std::vector<ast::Primary*>,
31-
std::string, int);
32-
std::string getRightExpressionType(ast::BinaryExpression* node);
27+
// helpers for extracting the type of a node
28+
std::string getType(ast::Primary*);
29+
std::string getType(ast::Expression*);
30+
std::string getType(ast::BinaryExpression* node);
31+
32+
// helper methods for easy type checking and error message handling
3333
bool nameIsLegal(std::string, int);
3434
bool typeExists(std::string, std::string, int);
3535
bool tryAddToSymbolTable(std::string, std::string, SymbolTable*, int);
3636
bool tryAddToSymbolTableIterative(std::string, std::string, SymbolTable*,
3737
int);
38+
void compareFunctions(std::vector<std::string>, std::vector<ast::Primary*>,
39+
std::string, int);
3840

3941
public:
4042
using Visitor::visit;

0 commit comments

Comments
 (0)