1 /*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "fields/fixed_field.h"
18 #include "util.h"
19
20 int FixedField::unique_id_ = 0;
21
FixedField(std::string name,int size,ParseLocation loc)22 FixedField::FixedField(std::string name, int size, ParseLocation loc)
23 : ScalarField(name + std::to_string(unique_id_++), size, loc) {}
24
GenGetter(std::ostream & s,Size start_offset,Size end_offset) const25 void FixedField::GenGetter(std::ostream& s, Size start_offset, Size end_offset) const {
26 s << "protected:";
27 ScalarField::GenGetter(s, start_offset, end_offset);
28 s << "public:\n";
29 }
30
GetBuilderParameterType() const31 std::string FixedField::GetBuilderParameterType() const {
32 return "";
33 }
34
GenBuilderParameter(std::ostream &) const35 bool FixedField::GenBuilderParameter(std::ostream&) const {
36 // No parameter needed for a fixed field.
37 return false;
38 }
39
HasParameterValidator() const40 bool FixedField::HasParameterValidator() const {
41 return false;
42 }
43
GenParameterValidator(std::ostream &) const44 void FixedField::GenParameterValidator(std::ostream&) const {
45 // No parameter validator needed for a fixed field.
46 }
47
GenInserter(std::ostream & s) const48 void FixedField::GenInserter(std::ostream& s) const {
49 s << "insert(";
50 GenValue(s);
51 s << ", i , " << GetSize().bits() << ");";
52 }
53
GenValidator(std::ostream & s) const54 void FixedField::GenValidator(std::ostream& s) const {
55 s << "if (Get" << util::UnderscoreToCamelCase(GetName()) << "() != ";
56 GenValue(s);
57 s << ") return false;";
58 }
59