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

Function AddListGenerator

NULLC/Callbacks.cpp:5366–5443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5364};
5365
5366void AddListGenerator(const char* pos, TypeInfo *rType)
5367{
5368//typedef int generic;
5369 TypeInfo *retType = rType;
5370
5371 currType = CodeInfo::GetArrayType(retType, TypeInfo::UNSIZED_ARRAY);
5372
5373//generic[] gen_list(generic ref() y)
5374 char *functionName = AllocateString(16);
5375 sprintf(functionName, "$gen_list");
5376 FunctionAdd(pos, functionName);
5377
5378 TypeHandler* h = NULL;
5379 SelectTypeByPointer(CodeInfo::GetFunctionType(retType, h, 0));
5380 FunctionParameter(pos, InplaceStr("y"));
5381 FunctionStart(pos);
5382
5383// auto[] res = auto_array(generic, 1);
5384 currType = typeAutoArray;
5385 VariableInfo *varInfo = AddVariable(pos, InplaceStr("res"));
5386 currType = retType;
5387 GetTypeId(pos);
5388 CodeInfo::nodeList.push_back(new NodeNumber(1, typeInt));
5389 AddFunctionCallNode(pos, "auto_array", 2);
5390 AddDefineVariableNode(pos, varInfo);
5391 AddPopNode(pos);
5392// int pos = 0;
5393 currType = typeInt;
5394 varInfo = AddVariable(pos, InplaceStr("pos"));
5395 CodeInfo::nodeList.push_back(new NodeNumber(0, typeInt));
5396 AddDefineVariableNode(pos, varInfo);
5397 AddPopNode(pos);
5398
5399// for(x in y)
5400 IncreaseCycleDepth();
5401 BeginBlock();
5402
5403 AddGetAddressNode(pos, InplaceStr("y"));
5404 AddGetVariableNode(pos);
5405 AddArrayIterator("x", InplaceStr("x"), NULL);
5406
5407// res.set(x, pos++);
5408 AddGetAddressNode(pos, InplaceStr("res"));
5409 AddGetAddressNode(pos, InplaceStr("x"));
5410 AddGetAddressNode(pos, InplaceStr("pos"));
5411 AddUnaryModifyOpNode(pos, OP_INCREMENT, OP_POSTFIX);
5412 AddMemberFunctionCall(pos, "set", 2);
5413 AddPopNode(pos);
5414
5415 EndBlock();
5416 AddForEachNode(pos);
5417
5418// __force_size(&res, pos);
5419 AddGetAddressNode(pos, InplaceStr("res"));
5420 AddGetAddressNode(pos, InplaceStr("pos"));
5421 AddGetVariableNode(pos);
5422 AddFunctionCallNode(pos, "__force_size", 2);
5423 AddPopNode(pos);

Callers 1

ParseArrayFunction · 0.85

Calls 15

AllocateStringFunction · 0.85
FunctionAddFunction · 0.85
SelectTypeByPointerFunction · 0.85
GetFunctionTypeFunction · 0.85
FunctionParameterFunction · 0.85
InplaceStrClass · 0.85
FunctionStartFunction · 0.85
AddVariableFunction · 0.85
GetTypeIdFunction · 0.85
AddFunctionCallNodeFunction · 0.85
AddDefineVariableNodeFunction · 0.85
AddPopNodeFunction · 0.85

Tested by

no test coverage detected