@@ -255,6 +255,84 @@ TypeChecker::getType(ast::Primary* primary)
255255
256256 return truncateType (fullAttributeType);
257257 }
258+ case ast::Primary::AttributeMethodAccessLiteral:
259+ {
260+ ast::AttributeMethodAccess* node =
261+ dynamic_cast <ast::AttributeMethodAccess*>(primary);
262+
263+ // ------- first extract the attribute ------- //
264+ ast::AttributeAccess* subsubnode = node->getAttribute ();
265+
266+ std::string attributeName = subsubnode->getAttribute ()->getValue ();
267+ std::string variableName = subsubnode->getUDT ()->getValue ();
268+
269+ // hacks: REMOVE ASAP
270+ if (variableName == " own" )
271+ {
272+ variableName = curUDT;
273+ }
274+ else
275+ {
276+ // ensure variable exists - double checked so no need for another
277+ // error message
278+ if (!symbolTable->hasVariable (variableName))
279+ {
280+ return " unknown" ;
281+ }
282+
283+ std::string udtTypeFull = symbolTable->getSymbolType (variableName);
284+ variableName = udtTypeFull.substr (1 , udtTypeFull.length ());
285+ }
286+
287+ // ensure udt exists - double checked so no need for another
288+ // error message
289+ if (!udtTable->hasUDT (variableName))
290+ {
291+ return " unknown" ;
292+ }
293+
294+ // ensure attribute exists for udt - double checked so only return error
295+ // once
296+ if (!udtTable->getAttributeSymbolTable (variableName)
297+ ->hasVariable (attributeName))
298+ {
299+ return " unknown" ;
300+ }
301+
302+ // std::string fullAttributeType =
303+ // udtTable->getAttributeSymbolTable(variableName)
304+ // ->getSymbolType(attributeName);
305+
306+ // ------- now extract the method ------- //
307+ std::string methodName = node->getName ()->getValue ();
308+ std::string variableUDTname = getType (node->getAttribute ());
309+
310+ // hacks: REMOVE ASAP
311+ if (variableUDTname == " own" )
312+ {
313+ variableUDTname = curUDT;
314+ }
315+ else
316+ {
317+ // ensure variable's udt exists - double checked so no need for
318+ // another error message
319+ if (!udtTable->hasUDT (variableUDTname))
320+ {
321+ return " unknown" ;
322+ }
323+ }
324+
325+ // ensure metho exists for udt - double checked so no need for another
326+ // error message
327+ if (!udtTable->getMethodSymbolTable (variableUDTname)
328+ ->hasVariable (methodName))
329+ {
330+ return " unknown" ;
331+ }
332+
333+ return truncateType (udtTable->getMethodSymbolTable (variableUDTname)
334+ ->getSymbolType (methodName));
335+ }
258336 case ast::Primary::MethodAccessLiteral:
259337 {
260338 ast::MethodAccess* node = dynamic_cast <ast::MethodAccess*>(primary);
@@ -1069,6 +1147,63 @@ TypeChecker::visit(ast::AttributeAccess* node)
10691147 }
10701148}
10711149
1150+ void
1151+ TypeChecker::visit (ast::AttributeMethodAccess* node)
1152+ {
1153+ visit (node->getAttribute ());
1154+
1155+ std::string methodName = node->getName ()->getValue ();
1156+ std::string variableUDTname = getType (node->getAttribute ());
1157+
1158+ std::cout << " HERE: " << variableUDTname << " \n " ;
1159+
1160+ // hacks: REMOVE ASAP
1161+ if (variableUDTname == " own" )
1162+ variableUDTname = curUDT;
1163+
1164+ else
1165+ {
1166+ // ensure variable's udt exists
1167+ if (!udtTable->hasUDT (variableUDTname))
1168+ {
1169+ semanticErrorHandler->handle (new Error (
1170+ node->getUDT ()->getLineNum (),
1171+ " Method: " + methodName + " called on nonexistent udt type: " +
1172+ variableUDTname + " ." ));
1173+
1174+ return ;
1175+ }
1176+ }
1177+
1178+ std::string udtType = variableUDTname;
1179+
1180+ // ensure metho exists for udt
1181+ if (!udtTable->getMethodSymbolTable (udtType)->hasVariable (methodName))
1182+ {
1183+ semanticErrorHandler->handle (
1184+ new Error (node->getName ()->getLineNum (),
1185+ " Method: " + methodName +
1186+ " does not exist for udt type: " + udtType + " ." ));
1187+ // abort
1188+ return ;
1189+ }
1190+
1191+ // visit function call
1192+ std::string fulltype =
1193+ udtTable->getMethodSymbolTable (udtType)->getSymbolType (methodName);
1194+
1195+ std::vector<std::string> inputs = getFunctionParamTypes (fulltype);
1196+
1197+ // ensure that each of the arguments is supplied and of the proper type
1198+ std::vector<ast::Primary*> args = node->getFunctionCall ()->getArguments ();
1199+
1200+ compareFunctions (inputs, args, methodName,
1201+ node->getFunctionCall ()->getLineNum ());
1202+
1203+ for (auto const & arg : args)
1204+ visit (arg);
1205+ }
1206+
10721207void
10731208TypeChecker::visit (ast::MethodAccess* node)
10741209{
0 commit comments