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

Use the ast edge label when building the ast node label #688

Merged
merged 1 commit into from
Nov 23, 2020

Conversation

aeisenberg
Copy link
Contributor

The C PrintAST library now includes the edge name in the AST Viewer
tree.

Resolves #687

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [n/a] @github/docs-content-dsp has been cc'd in all issues for UI or other user-facing changes made by this pull request.

Copy link
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

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

Generally looks good, but some questions for added clarity.

@@ -10,6 +10,7 @@
- Whenever the extension restarts, orphaned databases will be cleaned up. These are databases whose files are located inside of the extension's storage area, but are not imported into the workspace.
- After renaming a database, the database list is re-sorted. [#685](https://github.com/github/vscode-codeql/pull/685)
- Add a `codeQl.resultsDisplay.pageSize` setting to configure the number of results displayed in a single results view page. Increase the default page size from 100 to 200. [#686](https://github.com/github/vscode-codeql/pull/686)
- Update the AST Viewer so that edge names are included in each node label. So far, only C/C++ databases take advantage of this change. [#688](https://github.com/github/vscode-codeql/pull/688)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Update the AST Viewer so that edge names are included in each node label. So far, only C/C++ databases take advantage of this change. [#688](https://github.com/github/vscode-codeql/pull/688)
- Update the AST Viewer to include edge labels (if available) in addition to the target node labels. So far, only C/C++ databases take advantage of this change. [#688](https://github.com/github/vscode-codeql/pull/688)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -45,17 +45,18 @@ export default class AstBuilder {
const parentToChildren = new Map<BqrsId, BqrsId[]>();
const childToParent = new Map<BqrsId, BqrsId>();
const astOrder = new Map<BqrsId, number>();
const tupleTargetLabels = new Map<BqrsId, string>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Something like edgeLabels would make the purpose clearer. Please also add a comment explaining that this is a map from the target node ID to the edge label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@@ -65,6 +66,11 @@ export default class AstBuilder {
parentToChildren.set(sourceId, children = []);
}
children.push(targetId);

// ignore values that indicate a numeric order.
if (!Number.isFinite(Number(value))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're in the semmle.label case rather than semmle.order, isn't it reasonable to accept a number as the edge label?

Copy link
Contributor Author

@aeisenberg aeisenberg Nov 23, 2020

Choose a reason for hiding this comment

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

When you get to line 71, you are always looking at semmle.label since this is a switch statement.

If we accept a number as an edge label here, then we get confusing labels in the nodes of the ast viewer tree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because the AST viewer already numbers children?

@@ -84,9 +90,10 @@ export default class AstBuilder {
break;

case 'semmle.label': {
const label = [tupleTargetLabels.get(id), value ?? entity.label].filter(e => e).join(': ');
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever, but took me a minute. Comment to explain what it's doing, in particular that the UI will show the edge label (if available) and then the target node label? Or pull out edgeLabel and nodeLabel variables to make it clear what the individual values are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can clarify that a bit.

The C PrintAST library now includes the edge name in the AST Viewer
tree.
Copy link
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

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

One outstanding question so I can understand why we can't have numbers directly as edge labels, otherwise good to go!

@aeisenberg
Copy link
Contributor Author

Displaying numbers as the edge labels is redundant with the order and doesn't add any extra information. When I tried it out, the labels were cluttered.

@aeisenberg aeisenberg merged commit 579df25 into github:main Nov 23, 2020
@aeisenberg aeisenberg deleted the aeisenberg/ast-label branch November 24, 2020 22:30
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.

Use the edge label when building the AST tree
2 participants