string keywordReturn(MavenCompiler* c, string line) { // we have to be in a function to use this if(c->currentFunction == "") { pushError(c, "Can not return out of non-function"); return MAVEN_INVALID; } // it could be a void return if(line.length() == 6) return "return"; StringList types; MavenMutability mut; string newCode = dissectCode(c, line.substr(7, line.length() - 7), types, mut); // check the return type matches the function its in int nID = findNamespaceID(c, c->currentNamespace); smartAssert(nID >= 0); int oID = findObjectID(c, nID, c->currentClass); smartAssert(oID >= 0); for(int i = 0; i < c->namespaces->at(nID).objects->at(oID)->functions->length(); ++i) { if(c->namespaces->at(nID).objects->at(oID)->functions->at(i).name == c->currentFunction) { if(canCastBetween(c, types.join(","), c->namespaces->at(nID).objects->at(oID)->functions->at(i).returnType)) { return "return " + newCode; } else { pushError(c, "Can not cast return type %s to %s", types.join(","), c->namespaces->at(nID).objects->at(oID)->functions->at(i).returnType); return MAVEN_INVALID; } } } // if it gets to here something really bad has gone wrong return MAVEN_INVALID; }
string unresolveMavenPath(MavenCompiler* c, string path) { // remove "$static", "->a", spaces and brackets while(path.find("$static") != string::npos) path = path.erase(path.find("$static"), strlen("$static")); while(path.find("->a") != string::npos) path = path.erase(path.find("->a"), strlen("->a")); while(path.find(" ") != string::npos) path = path.erase(path.find(" "), strlen(" ")); while(path.find("(") != string::npos) path = path.erase(path.find("("), strlen("(")); while(path.find(")") != string::npos) path = path.erase(path.find(")"), strlen(")")); // finalise StringList parts = split("::", path); return parts.join("."); }
Path& Path::normalize() { StringTokenizer tokenizer(_path); tokenizer.onCharset("/"); std::string elem; StringList parts; while(tokenizer.next(elem)) { if(elem == ".." && ! parts.empty()) parts.pop(); else if(elem != ".") parts << elem; } _path = parts.join('/'); return *this; }
String HaxeMessageSyntax::readValue(String message, Ref<Token> token) { if (token->firstChild()) { StringList list; Ref<Token> child = token->firstChild(); int i = token->i0(); while (child) { if (i < child->i0()) list.append(message->copy(i, child->i0())); String s; if (child->keyword() == gt_) s = ">"; else if (child->keyword() == lt_) s = "<"; else s = message->copy(child->i0(), child->i1()); list.append(s); i = child->i1(); child = child->nextSibling(); } if (i < token->i1()) list.append(message->copy(i, token->i1())); return list.join(); } else return message->copy(token->i0(), token->i1()); }