本文整理汇总了C++中VirtualMachine::setFunctionParameter方法的典型用法代码示例。如果您正苦于以下问题:C++ VirtualMachine::setFunctionParameter方法的具体用法?C++ VirtualMachine::setFunctionParameter怎么用?C++ VirtualMachine::setFunctionParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine::setFunctionParameter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void GetFromValueCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node)
{
auto supergeheimeToken = node.getToken();
vector<string>& parameters = node.getContentArrayNonConstant();
string rValue = vm.getReturnValue();
IToken rToken = vm.getReturnToken();
if (&rValue != nullptr)
{
vm.setReturnValue("");
vm.setReturnToken(IToken::ANY);
if (vm.isAnIdentifier(rValue))
{
if (!vm.hasValueInFunctionParameters(parameters[1]))
{
vector<string> value = vm.getFunctionParametersByValue(rValue);
if (value.size() > 0)
{
vm.setVariable(parameters[1], vm.getVariable(value.back())->getValue(), supergeheimeToken, rToken);
}
else
{
// Exception var undefined
vm.setVariable(parameters[1], "", supergeheimeToken, rToken);
}
vm.setFunctionParameter(parameters[1], rValue);
}
}
else
{
vm.setVariable(parameters[1], rValue, supergeheimeToken, rToken);
}
}
}
示例2: execute
void GetAllFilesInDirectoryCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node)
{
auto supergeheimeToken = node.getToken();
vector<string>& parameters = node.getContentArrayNonConstant();
auto var = vm.getVariable(parameters[1]);
string extension = "*.*";
vector<string> out;
DIR* dir = nullptr;
struct dirent* dirent = nullptr;
string directory = var->getValue();
directory = directory.substr(1, directory.size() - 2);
dir = opendir(directory.c_str()); // Target directory
if (dir == nullptr)
{
//throwTypeError(*var, *var, vm);
//dir is null dir not found
throwCustomError("Directory not found! Cannot get all files in directory..", vm, supergeheimeToken);
return;
}
while (dir)
{
dirent = readdir(dir);
if (!dirent)
{
break;
}
string direct = dirent->d_name;
direct = directory + "\\" + direct;
DIR* temp = opendir(direct.c_str());
if (!temp)
{
string fileName = dirent->d_name;
out.push_back("\"" + fileName + "\"");
}
closedir(temp);
}
closedir(dir);
string buffer;
CompileSingleStatement varGetter = CompileSingleStatement();
string localVariable;
string arrayDictionary = varGetter.getNextLocalVariableName(buffer);
string arrayIdentifier = varGetter.getNextLocalVariableName(buffer);
vm.setVariable(arrayDictionary, "", supergeheimeToken, IToken::TYPE_TEXT_ARRAY);
shared_ptr<Variable> arrayVar = vm.getVariable(arrayDictionary);
vm.setFunctionParameter(arrayDictionary, arrayIdentifier);
int Size = out.size();
vm.addArrayToDictionary(arrayDictionary, vector<int>({ Size }));
vm.addIdentifer(arrayIdentifier);
for (size_t i = 0; i < out.size(); i++)
{
localVariable = varGetter.getNextLocalVariableName(buffer);
vm.setVariable(localVariable, out.at(i), supergeheimeToken, IToken::TYPE_TEXT);
vm.addItemToVariableArrayAt(arrayDictionary, vector<string>({ to_string(i) }), vm.getVariable(localVariable));
}
vm.setReturnValue(arrayIdentifier);
vm.setReturnToken(IToken::TYPE_TEXT_ARRAY);
}
示例3: execute
void GetFilesInDirectoryByExtensionCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node)
{
auto supergeheimeToken = node.getToken();
// TODO: DO EXTENSION STUFF
vector<string>& parameters = node.getContentArrayNonConstant();
auto var = vm.getVariable(parameters[1]);
string extension = ".cpp";
vector<string> out;
DIR* dir;
struct dirent* de;
string directory = var->getValue();
directory = directory.substr(1, directory.size() - 2);
dir = opendir(directory.c_str()); /*your directory*/
if (dir == nullptr)
{
//dir is null dir not found
throwCustomError("Directory not found! Cannot get files by extension..", vm, supergeheimeToken);
return;
}
while (dir)
{
de = readdir(dir);
if (!de)
{
break;
}
if (getExtension(de->d_name) == extension)
{
out.push_back(de->d_name);
}
}
closedir(dir);
string buffer;
CompileSingleStatement varGetter = CompileSingleStatement();
string localVariable;
string arrayDictionary = varGetter.getNextLocalVariableName(buffer);
string arrayIdentifier = varGetter.getNextLocalVariableName(buffer);
vm.setVariable(arrayDictionary, "", supergeheimeToken, IToken::TYPE_TEXT_ARRAY);
auto arrayVar = vm.getVariable(arrayDictionary);
vm.setFunctionParameter(arrayDictionary, arrayIdentifier);
int size = out.size();
vm.addArrayToDictionary(arrayDictionary, vector<int>({size}));
vm.addIdentifer(arrayIdentifier);
for (size_t i = 0; i < out.size(); i++)
{
localVariable = varGetter.getNextLocalVariableName(buffer);
vm.setVariable(localVariable, out.at(i), supergeheimeToken, IToken::TYPE_TEXT);
cout << out.at(i) << endl;
vm.addItemToVariableArrayAt(arrayDictionary, vector<string>({ to_string(i) }), vm.getVariable(localVariable));
}
vm.setReturnValue(arrayIdentifier);
vm.setReturnToken(IToken::TYPE_TEXT_ARRAY);
}