bool ItemReaderASTVisitor::visit(AST::UiPublicMember *ast) { PropertyDeclaration p; if (Q_UNLIKELY(ast->name.isEmpty())) throw ErrorInfo(Tr::tr("public member without name")); if (Q_UNLIKELY(ast->memberType.isEmpty())) throw ErrorInfo(Tr::tr("public member without type")); if (Q_UNLIKELY(ast->type == AST::UiPublicMember::Signal)) throw ErrorInfo(Tr::tr("public member with signal type not supported")); p.setName(ast->name.toString()); p.setType(PropertyDeclaration::propertyTypeFromString(ast->memberType.toString())); if (p.type() == PropertyDeclaration::UnknownType) { throw ErrorInfo(Tr::tr("Unknown type '%1' in property declaration.") .arg(ast->memberType.toString()), toCodeLocation(ast->typeToken)); } if (ast->typeModifier.compare(QLatin1String("list"))) { p.setFlags(p.flags() | PropertyDeclaration::ListProperty); } else if (Q_UNLIKELY(!ast->typeModifier.isEmpty())) { throw ErrorInfo(Tr::tr("public member with type modifier '%1' not supported").arg( ast->typeModifier.toString())); } m_item->m_propertyDeclarations.insert(p.name(), p); const JSSourceValuePtr value = JSSourceValue::create(); value->setFile(m_file); if (ast->statement) { handleBindingRhs(ast->statement, value); const QStringList bindingName(p.name()); checkDuplicateBinding(m_item, bindingName, ast->colonToken); } m_item->setProperty(p.name(), value); return false; }
bool ItemReaderASTVisitor::visit(AST::UiScriptBinding *ast) { QBS_CHECK(ast->qualifiedId); QBS_CHECK(!ast->qualifiedId->name.isEmpty()); const QStringList bindingName = toStringList(ast->qualifiedId); if (bindingName.length() == 1 && bindingName.first() == QLatin1String("id")) { const auto * const expStmt = AST::cast<AST::ExpressionStatement *>(ast->statement); if (Q_UNLIKELY(!expStmt)) throw ErrorInfo(Tr::tr("id: must be followed by identifier")); const auto * const idExp = AST::cast<AST::IdentifierExpression *>(expStmt->expression); if (Q_UNLIKELY(!idExp || idExp->name.isEmpty())) throw ErrorInfo(Tr::tr("id: must be followed by identifier")); m_item->m_id = idExp->name.toString(); m_file->ensureIdScope(m_itemPool); m_file->idScope()->setProperty(m_item->id(), ItemValue::create(m_item)); return false; } const JSSourceValuePtr value = JSSourceValue::create(); handleBindingRhs(ast->statement, value); Item * const targetItem = targetItemForBinding(bindingName, value); checkDuplicateBinding(targetItem, bindingName, ast->qualifiedId->identifierToken); targetItem->setProperty(bindingName.last(), value); return false; }
ItemReaderResult ItemReader::internalReadFile(const QString &filePath) { ASTCacheValue &cacheValue = (*m_astCache)[filePath]; if (cacheValue.isValid()) { if (Q_UNLIKELY(cacheValue.isProcessing())) throw ErrorInfo(Tr::tr("Loop detected when importing '%1'.").arg(filePath)); } else { QFile file(filePath); if (Q_UNLIKELY(!file.open(QFile::ReadOnly))) throw ErrorInfo(Tr::tr("Cannot open '%1'.").arg(filePath)); m_filesRead.insert(filePath); const QString code = QTextStream(&file).readAll(); QbsQmlJS::Lexer lexer(cacheValue.engine()); lexer.setCode(code, 1); QbsQmlJS::Parser parser(cacheValue.engine()); file.close(); if (!parser.parse()) { QList<QbsQmlJS::DiagnosticMessage> parserMessages = parser.diagnosticMessages(); if (Q_UNLIKELY(!parserMessages.isEmpty())) { ErrorInfo err; foreach (const QbsQmlJS::DiagnosticMessage &msg, parserMessages) err.append(msg.message, toCodeLocation(filePath, msg.loc)); throw err; } }
static void copyTemplateFile(const QString &fileName, const QString &targetDirectory, const Profile &profile, const QtEnvironment &qtEnv, QStringList *allFiles, const QtModuleInfo *module = 0) { if (!QDir::root().mkpath(targetDirectory)) { throw ErrorInfo(Internal::Tr::tr("Setting up Qt profile '%1' failed: " "Cannot create directory '%2'.") .arg(profile.name(), targetDirectory)); } QFile sourceFile(QLatin1String(":/templates/") + fileName); if (!sourceFile.open(QIODevice::ReadOnly)) { throw ErrorInfo(Internal::Tr::tr("Setting up Qt profile '%1' failed: " "Cannot open '%1' (%2).").arg(sourceFile.fileName(), sourceFile.errorString())); } QByteArray newContent = sourceFile.readAll(); if (module) replaceSpecialValues(&newContent, profile, *module, qtEnv); sourceFile.close(); const QString targetPath = targetDirectory + QLatin1Char('/') + fileName; allFiles->append(QFileInfo(targetPath).absoluteFilePath()); QFile targetFile(targetPath); if (targetFile.open(QIODevice::ReadOnly)) { if (newContent == targetFile.readAll()) // No need to overwrite anything in this case. return; targetFile.close(); } if (!targetFile.open(QIODevice::WriteOnly)) { throw ErrorInfo(Internal::Tr::tr("Setting up Qt profile '%1' failed: " "Cannot open '%1' (%2).").arg(targetFile.fileName(), targetFile.errorString())); } targetFile.resize(0); targetFile.write(newContent); }
ScreenSurface::ScreenSurface(int w, int h, int b, Uint32 f): width(w), height(h), bpp(b), flags(f) { if ( screenNum > 0 ) throw ErrorInfo("DONOT create more than ONE screen!"); if ( SDL_Init(SDL_INIT_VIDEO < 0 ) ) throw ErrorInfo(SDL_GetError()); pScreen = SDL_SetVideoMode(width, height, bpp, flags); screenNum++; }
// ### merge with Evaluator::handleEvaluationError static ErrorInfo errorInfoFromScriptValue(const QScriptValue &value, const QString &filePath) { if (!value.isError()) return ErrorInfo(value.toString(), CodeLocation(filePath)); return ErrorInfo(value.property(QStringLiteral("message")).toString(), CodeLocation(value.property(QStringLiteral("fileName")).toString(), value.property(QStringLiteral("lineNumber")).toInt32(), false)); }
ScreenSurface::ScreenSurface(): width(640), height(480), bpp(32), flags(0) { if ( screenNum > 0 ) throw ErrorInfo("DONOT create more than ONE screen!"); if ( SDL_Init(SDL_INIT_VIDEO < 0 ) ) throw ErrorInfo(SDL_GetError()); pScreen = SDL_SetVideoMode(width, height, bpp, flags); screenNum++; }
DisplaySurface::DisplaySurface(const std::string& file_name, const ScreenSurface& screen): fileName(file_name) { SDL_Surface* pSurfaceTemp = IMG_Load(file_name.c_str()); if ( pSurfaceTemp == 0 ) throw ErrorInfo(SDL_GetError()); pSurface = SDL_DisplayFormat(pSurfaceTemp); if ( pSurface == 0 ) throw ErrorInfo(SDL_GetError()); SDL_FreeSurface(pSurfaceTemp); pScreen = screen.point(); }
void StringListOption::doParse(const QString &representation, QStringList &input) { m_arguments = getArgument(representation, input).split(QLatin1Char(',')); if (m_arguments.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1': Argument list must not be empty.\n" "Usage: %2").arg(representation, description(command()))); } foreach (const QString &element, m_arguments) { if (element.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1': Argument list must not contain " "empty elements.\nUsage: %2") .arg(representation, description(command()))); } } }
void PersistentPool::finalizeWriteStream() { if (m_stream.status() != QDataStream::Ok) throw ErrorInfo(Tr::tr("Failure serializing build graph.")); m_stream.device()->seek(0); m_stream << QByteArray(QBS_PERSISTENCE_MAGIC); if (m_stream.status() != QDataStream::Ok) throw ErrorInfo(Tr::tr("Failure serializing build graph.")); const auto file = static_cast<QFile *>(m_stream.device()); if (!file->flush()) { file->close(); file->remove(); throw ErrorInfo(Tr::tr("Failure serializing build graph: %1").arg(file->errorString())); } }
void ScriptEngine::importProgram(const QScriptProgram &program, const QScriptValue &scope, QScriptValue &targetObject) { QSet<QString> globalPropertyNames; { QScriptValueIterator it(globalObject()); while (it.hasNext()) { it.next(); globalPropertyNames += it.name(); } } pushContext(); if (scope.isObject()) currentContext()->pushScope(scope); QScriptValue result = evaluate(program); QScriptValue activationObject = currentContext()->activationObject(); if (scope.isObject()) currentContext()->popScope(); popContext(); if (Q_UNLIKELY(hasErrorOrException(result))) throw ErrorInfo(tr("Error when importing '%1': %2").arg(program.fileName(), result.toString())); // If targetObject is already an object, it doesn't get overwritten but enhanced by the // contents of the .js file. // This is necessary for library imports that consist of multiple js files. if (!targetObject.isObject()) targetObject = newObject(); // Copy every property of the activation object to the target object. // We do not just save a reference to the activation object, because QScriptEngine contains // special magic for activation objects that leads to unanticipated results. { QScriptValueIterator it(activationObject); while (it.hasNext()) { it.next(); if (debugJSImports) qDebug() << "[ENGINE] Copying property " << it.name(); targetObject.setProperty(it.name(), it.value()); } } // Copy new global properties to the target object and remove them from // the global object. This is to support direct variable assignments // without the 'var' keyword in JavaScript files. QScriptValueIterator it(globalObject()); while (it.hasNext()) { it.next(); if (globalPropertyNames.contains(it.name())) continue; if (debugJSImports) { qDebug() << "[ENGINE] inserting global property " << it.name() << " " << it.value().toString(); } targetObject.setProperty(it.name(), it.value()); it.remove(); } }
void ScriptImporter::importSourceCode(const QString &sourceCode, const QString &filePath, QScriptValue &targetObject) { Q_ASSERT(targetObject.isObject()); // The targetObject doesn't get overwritten but enhanced by the contents of the .js file. // This is necessary for library imports that consist of multiple js files. QString &code = m_sourceCodeCache[filePath]; if (code.isEmpty()) { QbsQmlJS::Engine engine; QbsQmlJS::Lexer lexer(&engine); lexer.setCode(sourceCode, 1, false); QbsQmlJS::Parser parser(&engine); if (!parser.parseProgram()) { throw ErrorInfo(parser.errorMessage(), CodeLocation(filePath, parser.errorLineNumber(), parser.errorColumnNumber())); } IdentifierExtractor extractor; extractor.start(parser.rootNode()); code = QLatin1String("(function(){\n") + sourceCode + extractor.suffix(); } QScriptValue result = m_engine->evaluate(code, filePath, 0); if (m_engine->hasUncaughtException()) throw errorInfoFromScriptValue(result, filePath); copyProperties(result, targetObject); }
int ParameterContainer::offsetGetMaxLength(const QString &name) throw(ErrorInfo) { if(!m_maxLength.contains(name)){ throw ErrorInfo("Data does not exist for this name"); } return m_maxLength[name]; }
void CommandEchoModeOption::doParse(const QString &representation, QStringList &input) { const QString mode = getArgument(representation, input); if (mode.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1': No command echo mode given.\nUsage: %2") .arg(representation, description(command()))); } if (!allCommandEchoModeStrings().contains(mode)) { throw ErrorInfo(Tr::tr("Invalid use of option '%1': " "Invalid command echo mode '%2' given.\nUsage: %3") .arg(representation, mode, description(command()))); } m_echoMode = commandEchoModeFromName(mode); }
Atomic ReadAtomic(void) { int err; if(rrecs[currec].was_unread) { rrecs[currec].was_unread=0; return rrecs[currec].unread; } err=setjmp(lex_jmp_buf); if(err!=0) { ErrorInfo(err); printf(" end of file \"%s\" within comment /*...*/ \n", CurrentInputFile()); return 0; } if(rrecs[currec].cura>=rrecs[currec].acnt) readatomics(); if(rrecs[currec].eof==1 || rrecs[currec].acnt==0) return 0; rrecs[currec].cura++; return rrecs[currec].a[rrecs[currec].cura-1]; }
void CBuzzController::ControlStep() { /* Update debugging information */ m_sDebug.Clear(); if(m_sDebug.Trajectory.Tracking) { const CCI_PositioningSensor::SReading& sPosRead = m_pcPos->GetReading(); m_sDebug.TrajectoryAdd(sPosRead.Position); } /* Take care of the rest */ if(m_tBuzzVM && m_tBuzzVM->state == BUZZVM_STATE_READY) { ProcessInMsgs(); UpdateSensors(); if(buzzvm_function_call(m_tBuzzVM, "step", 0) != BUZZVM_STATE_READY) { fprintf(stderr, "[ROBOT %u] %s: execution terminated abnormally: %s\n\n", m_tBuzzVM->robot, m_strBytecodeFName.c_str(), ErrorInfo().c_str()); for(UInt32 i = 1; i <= buzzdarray_size(m_tBuzzVM->stacks); ++i) { buzzdebug_stack_dump(m_tBuzzVM, i, stdout); } return; } ProcessOutMsgs(); } else { fprintf(stderr, "[ROBOT %s] Robot is not ready to execute Buzz script.\n\n", GetId().c_str()); } }
const QString& ParameterContainer::offsetGetErrata(const QString &name) throw(ErrorInfo) { if(!m_errata.contains(name)){ throw ErrorInfo("Data does not exist for this name"); } return m_errata[name]; }
static Term cc_particle(Term t1, List *ind) { Term t, prt; t=ConsumeCompoundArg(t1,1); FreeAtomic(t1); prt=GetAtomProperty(t,PROP_TYPE); if( !(is_compound(prt) && CompoundName(prt)==OPR_PARTICLE)) { ErrorInfo(216); printf(" cc(\'");WriteTerm(t);printf("\') is undefined.\n"); longjmp(alg1_jmp_buf,1); } t1=t; /* if(CompoundArg1(prt)==t) t=CompoundArg2(prt); else t=CompoundArg1(prt);*/ if(ind!=NULL) *ind=CopyTerm(GetAtomProperty(t,PROP_INDEX)); if(!is_empty_list(*ind) && CompoundName(CompoundArg1(ListFirst(*ind)))==A_LORENTZ) { Term tt, in1,in2; tt=CompoundArg1(ListFirst(*ind)); in1=ConsumeCompoundArg(tt,1); in2=ConsumeCompoundArg(tt,2); SetCompoundArg(tt,1,in2); SetCompoundArg(tt,2,in1); } /* WriteTerm(*ind); puts(""); */ return t1; }
void GeneratorOption::doParse(const QString &representation, QStringList &input) { m_generatorName = getArgument(representation, input); if (m_generatorName.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1': No generator given.\nUsage: %2") .arg(representation, description(command()))); } }
QString CommandLineOption::getArgument(const QString &representation, QStringList &input) { if (input.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1': Missing argument.\nUsage: %2") .arg(representation, description(command()))); } return input.takeFirst(); }
void SettingsDirOption::doParse(const QString &representation, QStringList &input) { if (input.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1: Argument expected.\n" "Usage: %2").arg(representation, description(command()))); } m_settingsDir = input.takeFirst(); }
Term ProcDelVertex(Term t, List ind) { List l, pl; if(lagr_hash==NULL) { ErrorInfo(107); puts("DelVertex: no vertices"); return 0; } if(!is_compound(t)||CompoundArity(t)!=1) { ErrorInfo(107); puts("wrong call to DelVertex"); return 0; } pl=CompoundArg1(t); if(!is_list(pl)) { ErrorInfo(107); puts("wrong call to DelVertex"); return 0; } for(l=pl;l;l=ListTail(l)) if(is_function(ListFirst(l),0)) ChangeList(l,CallFunction(ListFirst(l),0)); pl=SortedList(pl,acmp); l=finda2(pl,1); if(is_empty_list(l)) { WarningInfo(108);printf("DelVertex: vertex "); WriteTerm(pl); puts(" not found"); return 0; } return 0; }
void JobsOption::doParse(const QString &representation, QStringList &input) { const QString jobCountString = getArgument(representation, input); bool stringOk; m_jobCount = jobCountString.toInt(&stringOk); if (!stringOk || m_jobCount <= 0) throw ErrorInfo(Tr::tr("Invalid use of option '%1': Illegal job count '%2'.\nUsage: %3") .arg(representation, jobCountString, description(command()))); }
void ItemReaderASTVisitor::checkDuplicateBinding(Item *item, const QStringList &bindingName, const AST::SourceLocation &sourceLocation) { if (Q_UNLIKELY(item->properties().contains(bindingName.last()))) { QString msg = Tr::tr("Duplicate binding for '%1'"); throw ErrorInfo(msg.arg(bindingName.join(QLatin1Char('.'))), toCodeLocation(sourceLocation)); } }
void DisplaySurface::blit(int at_x, int at_y) const { SDL_Rect offset; offset.x = at_x; offset.y = at_y; if ( SDL_BlitSurface(pSurface, 0, pScreen, &offset) < 0 ) throw ErrorInfo(SDL_GetError()); }
ErrorInfo setupQtProfile(const QString &profileName, Settings *settings, const QtEnvironment &qtEnvironment) { try { doSetupQtProfile(profileName, settings, qtEnvironment); return ErrorInfo(); } catch (const ErrorInfo &e) { return e; } }
ErrorInfo WampRouter::init() { Q_D(WampRouter); for(Realm* realm: d->_worker->_realms) { realm->setParent(NULL); realm->moveToThread(d->_workerThread); } QMetaObject::invokeMethod(d->_worker, "startServer", Qt::QueuedConnection); return ErrorInfo(); }
ErrorInfo AddressBookController::editContact(const Contact::ContactId id, const Contact &c) { if(!c.isValidToAdd()) { return ErrorInfo(ERR_CONTACT_NOT_VALID, "Invalid Contact. Make sure all required fields are filled."); } return dataStore.updateContact(id, c); }
void CommandLineFrontend::checkGeneratorName() { const QString generatorName = m_parser.generateOptions().generatorName(); m_generator = ProjectGeneratorManager::findGenerator(generatorName); if (m_generator) return; const auto generatorNames = ProjectGeneratorManager::loadedGeneratorNames(); if (!generatorNames.empty()) { const QString generatorNamesString = generatorNames.join(QLatin1String("\n\t")); if (!generatorName.isEmpty()) { throw ErrorInfo(Tr::tr("No generator named '%1'. Available generators:\n\t%2") .arg(generatorName, generatorNamesString)); } throw ErrorInfo(Tr::tr("No generator specified. Available generators:\n\t%1") .arg(generatorNamesString)); } throw ErrorInfo(Tr::tr("No generator specified or no generators are available.")); }
void InstallRootOption::doParse(const QString &representation, QStringList &input) { if (input.isEmpty()) { throw ErrorInfo(Tr::tr("Invalid use of option '%1: Argument expected.\n" "Usage: %2").arg(representation, description(command()))); } const QString installRoot = input.takeFirst(); if (installRoot == magicSysrootString()) m_useSysroot = true; else m_installRoot = installRoot; }