• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015 PLUMgrid, Inc.
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 <stdio.h>
18 #include <vector>
19 #include <string>
20 
21 #include "node.h"
22 
23 namespace ebpf {
24 namespace cc {
25 
26 #define ACCEPT(type, func) \
27   STATUS_RETURN type::accept(Visitor* v) { return v->visit_##func(this); }
EXPAND_NODES(ACCEPT)28 EXPAND_NODES(ACCEPT)
29 #undef ACCEPT
30 
31 VariableDeclStmtNode* StructDeclStmtNode::field(const string& name) const {
32   for (auto it = stmts_.begin(); it != stmts_.end(); ++it) {
33     if ((*it)->id_->name_ == name) {
34       return it->get();
35     }
36   }
37   return NULL;
38 }
39 
indexof(const string & name) const40 int StructDeclStmtNode::indexof(const string& name) const {
41   int i = 0;
42   for (auto it = stmts_.begin(); it != stmts_.end(); ++it, ++i) {
43     if ((*it)->id_->name_ == name) {
44       return i;
45     }
46   }
47   return -1;
48 }
49 
50 }  // namespace cc
51 }  // namespace ebpf
52