aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-01-13 11:54:25 +0000
committergingerBill <bill@gingerbill.org>2019-01-13 11:54:25 +0000
commit3363e2c1994face8a51677d430df60862bd9b99c (patch)
tree93ad4fb6a2a28e76066eb9ba86bbf562ce479e3c /src
parentcf94d1735d6ff84269e08afbdeb8744fd05be473 (diff)
Change import name determination rules
Use custom name if given, then directory name, then the package name
Diffstat (limited to 'src')
-rw-r--r--src/checker.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index a3b912e6f..388c71689 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -2631,7 +2631,7 @@ bool is_string_an_identifier(String s) {
return offset == s.len;
}
-String path_to_entity_name(String name, String fullpath) {
+String path_to_entity_name(String name, String fullpath, bool strip_extension=true) {
if (name.len != 0) {
return name;
}
@@ -2650,16 +2650,18 @@ String path_to_entity_name(String name, String fullpath) {
filename = substring(filename, slash, filename.len);
- dot = filename.len;
- while (dot --> 0) {
- u8 c = filename[dot];
- if (c == '.') {
- break;
+ if (strip_extension) {
+ dot = filename.len;
+ while (dot --> 0) {
+ u8 c = filename[dot];
+ if (c == '.') {
+ break;
+ }
}
- }
- if (dot > 0) {
- filename = substring(filename, 0, dot);
+ if (dot > 0) {
+ filename = substring(filename, 0, dot);
+ }
}
if (is_string_an_identifier(filename)) {
@@ -2884,8 +2886,8 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) {
ptr_set_add(&parent_scope->imported, scope);
}
-
- String import_name = id->import_name.string;
+ String import_name = path_to_entity_name(id->import_name.string, id->fullpath, false);
+ // String import_name = id->import_name.string;
if (import_name.len == 0) {
import_name = scope->pkg->name;
}