Skip to content
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

Add support for arbitrary expressions as default values in documentation #1323

Closed
wants to merge 4 commits into from

Conversation

malthe
Copy link
Contributor

@malthe malthe commented Oct 15, 2016

This fixes an issue where a recover-expression would get printed
as simply "recover", leaving out both the actual expression as well
as the "end" token.

The doc_expression function writes out an expression provided
as an AST node to the provided document.

This closes #1262.

@malthe
Copy link
Contributor Author

malthe commented Oct 15, 2016

This is somewhat preliminary and incomplete, but it does cover the situation stated in the issue. I wanted to at least get some feedback if this is the right approach.

@SeanTAllen
Copy link
Member

@malthe are you saying this shouldn't be merged?

@SeanTAllen
Copy link
Member

@malthe are far more descriptive commit message would be desired: "closes X" isnt particularly helpful. The summation of the problem solved should be included in the commit comment. GH issues can go away, the commit comment will live on. Can you amend to include a full description of the problem and the approach taken to resolve?

switch(token_get_id(ast->t))
{
case TK_STRING:
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats up with the {}'s around this case statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK you can't define a symbol in a case statement without wrapping in curly braces.

{
char* escaped = token_print_escaped(ast->t);
size_t len = strlen(escaped);
char* s = (char*)ponyint_pool_alloc_size(len + 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its been a bit since i worked with this stuff, but i believe this needs to be freed somewhere.

@@ -548,6 +548,82 @@ static void doc_type_params(docgen_t* docgen, ast_t* t_params,
fprintf(docgen->type_file, "]");
}

// Write the expression to the current type file.
void doc_fprint(docgen_t* docgen, ast_t* ast)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why fprint as a name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me from doc_fprint, its certainly not clear that this is writing out an expression.

@SeanTAllen
Copy link
Member

What does the output expression look like if this is used?

@malthe
Copy link
Contributor Author

malthe commented Oct 15, 2016

The output now looks like this:

new val create(
  base: (FilePath val | AmbientAuth val),
  path': String val,
  caps': Flags[(FileCreate val | FileChmod val | FileChown val | 
    FileLink val | FileLookup val | FileMkdir val | 
    FileRead val | FileRemove val | FileRename val | 
    FileSeek val | FileStat val | FileSync val | 
    FileTime val | FileTruncate val | FileWrite val | 
    FileExec val), U32 val] val = recover val FileCaps.all() end)
: FilePath val^ ?

The interesting bit here being the recover default value expression.

I think this pull request can be considered for merging into the main tree with the caveat that the implementation is not complete in the sense that not all expressions are correctly printed.

@malthe malthe changed the title Support for writing out expressions in documentation Add support for arbitrary expressions as default values in documentation Oct 15, 2016
fprintf(fp, "recover");
while(child != NULL)
{
if (ast_id(child) != TK_NONE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard pony c style formatting for this is something like

if(docgen.index_file != NULL && docgen.home_file != NULL) {

{
char* escaped = token_print_escaped(token);
size_t len = strlen(escaped);
char* s = (char*)ponyint_pool_alloc_size(len + 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does this get freed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets freed in token_free because we assign it to token->printed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this leak the previous token->printed if one was assigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's better to use the same semantics as token_print_escaped where the caller must free it explicitly.

@SeanTAllen
Copy link
Member

@malthe this is segfaulting now.

@malthe malthe force-pushed the issue-1262 branch 4 times, most recently from 8b39db2 to 94aaf6a Compare October 15, 2016 21:12
@malthe
Copy link
Contributor Author

malthe commented Oct 16, 2016

It seems like net/TCP.expect still fails every once in a while.

@@ -219,7 +219,6 @@ char* token_print_escaped(token_t* token)
return escaped;
}


Copy link
Member

@SeanTAllen SeanTAllen Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this line removed? i assume it was a mistake and should be added back in.

{
doc_expression(docgen, child);
child = ast_sibling(child);
if (child != NULL) {
Copy link
Member

@SeanTAllen SeanTAllen Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard ponyc still is for npo {}'s when its a single line after the if

additionally, no space between the if and the (child != NULL) is the standard style so

if(child!=NULL)

{
doc_expression(docgen, child);
child = ast_sibling(child);
if (child != NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard ponyc style is for no braces with a single line if

additionally, no space between the if and the (child != NULL) is the standard style so

if(child!=NULL)

doc_type(docgen, ast, false);
break;

case TK_DOT:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be combined with TK_SEQ and TK_CALL and others that are the same no? There's a slight variance in character that would have to be handled but there's a ton of duplication and it would be easy to introduce bugs in this.

fprintf(fp, "recover");
while(child != NULL)
{
if (ast_id(child) != TK_NONE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like the wrong way to tackle this.

there could be other types later that we would be special casing for. that said, i dont immediately have an idea for a better way to address.

while(child != NULL)
{
doc_expression(docgen, child);
child = ast_sibling(child);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this not have the NULL check logic that others do?

@SeanTAllen SeanTAllen force-pushed the master branch 6 times, most recently from 97b1943 to 21d37aa Compare March 11, 2017 14:51
This fixes an issue where a recover-expression would get printed
as simply "recover", leaving out both the actual expression as well
as the "end" token.

The `doc_expression` function writes out an expression provided
as an AST node to the provided document.
}
}
if (token == TK_CALL)
fprintf(fp, "()");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are call arguments handled?

@mfelsche
Copy link
Contributor

Afaik this does not handle any control structures, like if or loops or try statements. Are these in the scope of this PR?

@malthe
Copy link
Contributor Author

malthe commented Sep 26, 2018

@mfelsche I am not sure what the scope should be – the primary concern is to correctly print the expressions that appear in the standard library code as "default expression". I don't think there are any calls with arguments or control structures in there.

@SeanTAllen
Copy link
Member

Closing as stale.

@SeanTAllen SeanTAllen closed this Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid documentation generated
4 participants