2016-04-16 17:51:25 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-16 17:51:25 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-16 17:51:25 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2016-04-17 13:22:00 +00:00
|
|
|
#include <string>
|
2016-11-04 11:14:47 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <QImage>
|
2016-04-16 17:51:25 +00:00
|
|
|
#include "codegen/common/basic_tokenized_file.h"
|
2016-04-17 09:30:14 +00:00
|
|
|
#include "codegen/style/options.h"
|
2016-04-18 20:33:43 +00:00
|
|
|
#include "codegen/style/module.h"
|
2016-04-16 17:51:25 +00:00
|
|
|
|
|
|
|
namespace codegen {
|
|
|
|
namespace style {
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
using Modifier = std::function<void(QImage &png100x, QImage &png200x)>;
|
|
|
|
Modifier GetModifier(const QString &name);
|
|
|
|
|
2016-04-17 09:30:14 +00:00
|
|
|
// Parses an input file to the internal struct.
|
|
|
|
class ParsedFile {
|
2016-04-16 17:51:25 +00:00
|
|
|
public:
|
2016-04-18 20:33:43 +00:00
|
|
|
explicit ParsedFile(const Options &options);
|
2016-04-17 09:30:14 +00:00
|
|
|
ParsedFile(const ParsedFile &other) = delete;
|
|
|
|
ParsedFile &operator=(const ParsedFile &other) = delete;
|
2016-04-16 17:51:25 +00:00
|
|
|
|
2016-04-17 09:30:14 +00:00
|
|
|
bool read();
|
|
|
|
|
2016-04-18 20:33:43 +00:00
|
|
|
using ModulePtr = std::unique_ptr<structure::Module>;
|
|
|
|
ModulePtr getResult() {
|
|
|
|
return std::move(module_);
|
2016-04-16 17:51:25 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 09:30:14 +00:00
|
|
|
private:
|
2016-04-16 17:51:25 +00:00
|
|
|
bool failed() const {
|
2016-04-17 09:30:14 +00:00
|
|
|
return failed_ || file_.failed();
|
2016-04-16 17:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Log error to std::cerr with 'code' at the current position in file.
|
2016-04-17 09:30:14 +00:00
|
|
|
common::LogStream logError(int code) {
|
|
|
|
failed_ = true;
|
2016-04-16 17:51:25 +00:00
|
|
|
return file_.logError(code);
|
|
|
|
}
|
2016-04-17 13:22:00 +00:00
|
|
|
common::LogStream logErrorUnexpectedToken() {
|
2016-04-17 09:30:14 +00:00
|
|
|
failed_ = true;
|
2016-04-17 13:22:00 +00:00
|
|
|
return file_.logErrorUnexpectedToken();
|
|
|
|
}
|
|
|
|
common::LogStream logErrorTypeMismatch();
|
|
|
|
common::LogStream logAssert(bool assertion) {
|
|
|
|
if (!assertion) {
|
|
|
|
return logError(common::kErrorInternal) << "internal - ";
|
|
|
|
}
|
|
|
|
return common::LogStream(common::LogStream::Null);
|
2016-04-17 09:30:14 +00:00
|
|
|
}
|
2016-04-16 17:51:25 +00:00
|
|
|
|
2016-04-17 13:22:00 +00:00
|
|
|
// Helper methods for context-dependent reading.
|
2016-04-18 20:33:43 +00:00
|
|
|
ModulePtr readIncluded();
|
2016-04-17 13:22:00 +00:00
|
|
|
structure::Struct readStruct(const QString &name);
|
|
|
|
structure::Variable readVariable(const QString &name);
|
|
|
|
|
|
|
|
structure::StructField readStructField(const QString &name);
|
|
|
|
structure::Type readType();
|
|
|
|
structure::Value readValue();
|
|
|
|
|
|
|
|
structure::Value readStructValue();
|
|
|
|
structure::Value defaultConstructedStruct(const structure::FullName &name);
|
|
|
|
void applyStructParent(structure::Value &result, const structure::FullName &parentName);
|
|
|
|
bool readStructValueInner(structure::Value &result);
|
2016-04-17 17:52:17 +00:00
|
|
|
bool assignStructField(structure::Value &result, const structure::Variable &field);
|
2016-04-17 13:22:00 +00:00
|
|
|
bool readStructParents(structure::Value &result);
|
|
|
|
|
|
|
|
// Simple methods for reading value types.
|
|
|
|
structure::Value readPositiveValue();
|
|
|
|
structure::Value readNumericValue();
|
|
|
|
structure::Value readStringValue();
|
|
|
|
structure::Value readColorValue();
|
|
|
|
structure::Value readPointValue();
|
|
|
|
structure::Value readSizeValue();
|
|
|
|
structure::Value readAlignValue();
|
|
|
|
structure::Value readMarginsValue();
|
|
|
|
structure::Value readFontValue();
|
2016-04-21 17:57:29 +00:00
|
|
|
structure::Value readIconValue();
|
2016-04-17 13:22:00 +00:00
|
|
|
structure::Value readCopyValue();
|
|
|
|
|
2016-05-20 15:35:58 +00:00
|
|
|
structure::Value readNumericOrNumericCopyValue();
|
|
|
|
structure::Value readStringOrStringCopyValue();
|
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
structure::data::monoicon readMonoIconFields();
|
|
|
|
QString readMonoIconFilename();
|
|
|
|
|
2016-04-17 17:52:17 +00:00
|
|
|
// Read next token and fire unexpected token error if it is not of "type".
|
|
|
|
using BasicToken = common::BasicTokenizedFile::Token;
|
|
|
|
BasicToken assertNextToken(BasicToken::Type type);
|
|
|
|
|
2016-04-17 13:22:00 +00:00
|
|
|
// Look through include directories in options_ and find absolute include path.
|
|
|
|
Options includedOptions(const QString &filepath);
|
|
|
|
|
|
|
|
// Compose context-dependent full name.
|
|
|
|
structure::FullName composeFullName(const QString &name);
|
2016-04-16 17:51:25 +00:00
|
|
|
|
2016-04-20 12:59:25 +00:00
|
|
|
QString filePath_;
|
2016-04-16 17:51:25 +00:00
|
|
|
common::BasicTokenizedFile file_;
|
2016-04-17 09:30:14 +00:00
|
|
|
Options options_;
|
|
|
|
bool failed_ = false;
|
2016-04-18 20:33:43 +00:00
|
|
|
ModulePtr module_;
|
2016-04-17 09:30:14 +00:00
|
|
|
|
2016-04-17 13:22:00 +00:00
|
|
|
QMap<std::string, structure::Type> typeNames_ = {
|
|
|
|
{ "int" , { structure::TypeTag::Int } },
|
|
|
|
{ "double" , { structure::TypeTag::Double } },
|
|
|
|
{ "pixels" , { structure::TypeTag::Pixels } },
|
|
|
|
{ "string" , { structure::TypeTag::String } },
|
|
|
|
{ "color" , { structure::TypeTag::Color } },
|
|
|
|
{ "point" , { structure::TypeTag::Point } },
|
|
|
|
{ "size" , { structure::TypeTag::Size } },
|
|
|
|
{ "align" , { structure::TypeTag::Align } },
|
|
|
|
{ "margins" , { structure::TypeTag::Margins } },
|
|
|
|
{ "font" , { structure::TypeTag::Font } },
|
2016-05-27 13:56:35 +00:00
|
|
|
{ "icon" , { structure::TypeTag::Icon } },
|
2016-04-17 13:22:00 +00:00
|
|
|
};
|
|
|
|
|
2016-04-16 17:51:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace style
|
|
|
|
} // namespace codegen
|