Switch yang-ir to bnd-parent
[yangtools.git] / parser / yang-ir / src / main / java / org / opendaylight / yangtools / yang / ir / IOConstantsV1.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.ir;
9
10 /**
11  * Simplistic coding, without any real magic bit reuse. The idea is that each statement is in the form:
12  * <pre>{@code HEADER LINE COLUMN KEYWORD [ARGUMENT] [SUBSTATEMENTS]}</pre>
13  *
14  * <p>
15  * The {@code HEADER} is always a single byte, internally composed of four bitfields:
16  * <pre>
17  * +---+---+---+---+---+---+---+---+
18  * |  KW TYPE  | SIZE  |ARG|  L6N  |
19  * +---+---+---+---+---+---+---+---+
20  * </pre>
21  *
22  * <p>
23  * The {@code LINE} and {@code COLUMN} are variable size, indicated by the {@code L6N} bits:
24  * <ul>
25  *   <li>{@link #HDR_LOCATION_22} indicates u16 for LINE and u16 for COLUMN</li>
26  *   <li>{@link #HDR_LOCATION_31} indicates u24 for LINE and u8 for COLUMN</li>
27  *   <li>{@link #HDR_LOCATION_44} indicates s32 for LINE and s32 for COLUMN</li>
28  * </ul>
29  *
30  * <p>
31  * The {@code KEYWORD} is variable-format based on {@code KW TYPE} bits:
32  * <ul>
33  *   <li>{@link #HDR_KEY_DEF_QUAL} indicates a new definition, which is composed of two {@code STRING}s</li>
34  *   <li>{@link #HDR_KEY_DEF_UQUAL} indicates a new definition, which is composed of a single {@code STRING}</li>
35  *   <li>{@link #HDR_KEY_REF_U8} indicates a reference identified by a u8 integer</li>
36  *   <li>{@link #HDR_KEY_REF_U16} indicates a reference identified by a u16 integer</li>
37  *   <li>{@link #HDR_KEY_REF_S32} indicates a reference identified by a s32 integer</li>
38  * </ul>
39  * Once defined, each keyword can be referenced by encoding a reference with a linear counter of definition. I.e.
40  * the first definition is {@code 0}, the second is {@code 1}, etc.
41  *
42  * <p>
43  * The {@code ARGUMENT} is present only when indicated by {@link #HDR_ARGUMENT_PRESENT}. If it is present, it has
44  * variable encoding in form
45  * <pre>{@code ARGHDR [...]}</pre>
46  */
47 final class IOConstantsV1 {
48     // Statement indicator: indicates line/column split
49     static final int HDR_LOCATION_22       = 0x01;
50     static final int HDR_LOCATION_31       = 0x02;
51     static final int HDR_LOCATION_44       = 0x03;
52     static final int HDR_LOCATION_MASK     = HDR_LOCATION_44;
53     // Argument presence
54     static final int HDR_ARGUMENT_ABSENT   = 0x00;
55     static final int HDR_ARGUMENT_PRESENT  = 0x04;
56     static final int HDR_ARGUMENT_MASK     = HDR_ARGUMENT_PRESENT;
57     // Child statement size
58     static final int HDR_SIZE_0            = 0x00;
59     static final int HDR_SIZE_U8           = 0x08;
60     static final int HDR_SIZE_U16          = 0x10;
61     static final int HDR_SIZE_S32          = 0x18;
62     static final int HDR_SIZE_MASK         = HDR_SIZE_S32;
63     // Keyword indication
64     static final int HDR_KEY_DEF_UQUAL     = 0x00;
65     static final int HDR_KEY_DEF_QUAL      = 0x20;
66     // 0x40 reserved
67     // 0x60 reserved
68     // 0x80 reserved
69     static final int HDR_KEY_REF_U8        = 0xA0;
70     static final int HDR_KEY_REF_U16       = 0xC0;
71     static final int HDR_KEY_REF_S32       = 0xE0;
72     static final int HDR_KEY_MASK          = HDR_KEY_REF_S32;
73
74     static final int ARG_TYPE_IDENTIFIER   = 0x01;
75     static final int ARG_TYPE_DQUOT        = 0x02;
76     static final int ARG_TYPE_SQUOT        = 0x03;
77     static final int ARG_TYPE_UQUOT        = 0x04;
78     static final int ARG_TYPE_CONCAT_U8    = 0x05;
79     static final int ARG_TYPE_CONCAT_U16   = 0x06;
80     static final int ARG_TYPE_CONCAT_S32   = 0x07;
81     static final int ARG_TYPE_MASK         = ARG_TYPE_CONCAT_S32;
82
83     static final int STR_DEF_UTF           = 0x00; // writeUTF(), <16384
84     static final int STR_DEF_U8            = 0x10; // byte + UTF
85     static final int STR_DEF_U16           = 0x20; // short + UTF
86     static final int STR_DEF_S32           = 0x30; // int + UTF
87     static final int STR_DEF_CHARS         = 0x40; // writeChars()
88     static final int STR_REF_U8            = 0x50;
89     static final int STR_REF_U16           = 0x60;
90     static final int STR_REF_S32           = 0x70;
91     static final int STR_MASK              = STR_REF_S32;
92
93     private IOConstantsV1() {
94         // Hidden on purpose
95     }
96 }