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
19 #include "util.h"
20
21 int FixedField::unique_id_ = 0;
22
FixedField(std::string name,int size,ParseLocation loc)23 FixedField::FixedField(std::string name, int size, ParseLocation loc)
24 : ScalarField(name + std::to_string(unique_id_++), size, loc) {}
25
GenGetter(std::ostream & s,Size start_offset,Size end_offset) const26 void FixedField::GenGetter(std::ostream& s, Size start_offset, Size end_offset) const {
27 s << "protected:";
28 ScalarField::GenGetter(s, start_offset, end_offset);
29 s << "public:\n";
30 }
31
GetBuilderParameterType() const32 std::string FixedField::GetBuilderParameterType() const { return ""; }
33
GenBuilderParameter(std::ostream &) const34 bool FixedField::GenBuilderParameter(std::ostream&) const {
35 // No parameter needed for a fixed field.
36 return false;
37 }
38
HasParameterValidator() const39 bool FixedField::HasParameterValidator() const { return false; }
40
GenParameterValidator(std::ostream &) const41 void FixedField::GenParameterValidator(std::ostream&) const {
42 // No parameter validator needed for a fixed field.
43 }
44
GenInserter(std::ostream & s) const45 void FixedField::GenInserter(std::ostream& s) const {
46 s << "insert(";
47 GenValue(s);
48 s << ", i , " << GetSize().bits() << ");";
49 }
50
GenValidator(std::ostream & s) const51 void FixedField::GenValidator(std::ostream& s) const {
52 s << "if (Get" << util::UnderscoreToCamelCase(GetName()) << "() != ";
53 GenValue(s);
54 s << ") return false;";
55 }
56