Пример #1
0
FileLocation SourceLocation::getSpellingLocation() const
{
   std::string file;
   unsigned line, column;
   if (getSpellingLocation(&file, &line, &column))
      return FileLocation(FilePath(file), line, column);
   else
      return FileLocation();
}
Пример #2
0
TypeNode* handleSequenceType(TypeNode* type_expr)
{
    SequenceTypeNode* tn = new SequenceTypeNode(type_expr);
    tn->setLocation(FileLocation(yylineno));
    return tn;
#if 0
    const EquelleType et = type_expr->type();
    if (!et.isBasic()) {
        yyerror("cannot create a Sequence of non-basic types.");
    }
    TypeNode* node = new TypeNode(EquelleType(et.basicType(), Sequence, et.gridMapping(), et.subsetOf()));
    node->setLocation(FileLocation(yylineno));
    return node;
#endif
}
Пример #3
0
SequenceNode* handleStencilAssignment(FuncCallLikeNode* lhs, ExpressionNode* rhs)
{
    SequenceNode* retval = new SequenceNode();
    retval->setLocation(FileLocation(yylineno));

    StencilNode* stencil = dynamic_cast<StencilNode*>(lhs);
    if (stencil == nullptr) {
        std::string err_msg = "Internal error: The stencil \"" + lhs->name() + "\" does not appear to be properly defined";
        yyerror(err_msg.c_str());
    }

#if 0
    // If the type is a collection of invalids (no pun intended)
    // we can safely set it to the type of the rhs
    EquelleType lhs_et = SymbolTable::variableType(stencil->name());
    if (lhs_et.basicType() == Invalid
        && lhs_et.compositeType() == Collection
        && lhs_et.isStencil()) {
        EquelleType lhs_et = rhs->type();
        lhs_et.setMutable(true);
        SymbolTable::setVariableType(stencil->name(), lhs_et);
        // TODO: set dimensions correctly here
        TypeNode* lhs_type = new TypeNode(lhs_et);
        retval->pushNode(new VarDeclNode(stencil->name(), lhs_type));
    }
#endif
    retval->pushNode(new StencilAssignmentNode(stencil, rhs));
    return retval;
}
Пример #4
0
ExpressionNode* handleIdentifier(const std::string& name)
{
    VarNode* node = new VarNode(name);
    node->setLocation(FileLocation(yylineno));
    return node;
#if 0
    if (SymbolTable::isVariableDeclared(name)) {
        return new VarNode(name);
    } else {
        if (SymbolTable::isFunctionDeclared(name)) {
            return new FuncRefNode(name);
        } else {
            // This is a small problem: we want the error below, to catch
            // usage of undeclared identifiers, but the function start section
            // would then generate errors, because we are not yet in the function
            // scope.

            // std::string e("unknown identifier ");
            // e += name;
            // yyerror(e.c_str());
            return new JustAnIdentifierNode(name);
        }
    }
#endif
}
ChildFFMpegLoader::ChildFFMpegLoader(std::unique_ptr<VideoSoundData> &&data)
: AbstractAudioFFMpegLoader(
	FileLocation(),
	QByteArray(),
	base::byte_vector())
, _parentData(std::move(data)) {
}
Пример #6
0
StencilNode* handleStencilAccess(const std::string& name, FuncArgsNode* args)
{
    StencilNode* node = new StencilNode(name, args);
    node->setLocation(FileLocation(yylineno));
    return node;
#if 0
    if (!SymbolTable::isVariableDeclared(name)) {
        std::string err_msg = "Could not find the stencil variable " + name;
        yyerror(err_msg.c_str());
    }

    auto argtypes = args->argumentTypes();
    for (int i=0; i<argtypes.size(); ++i) {
        if (!isStencilType(argtypes[i].basicType())) {
            std::stringstream err_msg;
            err_msg << "Cannot access a stencil with a non-stencil index in variable \""
                    << name << "\"" << std::endl;
            yyerror(err_msg.str().c_str());
        }
        else if (argtypes[i].basicType() != StencilI + i) {
            std::stringstream err_msg;
            err_msg << "Got index " << basicTypeString(argtypes[i].basicType())
                    << " but expected " << basicTypeString(BasicType(StencilI + i))
                    << " for variable \"" << name << "\"" << std::endl;
            yyerror(err_msg.str().c_str());
        }
    }
    return new StencilNode(name, args);
#endif
}
Пример #7
0
FuncStartNode* handleFuncAssignmentStart(const std::string& name, FuncArgsNode* args)
{
    FuncStartNode* node = new FuncStartNode(name, args);
    node->setLocation(FileLocation(yylineno));
    return node;
#if 0
    // We are dealing with a function
    if (SymbolTable::isFunctionDeclared(name)) {
        // Set the scope name for the following block (the function itself)
        // Will be "undone" in handleFuncAssignment
        SymbolTable::setCurrentFunction(name);
        return new FuncStartNode(name, args);
    }
    // We are dealing with a defined stencil variable
    else if (SymbolTable::isVariableDeclared(name)) {
        return handleStencilAccess(name, args);
    }
    // We are dealing with an undefined stencil variable
    else {
        EquelleType type(Invalid, Collection);
        type.setStencil(true);
        SymbolTable::declareVariable(name, type);
        return handleStencilAccess(name, args);
    }
#endif
}
Пример #8
0
Node* handleDeclarationAssign(const std::string& name, TypeNode* type, ExpressionNode* expr)
{
    SequenceNode* seq = new SequenceNode;
    seq->pushNode(handleDeclaration(name, type));
    seq->pushNode(handleAssignment(name, expr));
    seq->setLocation(FileLocation(yylineno));
    return seq;
}
Пример #9
0
UnitNode* handleUnitPower(UnitNode* unit, const double num)
{
    const int n = static_cast<int>(num);
    if (n != num) {
        yyerror("Powers of units (to the right of '^') can only be integers.");
    }
    UnitNode* node = new PowerUnitNode(unit, n);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #10
0
FuncCallStatementNode* handleFuncCallStatement(FuncCallLikeNode* fcall_like)
{
    FuncCallNode* fcall = dynamic_cast<FuncCallNode*>(fcall_like);
    if (fcall == nullptr) {
        std::string err_msg = "Internal error: The function \"" + fcall_like->name() + "\" does not appear to be properly defined";
        yyerror(err_msg.c_str());
    }
    FuncCallStatementNode* node = new FuncCallStatementNode(fcall);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #11
0
TypeNode* handleMutableType(TypeNode* type_expr)
{
    MutableTypeNode* tn = new MutableTypeNode(type_expr);
    tn->setLocation(FileLocation(yylineno));
    return tn;
#if 0
    EquelleType et = type_expr->type();
    et.setMutable(true);
    TypeNode* tn = new TypeNode(et);
    tn->setLocation(type_expr->location());
    delete type_expr;
    return tn;
#endif
}
Пример #12
0
	FileLocation readFileLocation(const MediaKey &location, bool check) {
		FileLocations::iterator i = _fileLocations.find(location);
		for (FileLocations::iterator i = _fileLocations.find(location); (i != _fileLocations.end()) && (i.key() == location);) {
			if (check) {
				QFileInfo info(i.value().name);
				if (!info.exists() || info.lastModified() != i.value().modified || info.size() != i.value().size) {
					_fileLocationPairs.remove(i.value().name);
					i = _fileLocations.erase(i);
					_writeLocations();
					continue;
				}
			}
			return i.value();
		}
		return FileLocation();
	}
Пример #13
0
void FileUploader::uploadMedia(MsgId msgId, const ReadyLocalMedia &media) {
	if (media.type == ToPreparePhoto) {
		App::feedPhoto(media.photo, media.photoThumbs);
	} else if (media.type == ToPrepareDocument) {
		DocumentData *document;
		if (media.photoThumbs.isEmpty()) {
			document = App::feedDocument(media.document);
		} else {
			document = App::feedDocument(media.document, media.photoThumbs.begin().value());
		}
		document->status = FileUploading;
		if (!media.file.isEmpty()) {
			document->location = FileLocation(mtpc_storage_filePartial, media.file);
		}
	}
	queue.insert(msgId, File(media));
	sendNext();
}
Пример #14
0
TypeNode* handleArrayType(const int array_size, TypeNode* type_expr)
{
    ArrayTypeNode* tn = new ArrayTypeNode(type_expr, array_size);
    tn->setLocation(FileLocation(yylineno));
    return tn;
#if 0
    EquelleType et = type_expr->type();
    if (et.isArray()) {
        yyerror("cannot create an Array of an Array.");
        return type_expr;
    } else {
        et.setArraySize(array_size);
        TypeNode* tn = new TypeNode(et);
        tn->setLocation(type_expr->location());
        delete type_expr;
        return tn;
    }
#endif
}
Пример #15
0
void FileUploader::uploadMedia(const FullMsgId &msgId, const ReadyLocalMedia &media) {
    if (media.type == PreparePhoto) {
        App::feedPhoto(media.photo, media.photoThumbs);
    } else if (media.type == PrepareDocument || media.type == PrepareAudio) {
        DocumentData *document;
        if (media.photoThumbs.isEmpty()) {
            document = App::feedDocument(media.document);
        } else {
            document = App::feedDocument(media.document, media.photoThumbs.begin().value());
        }
        document->status = FileUploading;
        if (!media.data.isEmpty()) {
            document->setData(media.data);
        }
        if (!media.file.isEmpty()) {
            document->setLocation(FileLocation(StorageFilePartial, media.file));
        }
    }
    queue.insert(msgId, File(media));
    sendNext();
}
Пример #16
0
void FileUploader::upload(const FullMsgId &msgId, const FileLoadResultPtr &file) {
    if (file->type == PreparePhoto) {
        PhotoData *photo = App::feedPhoto(file->photo, file->photoThumbs);
        photo->uploadingData = new PhotoData::UploadingData(file->partssize);
    } else if (file->type == PrepareDocument || file->type == PrepareAudio) {
        DocumentData *document;
        if (file->thumb.isNull()) {
            document = App::feedDocument(file->document);
        } else {
            document = App::feedDocument(file->document, file->thumb);
        }
        document->status = FileUploading;
        if (!file->content.isEmpty()) {
            document->setData(file->content);
        }
        if (!file->filepath.isEmpty()) {
            document->setLocation(FileLocation(StorageFilePartial, file->filepath));
        }
    }
    queue.insert(msgId, File(file));
    sendNext();
}
ChildFFMpegLoader::ChildFFMpegLoader(uint64 videoPlayId, std_::unique_ptr<VideoSoundData> &&data) : AudioPlayerLoader(FileLocation(), QByteArray())
, _videoPlayId(videoPlayId)
, _parentData(std_::move(data)) {
	_frame = av_frame_alloc();
}
Пример #18
0
void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRequestId req) {
	Requests::iterator i = _requests.find(req);
	if (i == _requests.cend()) {
		if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): request req=%2 for offset=%3 not found in _requests=%4").arg(_id).arg(req).arg(offset).arg(serializereqs(_requests)));
		return loadNext();
	}
	if (result.type() != mtpc_upload_file) {
		if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): bad cons received! %2").arg(_id).arg(result.type()));
		return cancel(true);
	}

	int32 limit = (_locationType == UnknownFileLocation) ? DownloadPartSize : DocumentDownloadPartSize;
	int32 dcIndex = i.value();
	DataRequestedMap[_dc].v[dcIndex] -= limit;

	--_queue->queries;
	_requests.erase(i);

	auto &d = result.c_upload_file();
	auto &bytes = d.vbytes.c_string().v;

	if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): got part with offset=%2, bytes=%3, _queue->queries=%4, _nextRequestOffset=%5, _requests=%6").arg(_id).arg(offset).arg(bytes.size()).arg(_queue->queries).arg(_nextRequestOffset).arg(serializereqs(_requests)));

	if (bytes.size()) {
		if (_fileIsOpen) {
			int64 fsize = _file.size();
			if (offset < fsize) {
				_skippedBytes -= bytes.size();
			} else if (offset > fsize) {
				_skippedBytes += offset - fsize;
			}
			_file.seek(offset);
			if (_file.write(bytes.data(), bytes.size()) != qint64(bytes.size())) {
				return cancel(true);
			}
		} else {
			_data.reserve(offset + bytes.size());
			if (offset > _data.size()) {
				_skippedBytes += offset - _data.size();
				_data.resize(offset);
			}
			if (offset == _data.size()) {
				_data.append(bytes.data(), bytes.size());
			} else {
				_skippedBytes -= bytes.size();
				if (int64(offset + bytes.size()) > _data.size()) {
					_data.resize(offset + bytes.size());
				}
				memcpy(_data.data() + offset, bytes.data(), bytes.size());
			}
		}
	}
	if (!bytes.size() || (bytes.size() % 1024)) { // bad next offset
		_lastComplete = true;
	}
	if (_requests.isEmpty() && (_lastComplete || (_size && _nextRequestOffset >= _size))) {
		if (!_fname.isEmpty() && (_toCache == LoadToCacheAsWell)) {
			if (!_fileIsOpen) _fileIsOpen = _file.open(QIODevice::WriteOnly);
			if (!_fileIsOpen) {
				return cancel(true);
			}
			if (_file.write(_data) != qint64(_data.size())) {
				return cancel(true);
			}
		}
		_type = d.vtype.type();
		_complete = true;
		if (_fileIsOpen) {
			_file.close();
			_fileIsOpen = false;
			psPostprocessFile(QFileInfo(_file).absoluteFilePath());
		}
		removeFromQueue();

		if (!_queue->queries) {
			App::app()->killDownloadSessionsStart(_dc);
		}

		if (_localStatus == LocalNotFound || _localStatus == LocalFailed) {
			if (_locationType != UnknownFileLocation) { // audio, video, document
				MediaKey mkey = mediaKey(_locationType, _dc, _id, _version);
				if (!_fname.isEmpty()) {
					Local::writeFileLocation(mkey, FileLocation(mtpToStorageType(_type), _fname));
				}
				if (_toCache == LoadToCacheAsWell) {
					if (_locationType == DocumentFileLocation) {
						Local::writeStickerImage(mkey, _data);
					} else if (_locationType == AudioFileLocation) {
						Local::writeAudio(mkey, _data);
					}
				}
			} else {
				Local::writeImage(storageKey(*_location), StorageImageSaved(mtpToStorageType(_type), _data));
			}
		}
	} else {
		if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): not done yet, _lastComplete=%2, _size=%3, _nextRequestOffset=%4, _requests=%5").arg(_id).arg(Logs::b(_lastComplete)).arg(_size).arg(_nextRequestOffset).arg(serializereqs(_requests)));
	}
	emit progress(this);
	if (_complete) {
		FileDownload::ImageLoaded().notify();
	}
	loadNext();
}
Пример #19
0
NormNode* handleNorm(ExpressionNode* expr_to_norm)
{
    NormNode* node = new NormNode(expr_to_norm);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #20
0
UnaryNegationNode* handleUnaryNegation(ExpressionNode* expr_to_negate)
{
    UnaryNegationNode* node = new UnaryNegationNode(expr_to_negate);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #21
0
TrinaryIfNode* handleTrinaryIf(ExpressionNode* predicate, ExpressionNode* iftrue, ExpressionNode* iffalse)
{
    TrinaryIfNode* node = new TrinaryIfNode(predicate, iftrue, iffalse);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #22
0
OnNode* handleExtend(ExpressionNode* left, ExpressionNode* right)
{
    OnNode* node = new OnNode(left, right, true);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #23
0
StringNode* handleString(const std::string& content)
{
    StringNode* node = new StringNode(content);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #24
0
UnitNode* handleUnitOp(BinaryOp op, UnitNode* left, UnitNode* right)
{
    UnitNode* node = new BinaryOpUnitNode(op, left, right);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #25
0
QuantityNode* handleQuantity(NumberNode* number, UnitNode* unit)
{
    QuantityNode* node = new QuantityNode(number, unit);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #26
0
UnitNode* handleUnit(const std::string& name)
{
    UnitNode* node = new BasicUnitNode(name);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #27
0
RandomAccessNode* handleRandomAccess(ExpressionNode* expr, const int index)
{
    RandomAccessNode* node = new RandomAccessNode(expr, index);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #28
0
LoopNode* handleLoopStart(const std::string& loop_variable, const std::string& loop_set)
{
    LoopNode* node = new LoopNode(loop_variable, loop_set);
    node->setLocation(FileLocation(yylineno));
    return node;
}
Пример #29
0
void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRequestId req) {
//	uint64 ms = getms();
	Requests::iterator i = requests.find(req);
	if (i == requests.cend()) return loadNext();

	int32 limit = (_locationType == UnknownFileLocation) ? DownloadPartSize : DocumentDownloadPartSize;
	int32 dcIndex = i.value();
	_dataRequested[dc].v[dcIndex] -= limit;

	--queue->queries;
	requests.erase(i);

	const MTPDupload_file &d(result.c_upload_file());
	const string &bytes(d.vbytes.c_string().v);
	if (bytes.size()) {
		if (fileIsOpen) {
			int64 fsize = file.size();
			if (offset < fsize) {
				skippedBytes -= bytes.size();
			} else if (offset > fsize) {
				skippedBytes += offset - fsize;
			}
			file.seek(offset);
			if (file.write(bytes.data(), bytes.size()) != qint64(bytes.size())) {
				return finishFail();
			}
		} else {
			data.reserve(offset + bytes.size());
			if (offset > data.size()) {
				skippedBytes += offset - data.size();
				data.resize(offset);
			}
			if (offset == data.size()) {
				data.append(bytes.data(), bytes.size());
			} else {
				skippedBytes -= bytes.size();
				if (int64(offset + bytes.size()) > data.size()) {
					data.resize(offset + bytes.size());
				}
				memcpy(data.data() + offset, bytes.data(), bytes.size());
			}
		}
	}
	if (!bytes.size() || (bytes.size() % 1024)) { // bad next offset
		lastComplete = true;
	}
	if (requests.isEmpty() && (lastComplete || (size && nextRequestOffset >= size))) {
		if (!fname.isEmpty() && duplicateInData) {
			if (!fileIsOpen) fileIsOpen = file.open(QIODevice::WriteOnly);
			if (!fileIsOpen) {
				return finishFail();
			}
			if (file.write(data) != qint64(data.size())) {
				return finishFail();
			}
		}
		type = d.vtype.type();
		complete = true;
		if (fileIsOpen) {
			file.close();
			fileIsOpen = false;
			psPostprocessFile(QFileInfo(file).absoluteFilePath());
		}
		removeFromQueue();

		emit App::wnd()->imageLoaded();

		if (!queue->queries) {
			App::app()->killDownloadSessionsStart(dc);
		}

		if (_localStatus == LocalNotFound || _localStatus == LocalFailed) {
			if (_locationType != UnknownFileLocation) { // audio, video, document
				MediaKey mkey = mediaKey(_locationType, dc, id);
				if (!fname.isEmpty()) {
					Local::writeFileLocation(mkey, FileLocation(mtpToStorageType(type), fname));
				}
				if (duplicateInData) {
					if (_locationType == DocumentFileLocation) {
						Local::writeStickerImage(mkey, data);
					} else if (_locationType == AudioFileLocation) {
						Local::writeAudio(mkey, data);
					}
				}
			} else {
				Local::writeImage(storageKey(dc, volume, local), StorageImageSaved(mtpToStorageType(type), data));
			}
		}
	}
	emit progress(this);
	loadNext();
}
Пример #30
0
ArrayNode* handleArray(FuncArgsNode* expr_list)
{
    ArrayNode* node = new ArrayNode(expr_list);
    node->setLocation(FileLocation(yylineno));
    return node;
}