void reportProcedureInformation(Procedure *p, ReturnManner returnm, bool last, TypeContext tc){ ecCharToCharStack(p->name, nameString); printf("{"); printf("\"name\": \"%s\",", nameString); if (returnm == Return) { reportType("returnType", p->returnType, false, tc); } else if (returnm == CanReturnNothingness) { printf("\"canReturnNothingness\": true,"); } reportGenericArguments(p->genericArgumentVariables, p->genericArgumentConstraints, 0, tc); reportDocumentation(p->documentationToken); printf("\"arguments\": ["); for (int i = 0; i < p->arguments.size(); i++) { printf("{"); Variable variable = p->arguments[i]; const char *varname = variable.name->value.utf8CString(); reportType("type", variable.type, false, tc); printf("\"name\":"); printJSONStringToFile(varname, stdout); printf("}%s", i + 1 == p->arguments.size() ? "" : ","); delete [] varname; } printf("]"); printf("}%s", last ? "" : ","); }
static void parseGeneric (tokenInfo *const token, boolean declaration __unused__) { unsigned int depth = 0; #ifdef TYPE_REFERENCE_TOOL boolean constraint = FALSE; #endif Assert (isType (token, TOKEN_OPEN_BRACKET)); do { if (isType (token, TOKEN_OPEN_BRACKET)) ++depth; else if (isType (token, TOKEN_CLOSE_BRACKET)) --depth; #ifdef TYPE_REFERENCE_TOOL else if (declaration) { if (depth == 1) { if (isType (token, TOKEN_CONSTRAINT)) constraint = TRUE; else if (isKeyword (token, KEYWORD_create)) findKeyword (token, KEYWORD_end); else if (isType (token, TOKEN_IDENTIFIER)) { if (constraint) reportType (token); else addGenericName (token); constraint = FALSE; } } else if (isKeyword (token, KEYWORD_like)) readToken (token); else if (isType (token, TOKEN_IDENTIFIER)) reportType (token); } else { if (isType (token, TOKEN_OPEN_BRACKET)) ++depth; else if (isType (token, TOKEN_IDENTIFIER)) reportType (token); else if (isKeyword (token, KEYWORD_like)) readToken (token); } #endif readToken (token); } while (depth > 0); }
void reportGenericArguments(std::map<EmojicodeString, Type> map, std::vector<Type> constraints, size_t superCount, TypeContext tc) { printf("\"genericArguments\": ["); auto gans = std::vector<EmojicodeString>(map.size()); for (auto it : map) { gans[it.second.reference - superCount] = it.first; } auto reported = false; for (size_t i = 0; i < gans.size(); i++) { auto gan = gans[i]; auto utf8 = gan.utf8CString(); if (reported) { printf(","); } printf("{\"name\": "); printJSONStringToFile(utf8, stdout); printf(","); reportType("constraint", constraints[i], true, tc); printf("}%s", i + 1 == gans.size() ? "" : ","); delete [] utf8; reported = true; } printf("],"); }
static const type* analyzerDeclIdentLiteral (analyzerCtx* ctx, ast* Node, type* base, bool module, storageTag storage) { bool fn = typeIsFunction(base); /*The storage tag defaults to: - extern if the symbol is a function, - static if a module level variable, - auto otherwise, But an explicit storage specifier overrides all.*/ Node->storage = storage ? storage : fn ? storageExtern : module ? storageStatic : storageAuto; if (Node->symbol) { if (Node->symbol->tag == symId && !Node->symbol->storage) { /*Assign the storage tag*/ Node->symbol->storage = Node->storage; } if ( Node->symbol->tag == symId || Node->symbol->tag == symParam || Node->symbol->tag == symEnumConstant || Node->symbol->tag == symTypedef) { /*Assign the type*/ if (!Node->symbol->dt) Node->symbol->dt = base; /*Don't bother checking types if param Any conflicts will be reported by the function itself*/ else if (Node->symbol->tag == symParam) ; /*Not the first declaration of this symbol, check type matches*/ else if (!typeIsEqual(Node->symbol->dt, base)) errorConflictingDeclarations(ctx, Node, Node->symbol, base); /*Even if types match, not allowed to be redeclared if a variable*/ else if ( Node->symbol->tag == symId && !fn && Node->symbol->parent->tag != symStruct && Node->symbol->parent->tag != symUnion && Node->symbol->storage != storageExtern) errorRedeclared(ctx, Node, Node->symbol); reportSymbol(Node->symbol); } } else reportType(base); /*Take ownership of the base if unable to give it to a symbol*/ if (!Node->symbol || Node->symbol->dt != base) Node->dt = base; return base; }
static void parseType (tokenInfo *const token) { boolean bitType; Assert (isType (token, TOKEN_IDENTIFIER)); #ifdef TYPE_REFERENCE_TOOL reportType (token); #endif bitType = (boolean)(strcmp ("BIT", vStringValue (token->string)) == 0); readToken (token); if (bitType && isType (token, TOKEN_NUMERIC)) readToken (token); else if (isType (token, TOKEN_OPEN_BRACKET)) parseGeneric (token, FALSE); }
void TaskExport::writeTo( const QString& filename, const TaskList& tasks ) { QDomDocument document = XmlSerialization::createXmlTemplate( reportType() ); QDomElement metadata = XmlSerialization::metadataElement( document ); QDomElement report = XmlSerialization::reportElement( document ); // write tasks { QDomElement tasksElement = Task::makeTasksElement( document, tasks ); report.appendChild( tasksElement ); } // all done, write to file: QFile file( filename ); if ( file.open( QIODevice::WriteOnly ) ) { QTextStream stream( &file ); document.save( stream, 4 ); } else { throw XmlSerializationException( QObject::tr( "Cannot write to file" ) ); } }
void TaskExport::readFrom( const QString& filename ) { // load the time sheet: QFile file( filename ); if ( !file.exists() ) { throw XmlSerializationException( QObject::tr( "File does not exist." ) ); } // load the XML into a DOM tree: if (!file.open(QIODevice::ReadOnly)) { throw XmlSerializationException( QObject::tr( "Cannot open file for reading." ) ); } QDomDocument document; if (!document.setContent(&file)) { throw XmlSerializationException( QObject::tr( "Cannot read file" ) ); } // now read and check for the correct report type QDomElement rootElement = document.documentElement(); const QString tagName = rootElement.tagName(); const QString typeAttribute = rootElement.attribute( XmlSerialization::reportTypeAttribute() ); if( tagName != XmlSerialization::reportTagName() || typeAttribute != reportType() ) { throw XmlSerializationException( QObject::tr( "This file is not a Charm task definition file. Please double-check." ) ); } QDomElement metadata = XmlSerialization::metadataElement( document ); QDomElement report = XmlSerialization::reportElement( document ); // from metadata, read the export time stamp: m_exportTime = XmlSerialization::creationTime( metadata ); m_userName = XmlSerialization::userName( metadata ); // from report, read tasks: QDomElement tasksElement = report.firstChildElement( Task::taskListTagName() ); m_tasks = Task::readTasksElement( tasksElement, CHARM_DATABASE_VERSION ); qDebug() << "XmlSerialization::readFrom: loaded task definitions exported by" << m_userName << "as of" << m_exportTime; }
static boolean parseType (tokenInfo *const token) { tokenInfo* const id = newToken (); copyToken (id, token); readToken (token); if (isType (token, TOKEN_COLON)) /* check for "{entity: TYPE}" */ { readToken (id); readToken (token); } if (isKeyword (id, KEYWORD_like)) { if (isType (token, TOKEN_IDENTIFIER) || isKeyword (token, KEYWORD_Current)) readToken (token); } else { if (isKeyword (id, KEYWORD_attached) || isKeyword (id, KEYWORD_detachable) || isKeyword (id, KEYWORD_expanded)) { copyToken (id, token); readToken (token); } if (isType (id, TOKEN_IDENTIFIER)) { #ifdef TYPE_REFERENCE_TOOL reportType (id); #endif if (isType (token, TOKEN_OPEN_BRACKET)) parseGeneric (token, FALSE); else if ((strcmp ("BIT", vStringValue (id->string)) == 0)) readToken (token); /* read token after number of bits */ } } deleteToken (id); return TRUE; }
void report(Package *package){ std::list<Enum *> enums; std::list<Class *> classes; std::list<Protocol *> protocols; for (auto exported : package->exportedTypes()) { switch (exported.type.type) { case TT_CLASS: classes.push_back(exported.type.eclass); break; case TT_ENUM: enums.push_back(exported.type.eenum); break; case TT_PROTOCOL: protocols.push_back(exported.type.protocol); break; default: break; } } bool printedClass = false; printf("{"); printf("\"classes\": ["); for(auto eclass : classes){ if (printedClass) { putchar(','); } printedClass = true; printf("{"); ecCharToCharStack(eclass->name, className); printf("\"name\": \"%s\",", className); reportGenericArguments(eclass->ownGenericArgumentVariables, eclass->genericArgumentConstraints, eclass->superGenericArguments.size(), TypeContext(eclass)); reportDocumentation(eclass->documentationToken); if (eclass->superclass) { ecCharToCharStack(eclass->superclass->name, superClassName); printf("\"superclass\": {\"package\": \"%s\", \"name\": \"%s\"},", eclass->superclass->package->name(), superClassName); } printf("\"methods\": ["); for(size_t i = 0; i < eclass->methodList.size(); i++){ Method *method = eclass->methodList[i]; reportProcedureInformation(method, Return, i + 1 == eclass->methodList.size(), TypeContext(eclass, method)); } printf("],"); printf("\"initializers\": ["); for(size_t i = 0; i < eclass->initializerList.size(); i++){ Initializer *initializer = eclass->initializerList[i]; reportProcedureInformation(initializer, initializer->canReturnNothingness ? CanReturnNothingness : NoReturn, i + 1 == eclass->initializerList.size(), TypeContext(eclass, initializer)); } printf("],"); printf("\"classMethods\": ["); for(size_t i = 0; i < eclass->classMethodList.size(); i++){ ClassMethod *classMethod = eclass->classMethodList[i]; reportProcedureInformation((Procedure *)classMethod, Return, eclass->classMethodList.size() == i + 1, TypeContext(eclass, classMethod)); } printf("],"); printf("\"conformsTo\": ["); for(size_t i = 0; i < eclass->protocols().size(); i++){ Protocol *protocol = eclass->protocols()[i]; reportType(nullptr, Type(protocol, false), i + 1 == eclass->protocols().size(), TypeContext(eclass)); } printf("]}"); } printf("],"); printf("\"enums\": ["); bool printedEnum = false; for(auto eenum : enums){ if (printedEnum) { putchar(','); } printf("{"); printedEnum = true; ecCharToCharStack(eenum->name, enumName); printf("\"name\": \"%s\",", enumName); reportDocumentation(eenum->documentationToken); bool printedValue = false; printf("\"values\": ["); for(auto it : eenum->map){ ecCharToCharStack(it.first, value); if (printedValue){ putchar(','); } printf("\"%s\"", value); printedValue = true; } printf("]}"); } printf("],"); printf("\"protocols\": ["); bool printedProtocol = false; for(auto protocol : protocols){ if (printedProtocol) { putchar(','); } printedProtocol = true; printf("{"); ecCharToCharStack(protocol->name, protocolName); printf("\"name\": \"%s\",", protocolName); reportDocumentation(protocol->documentationToken); printf("\"methods\": ["); for(size_t i = 0; i < protocol->methods().size(); i++){ Method *method = protocol->methods()[i]; reportProcedureInformation((Procedure *)method, Return, i + 1 == protocol->methods().size(), TypeContext(Type(protocol, false))); } printf("]}"); } printf("]"); printf("}"); }
void report(const char *packageName){ bool printedClass = false; printf("{"); printf("\"classes\": ["); for(auto eclass : classes){ if (strcmp(eclass->package->name, packageName) != 0) { continue; } if (printedClass) { putchar(','); } printedClass = true; printf("{"); ecCharToCharStack(eclass->name, className); printf("\"name\": \"%s\",", className); reportDocumentation(eclass->documentationToken); if (eclass->superclass) { ecCharToCharStack(eclass->superclass->name, superClassName); printf("\"superclass\": {\"package\": \"%s\", \"name\": \"%s\"},", eclass->superclass->package->name, superClassName); } printf("\"methods\": ["); for(size_t i = 0; i < eclass->methodList.size(); i++){ Method *method = eclass->methodList[i]; reportProcedureInformation(method, Return, i + 1 == eclass->methodList.size()); } printf("],"); printf("\"initializers\": ["); for(size_t i = 0; i < eclass->initializerList.size(); i++){ Initializer *initializer = eclass->initializerList[i]; reportProcedureInformation(initializer, initializer->canReturnNothingness ? CanReturnNothingness : NoReturn, i + 1 == eclass->initializerList.size()); } printf("],"); printf("\"classMethods\": ["); for(size_t i = 0; i < eclass->classMethodList.size(); i++){ ClassMethod *classMethod = eclass->classMethodList[i]; reportProcedureInformation((Procedure *)classMethod, Return, eclass->classMethodList.size() == i + 1); } printf("],"); printf("\"conformsTo\": ["); for(size_t i = 0; i < eclass->protocols().size(); i++){ Protocol *protocol = eclass->protocols()[i]; reportType(nullptr, Type(protocol, false), i + 1 == eclass->protocols().size()); } printf("]}"); } printf("],"); printf("\"enums\": ["); bool printedEnum = false; for(auto it : enumsRegister){ Enum *eenum = it.second; if (strcmp(eenum->package.name, packageName) != 0) { continue; } if (printedEnum) { putchar(','); } printf("{"); printedEnum = true; ecCharToCharStack(eenum->name, enumName); printf("\"name\": \"%s\",", enumName); reportDocumentation(eenum->documentationToken); bool printedValue = false; printf("\"values\": ["); for(auto it : eenum->map){ ecCharToCharStack(it.first, value); if (printedValue){ putchar(','); } printf("\"%s\"", value); printedValue = true; } printf("]}"); } printf("],"); printf("\"protocols\": ["); bool printedProtocol = false; for(auto it : protocolsRegister){ Protocol *protocol = it.second; if (strcmp(protocol->package->name, packageName) != 0) { continue; } if (printedProtocol) { putchar(','); } printedProtocol = true; printf("{"); ecCharToCharStack(protocol->name, protocolName); printf("\"name\": \"%s\",", protocolName); reportDocumentation(protocol->documentationToken); printf("\"methods\": ["); for(size_t i = 0; i < protocol->methods().size(); i++){ Method *method = protocol->methods()[i]; reportProcedureInformation((Procedure *)method, Return, i + 1 == protocol->methods().size()); } printf("]}"); } printf("]"); printf("}"); }