Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | # Copyright 2013, Big Switch Networks, Inc. |
| 2 | # |
| 3 | # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| 4 | # the following special exception: |
| 5 | # |
| 6 | # LOXI Exception |
| 7 | # |
| 8 | # As a special exception to the terms of the EPL, you may distribute libraries |
| 9 | # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| 10 | # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| 11 | # from the LoxiGen Libraries and the notice provided below is (i) included in |
| 12 | # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| 13 | # documentation for the LoxiGen Libraries, if distributed in binary form. |
| 14 | # |
| 15 | # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| 16 | # |
| 17 | # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| 18 | # a copy of the EPL at: |
| 19 | # |
| 20 | # http://www.eclipse.org/legal/epl-v10.html |
| 21 | # |
| 22 | # Unless required by applicable law or agreed to in writing, software |
| 23 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 25 | # EPL for the specific language governing permissions and limitations |
| 26 | # under the EPL. |
| 27 | |
| 28 | """ |
| 29 | This file needs significant work and normalization. We need a better |
| 30 | representation for flags, associating them to variables, and associating |
| 31 | them to OF versions. |
| 32 | |
| 33 | @fixme Most of this will be going away soon |
| 34 | """ |
| 35 | |
| 36 | import sys |
| 37 | import copy |
| 38 | import type_maps |
Andreas Wundsam | 542a13c | 2013-11-15 13:28:55 -0800 | [diff] [blame] | 39 | import c_gen.of_g_legacy as of_g |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 40 | import re |
| 41 | |
| 42 | # These mark idents as _not_ flags and have precedence |
| 43 | non_flag_rules = [ |
| 44 | "OF_CONFIG_FRAG_NORMAL", |
| 45 | "OF_FLOW_MOD_FAILED_BAD_FLAGS", |
| 46 | "OF_SWITCH_CONFIG_FAILED_BAD_FLAGS", |
| 47 | "OF_PORT_STATE_FLAG_STP_LISTEN", |
| 48 | "OF_TABLE_CONFIG_TABLE_MISS_CONTROLLER", |
| 49 | ] |
| 50 | |
| 51 | # These mark idents as flags |
| 52 | flag_rules = [ |
| 53 | "OF_CONFIG_", |
| 54 | "OF_TABLE_CONFIG_", |
| 55 | ] |
| 56 | |
| 57 | def ident_is_flag(ident): |
| 58 | """ |
| 59 | Return True if ident should be treated as a flag |
| 60 | """ |
| 61 | |
| 62 | # Do negative matches first |
| 63 | for entry in non_flag_rules: |
| 64 | if re.match(entry, ident): |
| 65 | return False |
| 66 | |
| 67 | # General rule, if it says flag it is (unless indicated above) |
| 68 | if ident.find("FLAG") >= 0: |
| 69 | return True |
| 70 | |
| 71 | for entry in flag_rules: |
| 72 | if re.match(entry, ident): |
| 73 | return True |
| 74 | |
| 75 | return False |