1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
6 #include "RuntimeMetaData.h"
8 using namespace antlr4;
10 const std::string RuntimeMetaData::VERSION = "4.9.2";
12 std::string RuntimeMetaData::getRuntimeVersion() {
16 void RuntimeMetaData::checkVersion(const std::string &generatingToolVersion, const std::string &compileTimeVersion) {
17 std::string runtimeVersion = VERSION;
18 bool runtimeConflictsWithGeneratingTool = false;
19 bool runtimeConflictsWithCompileTimeTool = false;
21 if (generatingToolVersion != "") {
22 runtimeConflictsWithGeneratingTool = runtimeVersion != generatingToolVersion
23 && getMajorMinorVersion(runtimeVersion) != getMajorMinorVersion(generatingToolVersion);
26 runtimeConflictsWithCompileTimeTool = runtimeVersion != compileTimeVersion
27 && getMajorMinorVersion(runtimeVersion) != getMajorMinorVersion(compileTimeVersion);
29 if (runtimeConflictsWithGeneratingTool) {
30 std::cerr << "ANTLR Tool version " << generatingToolVersion << " used for code generation does not match "
31 "the current runtime version " << runtimeVersion << std::endl;
33 if (runtimeConflictsWithCompileTimeTool) {
34 std::cerr << "ANTLR Runtime version " << compileTimeVersion << " used for parser compilation does not match "
35 "the current runtime version " << runtimeVersion << std::endl;
39 std::string RuntimeMetaData::getMajorMinorVersion(const std::string &version) {
40 size_t firstDot = version.find('.');
41 size_t secondDot = firstDot != std::string::npos ? version.find('.', firstDot + 1) : std::string::npos;
42 size_t firstDash = version.find('-');
43 size_t referenceLength = version.size();
44 if (secondDot != std::string::npos) {
45 referenceLength = std::min(referenceLength, secondDot);
48 if (firstDash != std::string::npos) {
49 referenceLength = std::min(referenceLength, firstDash);
52 return version.substr(0, referenceLength);