MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / AddImportedName

Method AddImportedName

lib/validator/component_context.cpp:91–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91bool ComponentContext::Context::AddImportedName(
92 const ComponentName &Name) noexcept {
93 switch (Name.getKind()) {
94 case ComponentNameKind::Constructor:
95 case ComponentNameKind::Method:
96 case ComponentNameKind::Static:
97 case ComponentNameKind::InterfaceType:
98 case ComponentNameKind::Label:
99 case ComponentNameKind::LockedDep:
100 case ComponentNameKind::UnlockedDep:
101 case ComponentNameKind::Url:
102 case ComponentNameKind::Integrity:
103 break;
104 default:
105 return false;
106 }
107
108 auto toLowerString = [](std::string_view SV) {
109 std::string Result = std::string(SV);
110 std::transform(
111 Result.begin(), Result.end(), Result.begin(),
112 [](unsigned char C) { return static_cast<char>(std::tolower(C)); });
113 return Result;
114 };
115
116 // Handle the Constructor case separately.
117 if (Name.getKind() == ComponentNameKind::Constructor) {
118 std::string LowerCase = toLowerString(Name.getOriginalName());
119 std::string Label = std::string(Name.getNoTagName());
120 // Check for conflicts with existing constructors.
121 if (ImportedNames.count(LowerCase)) {
122 return false;
123 }
124
125 if (ImportedNames.count(toLowerString(Label))) {
126 if (!ImportedNames.count(Label)) {
127 return false;
128 }
129 // By rule, a constructor [constructor]X and X are strongly-unique.
130 // If X and its lower-case x form both exist, it means x comes from X.
131 }
132 ImportedNames.insert(LowerCase);
133 ImportedNames.insert(std::string(Name.getOriginalName()));
134 return true;
135 }
136
137 // For case 2, L and L.L are not strongly-unique together.
138 std::string Normal = std::string(Name.getNoTagName());
139 std::string UniForm = toLowerString(Normal);
140 std::string LdL =
141 std::string(Name.getNoTagName()) + "." + std::string(Name.getNoTagName());
142
143 if (ImportedNames.count(LdL)) {
144 return false;
145 }
146
147 if (Normal.find('.') != std::string::npos) {
148 std::string Left, Right;

Callers 2

TESTFunction · 0.80
addImportedNameMethod · 0.80

Calls 10

tolowerFunction · 0.85
getKindMethod · 0.80
getOriginalNameMethod · 0.80
getNoTagNameMethod · 0.80
countMethod · 0.80
insertMethod · 0.80
substrMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by 1

TESTFunction · 0.64