-
Notifications
You must be signed in to change notification settings - Fork 3
Solution to conditionally dump overrides #127
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
Open
amir734jj
wants to merge
11
commits into
boyland:master
Choose a base branch
from
amir734jj:user/amir734jj/codegen-override
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
602c29f
working solution to conditionally dump overrides
amir734jj cf3a08a
small updates
amir734jj c4a32a5
updated the code according to the feedback
amir734jj 843690c
visited stuff wan't needed
amir734jj da5f21e
set import wasn't needed
amir734jj 19041af
Merge remote-tracking branch 'boyland/master' into user/amir734jj/cod…
amir734jj de617ba
Fixed merge error and updated code according to feedback
amir734jj 23318b9
Improvement to handle different return type but same name which cause…
amir734jj 3cf1aa4
Merge remote-tracking branch 'origin/master' into user/amir734jj/code…
amir734jj 58c9b10
fix merge issue
amir734jj e38e051
Attempting to fix canonical types, instead of skipping Result argument
amir734jj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,10 +181,10 @@ void dump_formal(Declaration formal, ostream&os) | |
| if (KEYseq_formal == Declaration_KEY(formal)) os << "*"; | ||
| } | ||
|
|
||
| void dump_function_prototype(string name, Type ft, bool dump_anchor_actual, ostream& oss) | ||
| void dump_function_prototype(string name, Type ft, bool dump_anchor_actual, bool override_needed, ostream& oss) | ||
| { | ||
| oss << indent() << "val v_" << name << " = f_" << name << " _;\n"; | ||
| oss << indent() << "def f_" << name << "("; | ||
| oss << indent() << (override_needed ? "override " : "") << "val v_" << name << " = f_" << name << " _;\n"; | ||
| oss << indent() << (override_needed ? "override " : "") << "def f_" << name << "("; | ||
|
|
||
| bool started = false; | ||
| Declarations formals = function_type_formals(ft); | ||
|
|
@@ -1392,7 +1392,7 @@ static void dump_scala_pattern_function( | |
|
|
||
| if (!body) { | ||
| // the constructor function: | ||
| dump_function_prototype(name,ft,dump_anchor_actual,oss); | ||
| dump_function_prototype(name,ft,dump_anchor_actual,false /* override_needed */,oss); | ||
| oss << " = c_" << name << args; | ||
| if (is_syntax) oss << ".register"; | ||
| oss << ";\n"; | ||
|
|
@@ -1451,6 +1451,78 @@ void dump_scala_Declaration_header(Declaration decl, ostream& oss) | |
| } | ||
| } | ||
|
|
||
| // Recursive helper function to check given a surrounding declaration (module_decl, class_decl or type_decl) | ||
| // if it contains a function declaration that matches the given name and return type | ||
| // if true then override would be needed otherwise not needed | ||
| static void type_has_service_function(Declaration decl, Symbol fdecl_name, vector<Declaration>& found_decls) { | ||
| switch (Declaration_KEY(decl)) { | ||
| case KEYsome_type_decl: { | ||
| Type type = some_type_decl_type(decl); | ||
| switch (Type_KEY(type)) | ||
| { | ||
| case KEYno_type: { | ||
| bool is_phylum = Declaration_KEY(decl) == KEYphylum_decl; | ||
| return type_has_service_function(is_phylum ? module_PHYLUM : module_TYPE, fdecl_name, found_decls); | ||
| } | ||
| case KEYtype_use: | ||
| return type_has_service_function(canonical_type_decl(canonical_type(type)), fdecl_name, found_decls); | ||
| case KEYtype_inst: | ||
| return type_has_service_function(USE_DECL(module_use_use(type_inst_module(type))), fdecl_name, found_decls); | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| case KEYsome_class_decl: { | ||
| Block body = some_class_decl_contents(decl); | ||
| Declaration item; | ||
| for (item = first_Declaration(block_body(body)); item != NULL; item = DECL_NEXT(item)) { | ||
| switch (Declaration_KEY(item)) { | ||
| case KEYsome_function_decl: | ||
| if (def_name(some_function_decl_def(item)) == fdecl_name) { | ||
| found_decls.push_back(item); | ||
| } | ||
|
|
||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (decl == module_PHYLUM || decl == module_TYPE) { | ||
| return; | ||
| } else { | ||
| type_has_service_function(some_class_decl_result_type(decl), fdecl_name, found_decls); | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite. This should check the |
||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Declaration get_enclosing_some_class_decl(Declaration source) { | ||
| void* node = (void*)source; | ||
| while (node != NULL) { | ||
| switch (ABSTRACT_APS_tnode_phylum(node)) { | ||
| case KEYDeclaration: { | ||
| Declaration decl = (Declaration) node; | ||
| switch (Declaration_KEY(decl)) { | ||
| case KEYsome_class_decl: | ||
| return decl; | ||
| default: | ||
| break; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| node = tnode_parent(node); | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| void dump_scala_Declaration(Declaration decl,ostream& oss) | ||
| { | ||
| const char *name = 0; | ||
|
|
@@ -1922,7 +1994,44 @@ void dump_scala_Declaration(Declaration decl,ostream& oss) | |
| Type fty = function_decl_type(decl); | ||
| Declaration rdecl = first_Declaration(function_type_return_values(fty)); | ||
| Block b = function_decl_body(decl); | ||
| dump_function_prototype(name,fty,false /* dump_anchor_actual */,oss); | ||
| Declaration mdecl = get_enclosing_some_class_decl(decl); | ||
| bool override_needed = false; | ||
| if (mdecl != NULL) { | ||
| vector<Declaration> found_fdecls; | ||
| type_has_service_function(some_class_decl_result_type(mdecl), def_name(declaration_def(decl)), found_fdecls); | ||
|
|
||
| auto cftype2 = (struct Canonical_function_type *)canonical_type(fty); | ||
| // Result declaration of the current (implementing) module | ||
| Declaration current_result = some_class_decl_result_type(mdecl); | ||
| for (auto& found_fdecl : found_fdecls) { | ||
| auto cftype1 = (struct Canonical_function_type *)canonical_type(some_function_decl_type(found_fdecl)); | ||
| // Result declaration of the inherited (source) module | ||
| Declaration found_mdecl = get_enclosing_some_class_decl(found_fdecl); | ||
| Declaration ctype1_mdecl_result = found_mdecl ? some_class_decl_result_type(found_mdecl) : NULL; | ||
| if (cftype1->num_formals == cftype2->num_formals) { | ||
| bool formals_type_match = true; | ||
| for (int i = 0; i < cftype1->num_formals; ++i) { | ||
| if (canonical_type_compare2(cftype1->param_types[i], cftype2->param_types[i], | ||
| ctype1_mdecl_result, current_result) != 0) { | ||
| formals_type_match = false; | ||
| } | ||
| } | ||
|
|
||
| if (formals_type_match) { | ||
| if (canonical_type_compare2(cftype1->return_type, cftype2->return_type, | ||
| ctype1_mdecl_result, current_result) == 0) { | ||
| override_needed = true; | ||
| break; | ||
| } else { | ||
| aps_error(decl, "Function %s has same name as inherited function but different return type; overriding not possible since return types are incompatible", decl_name(decl)); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dump_function_prototype(name, fty, false /* dump_anchor_actual */, override_needed, oss); | ||
|
|
||
| // three kinds of definitions: | ||
| // 1. the whole thing: a non-empty body: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Interesting!
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.
These two global static variables were originally defined for canonical stuff. So I thought let's reuse them.