@@ -126,6 +126,11 @@ sailfishc::checkType(const std::string& t0, const std::string& t1)
126126 auto right =
127127 symboltable->hasVariable (t1) ? symboltable->getSymbolType (t1) : t1;
128128
129+ // if either is a udt, make sure we check udt type, not U which is returned
130+ // by symbol table
131+ left = left == " U" && udttable->hasUDT (t0) ? t0 : left;
132+ right = right == " U" && udttable->hasUDT (t1) ? t1 : right;
133+
129134 // should actually check types here
130135
131136 // edge case lists
@@ -261,16 +266,24 @@ sailfishc::checkFunctionCall(const std::string& name,
261266 bool flag = false ;
262267 for (int i = 0 ; i < inputs.size (); i++)
263268 {
269+ auto left = symboltable->hasVariable (inputs[i])
270+ ? symboltable->getSymbolType (inputs[i])
271+ : inputs[i];
272+ auto right = symboltable->hasVariable (fcInputs[i])
273+ ? symboltable->getSymbolType (fcInputs[i])
274+ : fcInputs[i];
275+
264276 if (inputs[i].at (0 ) == ' [' )
265277 inputs[i] = extractListType (inputs[i]);
266278
267279 if (fcInputs[i].at (0 ) == ' [' )
268280 fcInputs[i] = extractListType (fcInputs[i]);
269281
270- if (inputs[i] != fcInputs[i] )
282+ if (left != right )
271283 semanticerrorhandler->handle (std::make_unique<Error>(Error (
272284 currentToken->col , currentToken->line ,
273- " Function input parameter type mismatch in function call " +
285+ " Function input parameter type mismatch in "
286+ " function call " +
274287 name,
275288 " Expected " + inputs[i] + " and received: " , fcInputs[i],
276289 " ." )));
@@ -740,46 +753,48 @@ sailfishc::parseFunctionInOut(const std::string& name)
740753 bool seenVoid = false ;
741754 int argCount = 0 ;
742755 std::string outputBuffer = " " ;
743- recursiveParse (
744- true , TokenKind::RPAREN,
745- [&outputBuffer, &types, &seenVoid, &argCount, this ]() {
746- ++argCount;
747-
748- auto sands = this ->parseVariable ();
749- auto name = std::get<0 >(sands);
750- auto type = std::get<1 >(sands);
751-
752- if (type != " void" )
753- if (outputBuffer != " " )
754- outputBuffer +=
755- " , " + builtinTypesTranslator (type) + " " + name;
756- else
757- outputBuffer += builtinTypesTranslator (type) + " " + name;
758- else if (!isUdt)
759- {
760- if (outputBuffer != " " )
761- outputBuffer += " , " + builtinTypesTranslator (type);
762- else
763- outputBuffer += builtinTypesTranslator (type);
764- }
765-
766- if (type == " void" )
767- seenVoid = true ;
768-
769- if (argCount > 1 && seenVoid)
770- {
771- semanticerrorhandler->handle (std::make_unique<Error>(
772- Error (currentToken->col , currentToken->line ,
773- " Illegal multi-void definition of formals "
774- " in function signature" ,
775- " " , " " , " " )));
776- }
777-
778- if (type != " void" )
779- symboltable->addSymbol (std::get<0 >(sands), type);
780-
781- types += " _" + type;
782- });
756+ recursiveParse (true , TokenKind::RPAREN,
757+ [&outputBuffer, &types, &seenVoid, &argCount, this ]() {
758+ ++argCount;
759+
760+ auto sands = this ->parseVariable ();
761+ auto name = std::get<0 >(sands);
762+ auto type = std::get<1 >(sands);
763+
764+ auto outedType = builtinTypesTranslator (type);
765+ if (udttable->hasUDT (type))
766+ outedType = " struct " + outedType + " *" ;
767+
768+ if (type != " void" )
769+ if (outputBuffer != " " )
770+ outputBuffer += " , " + outedType + " " + name;
771+ else
772+ outputBuffer += outedType + " " + name;
773+ else if (!isUdt)
774+ {
775+ if (outputBuffer != " " )
776+ outputBuffer += " , " + outedType;
777+ else
778+ outputBuffer += outedType;
779+ }
780+
781+ if (type == " void" )
782+ seenVoid = true ;
783+
784+ if (argCount > 1 && seenVoid)
785+ {
786+ semanticerrorhandler->handle (std::make_unique<Error>(
787+ Error (currentToken->col , currentToken->line ,
788+ " Illegal multi-void definition of formals "
789+ " in function signature" ,
790+ " " , " " , " " )));
791+ }
792+
793+ if (type != " void" )
794+ symboltable->addSymbol (std::get<0 >(sands), type);
795+
796+ types += " _" + type;
797+ });
783798 advanceAndCheckToken (TokenKind::RPAREN); // consume r paren
784799
785800 // outputs
@@ -790,6 +805,9 @@ sailfishc::parseFunctionInOut(const std::string& name)
790805
791806 if (udttable->hasUDT (output))
792807 output = " struct " + output + " *" ;
808+ else
809+ output = builtinTypesTranslator (output);
810+
793811 advanceAndCheckToken (TokenKind::RPAREN); // consume r paren
794812
795813 if (isUdt)
@@ -1209,6 +1227,9 @@ sailfishc::parseE7(const std::string& T0)
12091227 auto type = T0;
12101228 if (!isPrimitive (T0))
12111229 type = this ->symboltable ->getSymbolType (T0);
1230+ if (type == " U" )
1231+ type = T0;
1232+
12121233 this ->checkType (type, T1);
12131234 return T1;
12141235 },
@@ -1300,7 +1321,9 @@ sailfishc::parseE10(const std::string& T0)
13001321 {
13011322 auto type = parseMemberAccess (T0);
13021323
1303- return parseE1 (type);
1324+ type = parseE1 (type);
1325+
1326+ return type;
13041327 }
13051328
13061329 return parseE11 (T0);
@@ -1398,12 +1421,16 @@ sailfishc::parseAttributeAccess(const std::string& udtname,
13981421 advanceAndCheckToken (TokenKind::DOT); // consume '.'
13991422 auto attribute = parseIdentifier ();
14001423
1401- if (udtname != " own " )
1402- targetBuffer += udtname ;
1424+ if (currentToken-> kind == TokenKind::TRIPLE_DOT )
1425+ attributeAccessName = attribute ;
14031426 else
1404- targetBuffer += " this" ;
1405-
1406- targetBuffer += " ->" + builtinTypesTranslator (attribute);
1427+ {
1428+ if (udtname != " own" )
1429+ targetBuffer += udtname;
1430+ else
1431+ targetBuffer += " this" ;
1432+ targetBuffer += " ->" + builtinTypesTranslator (attribute);
1433+ }
14071434
14081435 // check if type exists
14091436 if (!st->hasVariable (attribute))
@@ -1479,10 +1506,24 @@ sailfishc::parseFunctionCall()
14791506 });
14801507
14811508 if (methodAccessName != " " )
1509+ {
14821510 if (nonVoidInputs == 0 )
1483- targetBuffer += methodAccessName;
1511+ {
1512+ if (attributeAccessName != " " )
1513+ targetBuffer += " this->" + attributeAccessName;
1514+ else
1515+ targetBuffer += methodAccessName;
1516+ }
14841517 else
1485- targetBuffer += " , " + methodAccessName;
1518+ {
1519+ if (attributeAccessName != " " )
1520+ targetBuffer += " , this->" + attributeAccessName;
1521+ else
1522+ targetBuffer += ' ,' + methodAccessName;
1523+ }
1524+ }
1525+
1526+ attributeAccessName = " " ;
14861527
14871528 types += " )" ;
14881529
@@ -1650,8 +1691,14 @@ sailfishc::parsePrimary()
16501691
16511692 if (methodAccessName == " " ||
16521693 (methodAccessName != " " && type != " void" ))
1653- // if (!udttable->hasUDT(symboltable->getSymbolType(type)))
1654- targetBuffer += builtinTypesTranslator (type);
1694+ if ((currentToken->kind != TokenKind::TRIPLE_DOT) &&
1695+ (currentToken->kind != TokenKind::DOT))
1696+ {
1697+ if (udttable->hasUDT (type))
1698+ targetBuffer += " struct " + type + " *" ;
1699+ else
1700+ targetBuffer += builtinTypesTranslator (type);
1701+ }
16551702
16561703 return type;
16571704 }
0 commit comments