-
Notifications
You must be signed in to change notification settings - Fork 106
[k2] add support argc/argv superglobals in k2-cli #1295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
} else if (letter == '"') { | ||
in_quote = !in_quote; | ||
} else if (letter == '\'') { | ||
10000 | php_warning("in command line arg supported only \" quote"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you added an extra space \" quote"
@@ -65,6 +65,14 @@ void StaticInit::compile(CodeGenerator &W) const { | |||
W << END << NL << NL; | |||
} | |||
|
|||
if (G->is_output_mode_k2()) { | |||
W << "namespace kphp::compiler_interface {" << NL; | |||
FunctionSignatureGenerator(W) << ("std::string_view get_main_file_name() ") << BEGIN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make this function constexpr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang++
gives error with message that inline function ... is not defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, considering using -
instead of _
in file names
@@ -43,6 +44,7 @@ struct ComponentState final : private vk::not_copyable { | |||
|
|||
private: | |||
static constexpr std::string_view INI_ARG_PREFIX = "ini "; | |||
static constexpr std::string_view COMMAND_LINE_ARG = "command-line"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's define it as CLI_ARG = "cli"
@@ -19,6 +19,7 @@ struct ComponentState final : private vk::not_copyable { | |||
const uint32_t argc; | |||
const uint32_t envc; | |||
mixed runtime_config; | |||
array<string> command_line_argv; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli_argv
@@ -54,6 +56,40 @@ void ComponentState::parse_runtime_config_arg(std::string_view value_view) noexc | |||
} | |||
} | |||
|
|||
void ComponentState::parse_command_line_arg(std::string_view value_view) noexcept { | |||
if (value_view.empty()) [[unlikely]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to have warning
here
return; | ||
} | ||
|
||
if (!command_line_argv.empty()) [[unlikely]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be placed at the top of the function
} | ||
|
||
if (!command_line_argv.empty()) [[unlikely]] { | ||
php_warning("command line argument support no more one usage"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird message, I'd suggest multiple command line arguments strings specified. skipping
or something similar
return; | ||
} | ||
|
||
const auto& main_file_view{kphp::compiler_interface::get_main_file_name()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think reference is redundant here
command_line_argv.push_back(string(main_file_view.data(), main_file_view.size())); | ||
|
||
bool in_quote{}; | ||
string current_arg{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like an error. You need to set special reference counter for each reference counted object
|
||
bool in_quote{}; | ||
string current_arg{}; | ||
for (char letter : value_view) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not actually letter
since there might be other symbols
bool in_quote{}; | ||
string current_arg{}; | ||
for (char letter : value_view) { | ||
if (std::isspace(letter) && !in_quote && !current_arg.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks overcomplicated. Let's use standard string view functions instead
No description provided.