-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Conversation
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. |
@malthe are you saying this shouldn't be merged? |
@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? |
src/libponyc/ast/ast.c
Outdated
switch(token_get_id(ast->t)) | ||
{ | ||
case TK_STRING: | ||
{ |
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.
whats up with the {}'s around this case statement?
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.
AFAIK you can't define a symbol in a case statement without wrapping in curly braces.
src/libponyc/ast/ast.c
Outdated
{ | ||
char* escaped = token_print_escaped(ast->t); | ||
size_t len = strlen(escaped); | ||
char* s = (char*)ponyint_pool_alloc_size(len + 3); |
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.
its been a bit since i worked with this stuff, but i believe this needs to be freed somewhere.
src/libponyc/pass/docgen.c
Outdated
@@ -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) |
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.
why fprint as a 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.
to me from doc_fprint, its certainly not clear that this is writing out an expression.
What does the output expression look like if this is used? |
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 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. |
src/libponyc/pass/docgen.c
Outdated
fprintf(fp, "recover"); | ||
while(child != NULL) | ||
{ | ||
if (ast_id(child) != TK_NONE) { |
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.
standard pony c style formatting for this is something like
if(docgen.index_file != NULL && docgen.home_file != NULL) {
src/libponyc/ast/token.c
Outdated
{ | ||
char* escaped = token_print_escaped(token); | ||
size_t len = strlen(escaped); | ||
char* s = (char*)ponyint_pool_alloc_size(len + 3); |
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.
where does this get freed?
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 gets freed in token_free
because we assign it to token->printed
.
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.
Won't this leak the previous token->printed
if one was assigned?
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.
Perhaps it's better to use the same semantics as token_print_escaped
where the caller must free it explicitly.
@malthe this is segfaulting now. |
8b39db2
to
94aaf6a
Compare
It seems like |
src/libponyc/ast/token.c
Outdated
@@ -219,7 +219,6 @@ char* token_print_escaped(token_t* token) | |||
return escaped; | |||
} | |||
|
|||
|
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.
why was this line removed? i assume it was a mistake and should be added back in.
src/libponyc/pass/docgen.c
Outdated
{ | ||
doc_expression(docgen, child); | ||
child = ast_sibling(child); | ||
if (child != NULL) { |
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.
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)
src/libponyc/pass/docgen.c
Outdated
{ | ||
doc_expression(docgen, child); | ||
child = ast_sibling(child); | ||
if (child != NULL) { |
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.
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)
src/libponyc/pass/docgen.c
Outdated
doc_type(docgen, ast, false); | ||
break; | ||
|
||
case TK_DOT: |
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 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) { |
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 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.
src/libponyc/pass/docgen.c
Outdated
while(child != NULL) | ||
{ | ||
doc_expression(docgen, child); | ||
child = ast_sibling(child); |
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.
why does this not have the NULL check logic that others do?
97b1943
to
21d37aa
Compare
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, "()"); |
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.
Where are call arguments handled?
Afaik this does not handle any control structures, like |
@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. |
Closing as stale. |
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 providedas an AST node to the provided document.
This closes #1262.