1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ideHelpersProto.h"
17
18 namespace panda::proto {
Serialize(const panda::pandasm::SourceLocation & location,protoPanda::SourceLocation & protoLocation)19 void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location,
20 protoPanda::SourceLocation &protoLocation)
21 {
22 auto *protoBegin = protoLocation.mutable_begin();
23 SourcePosition::Serialize(location.begin, *protoBegin);
24 auto *protoEnd = protoLocation.mutable_end();
25 SourcePosition::Serialize(location.end, *protoEnd);
26 }
27
Deserialize(const protoPanda::SourceLocation & protoLocation,panda::pandasm::SourceLocation & location)28 void SourceLocation::Deserialize(const protoPanda::SourceLocation &protoLocation,
29 panda::pandasm::SourceLocation &location)
30 {
31 if (protoLocation.has_begin()) {
32 SourcePosition::Deserialize(protoLocation.begin(), location.begin);
33 }
34 if (protoLocation.has_end()) {
35 SourcePosition::Deserialize(protoLocation.end(), location.end);
36 }
37 }
38
Serialize(const panda::pandasm::SourcePosition & position,protoPanda::SourcePosition & protoPosition)39 void SourcePosition::Serialize(const panda::pandasm::SourcePosition &position,
40 protoPanda::SourcePosition &protoPosition)
41 {
42 protoPosition.set_line(position.line);
43 protoPosition.set_column(position.column);
44 }
45
Deserialize(const protoPanda::SourcePosition & protoPosition,panda::pandasm::SourcePosition & position)46 void SourcePosition::Deserialize(const protoPanda::SourcePosition &protoPosition,
47 panda::pandasm::SourcePosition &position)
48 {
49 position.line = protoPosition.line();
50 position.column = protoPosition.column();
51 }
52 } // panda::proto
53