MCPcopy Create free account
hub / github.com/WheretIB/nullc / ParseArray

Function ParseArray

NULLC/Parser.cpp:1763–1815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1761}
1762
1763bool ParseArray(Lexeme** str)
1764{
1765 if(!ParseLexem(str, lex_ofigure))
1766 return false;
1767
1768 if((*str)->type == lex_for)
1769 {
1770 // coroutine auto(){
1771 BeginCoroutine();
1772 SelectTypeByPointer(NULL);
1773
1774 static int generatorFuncCount = 0;
1775 char *functionName = (char*)stringPool.Allocate(16);
1776 sprintf(functionName, "$genl%d", generatorFuncCount);
1777 generatorFuncCount++;
1778 FunctionAdd((*str)->pos, functionName);
1779 FunctionStart((*str)->pos);
1780 ParseCode(str);
1781 AddGeneratorReturnData((*str)->pos);
1782 TypeInfo *retType = GetSelectedType();
1783 AddReturnNode((*str)->pos);
1784 AddTwoExpressionNode();
1785
1786 FunctionEnd((*str)->pos);
1787
1788 if(!AddFunctionCallNode((*str)->pos, "$gen_list", 1, true))
1789 {
1790 // cannot find generator, create new
1791 NodeZeroOP *last = CodeInfo::nodeList.back();
1792 CodeInfo::nodeList.pop_back();
1793 AddListGenerator((*str)->pos, retType);
1794 CodeInfo::nodeList.push_back(last);
1795 AddFunctionCallNode((*str)->pos, "$gen_list", 1);
1796 AddTwoExpressionNode(CodeInfo::GetArrayType((TypeInfo*)retType, TypeInfo::UNSIZED_ARRAY));
1797 }
1798
1799 }else{
1800 unsigned int arrElementCount = 0;
1801 if(!ParseTernaryExpr(str))
1802 ThrowError((*str)->pos, "ERROR: value not found after '{'");
1803 while(ParseLexem(str, lex_comma))
1804 {
1805 if(!ParseTernaryExpr(str))
1806 ThrowError((*str)->pos, "ERROR: value not found after ','");
1807 arrElementCount++;
1808 }
1809 AddArrayConstructor((*str)->pos, arrElementCount);
1810 }
1811 if(!ParseLexem(str, lex_cfigure))
1812 ThrowError((*str)->pos, "ERROR: '}' not found after inline array");
1813
1814 return true;
1815}
1816
1817bool ParseVariable(Lexeme** str, bool *lastIsFunctionCall = NULL)
1818{

Callers 1

ParseTerminalFunction · 0.85

Calls 15

ParseLexemFunction · 0.85
BeginCoroutineFunction · 0.85
SelectTypeByPointerFunction · 0.85
FunctionAddFunction · 0.85
FunctionStartFunction · 0.85
ParseCodeFunction · 0.85
AddGeneratorReturnDataFunction · 0.85
GetSelectedTypeFunction · 0.85
AddReturnNodeFunction · 0.85
AddTwoExpressionNodeFunction · 0.85
FunctionEndFunction · 0.85
AddFunctionCallNodeFunction · 0.85

Tested by

no test coverage detected