4 This class is to generate a global table for the content of spd file.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.build
.global
;
17 import java
.util
.HashMap
;
18 import java
.util
.List
;
21 import org
.tianocore
.GuidDeclarationsDocument
.GuidDeclarations
;
22 import org
.tianocore
.IncludeHeaderDocument
.IncludeHeader
;
23 import org
.tianocore
.LibraryClassDeclarationDocument
.LibraryClassDeclaration
;
24 import org
.tianocore
.LibraryClassDeclarationsDocument
.LibraryClassDeclarations
;
25 import org
.tianocore
.PackageHeadersDocument
.PackageHeaders
;
26 import org
.tianocore
.PackageSurfaceAreaDocument
;
27 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
28 import org
.tianocore
.PpiDeclarationsDocument
.PpiDeclarations
;
29 import org
.tianocore
.PpiDeclarationsDocument
.PpiDeclarations
.Entry
;
30 import org
.tianocore
.ProtocolDeclarationsDocument
.ProtocolDeclarations
;
34 This class is to generate a global table for the content of spd file.
39 /// Map of module name and package it belongs to.
40 /// Key : Module BaseName
41 /// Value: Relative Path to Package
43 Map
<String
, String
[]> msaInfo
= new HashMap
<String
, String
[]>();
46 /// Map of module info.
48 /// Value: moduletype related include file
50 Map
<String
, String
> moduleInfo
= new HashMap
<String
, String
>();
55 /// value: String[] a. PPI C_NAME; b. PPI GUID;
57 Map
<String
, String
[]> ppiInfo
= new HashMap
<String
, String
[]>();
60 /// Map of Protocol info.
61 /// Key : Protocol name
62 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;
64 Map
<String
, String
[]> protocolInfo
= new HashMap
<String
, String
[]>();
69 /// value: String[] a. Guid C_NAME; b. Guid's GUID;
71 Map
<String
, String
[]> guidInfo
= new HashMap
<String
, String
[]>();
75 /// Map of library class and its exposed header file.
76 /// Key : library class name
77 /// value : library class corresponding header file
79 Map
<String
, String
> libClassHeaderList
= new HashMap
<String
, String
>();
84 String packagePath
= null;
89 This function mainly initialize some member variables.
91 @param spdDoc Handle of spd document.
92 @param spdPath Path of spd file.
94 Spd (PackageSurfaceAreaDocument spdDoc
, String spdPath
) {
96 PackageSurfaceArea spd
= spdDoc
.getPackageSurfaceArea();
97 this.packagePath
= spdPath
;
99 GuidDeclarations spdGuidInfo
= spd
.getGuidDeclarations();
100 genGuidInfoList(spdGuidInfo
);
102 PpiDeclarations spdPpiInfo
= spd
.getPpiDeclarations();
103 genPpiInfoList(spdPpiInfo
);
105 ProtocolDeclarations spdProtocolInfo
= spd
.getProtocolDeclarations();
106 genProtocolInfoList(spdProtocolInfo
);
108 LibraryClassDeclarations spdLibClassDeclare
= spd
109 .getLibraryClassDeclarations();
110 genLibClassDeclare(spdLibClassDeclare
);
112 PackageHeaders spdPackageHeaderInfo
= spd
.getPackageHeaders();
113 genModuleInfoList(spdPackageHeaderInfo
);
120 This function is to generate Module info map.
122 @param packageHeader The information of packageHeader which descripted
125 public void genModuleInfoList(PackageHeaders packageHeader
) {
127 if (packageHeader
!= null) {
128 List
<IncludeHeader
> headerList
= packageHeader
.getIncludeHeaderList();
129 IncludeHeader header
;
131 for (int i
= 0; i
< headerList
.size(); i
++) {
132 header
= (IncludeHeader
)headerList
.get(i
);
134 this.moduleInfo
.put(header
.getModuleType().toString(), header
.getStringValue());
135 } catch (Exception e
) {
136 System
.out
.print("can't find ModuleHeaders ModuleType & includeHeader!\n");
145 This function is to generate Ppi info map.
147 @param ppiInfo The information of PpiDeclarations which descripted
150 public void genPpiInfoList(PpiDeclarations ppiInfo
) {
151 String
[] cNameGuid
= new String
[2];
154 if (ppiInfo
!= null) {
155 List
<PpiDeclarations
.Entry
> ppiEntryList
= ppiInfo
.getEntryList();
156 PpiDeclarations
.Entry ppiEntry
;
158 for (int i
= 0; i
< ppiEntryList
.size(); i
++) {
159 ppiEntry
= (PpiDeclarations
.Entry
)ppiEntryList
.get(i
);
161 if (ppiEntry
.isSetGuidValue()) {
162 guidString
= ppiEntry
.getGuidValue();
164 guidString
= ppiEntry
.getGuid().getStringValue();
167 cNameGuid
[0] = ppiEntry
.getCName();
168 cNameGuid
[1] = formatGuidName(guidString
);
169 this.ppiInfo
.put(ppiEntry
.getName(), new String
[] { cNameGuid
[0], cNameGuid
[1] });
170 } catch (Exception e
) {
171 System
.out
.print("can't find GuidDeclarations C_Name & Guid!\n");
180 This function is to generate Protocol info map.
182 @param proInfo The information of ProtocolDeclarations which
183 descripted in spd file.
185 public void genProtocolInfoList(ProtocolDeclarations proInfo
) {
186 String
[] cNameGuid
= new String
[2];
189 if (proInfo
!= null) {
190 List
<ProtocolDeclarations
.Entry
> protocolEntryList
= proInfo
.getEntryList();
191 ProtocolDeclarations
.Entry protocolEntry
;
192 for (int i
= 0; i
< protocolEntryList
.size(); i
++) {
193 protocolEntry
= (ProtocolDeclarations
.Entry
)protocolEntryList
.get(i
);
195 if (protocolEntry
.isSetGuidValue()) {
196 guidString
= protocolEntry
.getGuidValue();
198 guidString
= protocolEntry
.getGuid().getStringValue();
200 cNameGuid
[0] = protocolEntry
.getCName();
201 cNameGuid
[1] = formatGuidName(guidString
);
203 String temp
= new String(protocolEntry
.getName());
204 this.protocolInfo
.put(temp
, new String
[] { cNameGuid
[0], cNameGuid
[1] });
205 } catch (Exception e
) {
206 System
.out
.print("can't find ProtocolDeclarations C_Name & Guid!\n");
215 This function is to generate GUID inf map.
217 @param guidInfo The information of GuidDeclarations which descripted
221 public void genGuidInfoList(GuidDeclarations guidInfo
) {
222 String
[] cNameGuid
= new String
[2];
225 if (guidInfo
!= null) {
227 List
<GuidDeclarations
.Entry
> guidEntryList
= guidInfo
.getEntryList();
228 GuidDeclarations
.Entry guidEntry
;
229 for (int i
= 0; i
< guidEntryList
.size(); i
++) {
230 guidEntry
= (GuidDeclarations
.Entry
)guidEntryList
.get(i
);
231 if (guidEntry
.isSetGuidValue()) {
232 guidString
= guidEntry
.getGuidValue();
234 guidString
= guidEntry
.getGuid().getStringValue();
237 cNameGuid
[0] = guidEntry
.getCName();
238 cNameGuid
[1] = formatGuidName(guidString
);
239 this.guidInfo
.put(guidEntry
.getName(), new String
[] {cNameGuid
[0], cNameGuid
[1] });
247 This function is to generate the libClassHeader list.
249 @param libClassDeclares The information of LibraryClassDeclarations which
250 descripted in spd file.
252 public void genLibClassDeclare(LibraryClassDeclarations libClassDeclares
) {
253 if (libClassDeclares
!= null && libClassDeclares
.getLibraryClassDeclarationList() != null) {
254 if (libClassDeclares
.getLibraryClassDeclarationList().size() > 0) {
255 List
<LibraryClassDeclaration
> libDeclareList
= libClassDeclares
.getLibraryClassDeclarationList();
256 for (int i
= 0; i
< libDeclareList
.size(); i
++) {
257 libClassHeaderList
.put(libDeclareList
.get(i
).getLibraryClass()
258 .getStringValue(), libDeclareList
.get(i
)
259 .getIncludeHeader().getStringValue());
268 This function is to get ppi GUID according ppi name.
270 @param ppiStr Name of ppi.
273 public String
getPpiGuid(String ppiStr
) {
274 if (ppiInfo
.get(ppiStr
) != null) {
275 return ppiInfo
.get(ppiStr
)[1];
285 This function is to get the ppi CName and it's GUID according to ppi name.
287 @param ppiName Name of ppi.
288 @return Ppi CName and it's GUID.
290 public String
[] getPpiCnameGuidArray(String ppiName
) {
291 return this.ppiInfo
.get(ppiName
);
297 This function is to get the protocol GUID according to protocol's name.
299 @param protocolStr Name of protocol.
300 @return Protocol's GUID.
302 public String
getProtocolGuid(String protocolStr
) {
303 if (protocolInfo
.get(protocolStr
) != null) {
304 return this.protocolInfo
.get(protocolStr
)[0];
311 getProtocolNameGuidArray
313 This function is to get the protocol's CName ant it's GUID according to
316 @param protocolName Name of protocl.
317 @return Protocol's CName and it's GUID.
319 public String
[] getProtocolNameGuidArray(String protocolName
) {
320 return this.protocolInfo
.get(protocolName
);
326 This function is to get the GUID according to GUID's name
328 @param guidStr Name of GUID
331 public String
getGUIDGuid(String guidStr
) {
332 if (guidInfo
.get(guidStr
) != null) {
333 return guidInfo
.get(guidStr
)[1];
343 This function is to get the GUID's CName and it's GUID according to
346 @param guidName Name of GUID
347 @return CName and GUID.
349 public String
[] getGuidNameArray(String guidName
) {
350 return this.guidInfo
.get(guidName
);
356 This function is to get the library exposed header file name according
359 @param libName Name of library class
360 @return Name of header file
362 String
getLibClassIncluder(String libName
) {
363 return libClassHeaderList
.get(libName
);
367 getModuleTypeIncluder
369 This function is to get the header file name from module info map
370 according to module type.
372 @param moduleType Module type.
373 @return Name of header file.
375 String
getModuleTypeIncluder(String moduleType
) {
376 return moduleInfo
.get(moduleType
);
382 This function is to formate GUID to ANSI c form.
384 @param guidNameCon String of GUID.
385 @return Formated GUID.
387 public static String
formatGuidName (String guidNameConv
) {
392 .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {
393 strList
= guidNameConv
.split("-");
394 guid
= "0x" + strList
[0] + ", ";
395 guid
= guid
+ "0x" + strList
[1] + ", ";
396 guid
= guid
+ "0x" + strList
[2] + ", ";
398 guid
= guid
+ "0x" + strList
[3].substring(0, 2) + ", ";
399 guid
= guid
+ "0x" + strList
[3].substring(2, 4);
401 while (index
< strList
[4].length()) {
403 guid
= guid
+ "0x" + strList
[4].substring(index
, index
+ 2);
408 } else if (guidNameConv
409 .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {
410 strList
= guidNameConv
.split(",");
413 // chang Microsoft specific form to ANSI c form
415 for (int i
= 0; i
< 3; i
++){
416 guid
= guid
+ strList
[i
] + ",";
420 for (int i
= 3; i
< strList
.length
; i
++){
421 if (i
== strList
.length
- 1){
422 guid
= guid
+ strList
[i
];
424 guid
= guid
+ strList
[i
] + ",";
430 System
.out
.println("Check GUID Value, it don't conform to the schema!!!");