1 // *****************************************************************************
2 // *****************************************************************************
3 // Copyright 2013 - 2015, Cadence Design Systems
4 //
5 // This file is part of the Cadence LEF/DEF Open Source
6 // Distribution, Product Version 5.8.
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied. See the License for the specific language governing
18 // permissions and limitations under the License.
19 //
20 // For updates, support, or to become part of the LEF/DEF Community,
21 // check www.openeda.org for details.
22 //
23 // $Author: dell $
24 // $Revision: #1 $
25 // $Date: 2017/06/06 $
26 // $State: $
27 // *****************************************************************************
28 // *****************************************************************************
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include "lex.h"
33 #include "defiPropType.hpp"
34 #include "defiDebug.hpp"
35
36 BEGIN_LEFDEF_PARSER_NAMESPACE
37
38
defiPropType()39 defiPropType::defiPropType() {
40 Init();
41 }
42
43
Init()44 void defiPropType::Init() {
45 numProperties_ = 0;
46 propertiesAllocated_ = 0;
47 propNames_ = 0;
48 propTypes_ = 0;
49 }
50
51
Clear()52 void defiPropType::Clear() {
53 int i;
54
55 for (i = 0; i < numProperties_; i++) {
56 free(propNames_[i]);
57 }
58 numProperties_ = 0;
59 propertiesAllocated_ = 0;
60 }
61
62
Destroy()63 void defiPropType::Destroy() {
64 Clear();
65 if (propNames_)
66 free(propNames_);
67 if (propTypes_)
68 free(propTypes_);
69 }
70
71
~defiPropType()72 defiPropType::~defiPropType() {
73 Destroy();
74 }
75
76
setPropType(const char * name,const char type)77 void defiPropType::setPropType(const char* name, const char type) {
78 int len;
79
80 if (numProperties_ == propertiesAllocated_)
81 bumpProps();
82 len = strlen(name) + 1;
83 propNames_[numProperties_] = (char*)malloc(len);
84 strcpy(propNames_[numProperties_], name);
85 propTypes_[numProperties_] = type;
86 numProperties_ += 1;
87 }
88
89
bumpProps()90 void defiPropType::bumpProps() {
91 int lim = propertiesAllocated_;
92 int news ;
93 char** newpn;
94 char* newt;
95
96 news = lim ? lim + lim : 2;
97
98 newpn = (char**)malloc(sizeof(char*)*news);
99 newt = (char*)malloc(sizeof(char)*news);
100
101 lim = propertiesAllocated_ = news;
102
103 if (lim > 2) {
104 int i;
105 for (i = 0; i < numProperties_; i++) {
106 newpn[i] = propNames_[i];
107 newt[i] = propTypes_[i];
108 }
109 free((char*)(propNames_));
110 free((char*)(propTypes_));
111 }
112 propNames_ = newpn;
113 propTypes_ = newt;
114 }
115
116
propType(char * name) const117 char defiPropType::propType(char* name) const {
118 int i;
119
120 // Name is NULL, error
121 if (!name)
122 return('N');
123
124 for (i = 0; i < numProperties_; i++) {
125 if (strcmp(name, propNames_[i]) == 0)
126 return(propTypes_[i]); // found the prop name
127 }
128 return('N'); // Can't found the name
129 }
130 END_LEFDEF_PARSER_NAMESPACE
131
132