GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
DebugEmitter.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 * You acknowledge that this software is not designed or intended for use
33 * in the design, construction, operation or maintenance of any nuclear
34 * facility.
35 *
36 * Sun gratefully acknowledges that this software was originally authored
37 * and developed by Kenneth Bradley Russell and Christopher John Kline.
38 */
39
40package com.jogamp.gluegen;
41
42import java.io.IOException;
43import java.util.*;
44
45import com.jogamp.gluegen.cgram.types.*;
46
47/** Debug emitter which prints the parsing results to standard output. */
48
49public class DebugEmitter implements GlueEmitter {
51
52 @Override
53 public void readConfigurationFile(final String filename) throws IOException {
54 cfg = createConfig();
55 cfg.read(filename);
56 }
57
58 @Override
59 public JavaConfiguration getConfig() { return cfg; }
60
61 @Override
62 public void beginEmission(final GlueEmitterControls controls) {
63 System.out.println("----- BEGIN EMISSION OF GLUE CODE -----");
64 }
65
66 @Override
67 public void endEmission() {
68 System.out.println("----- END EMISSION OF GLUE CODE -----");
69 }
70
71 @Override
72 public void beginDefines() {}
73
74 @Override
75 public void emitDefine(final ConstantDefinition def, final String optionalComment) {
76 final String name = def.getName();
77 final String value = def.getNativeExpr();
78 System.out.println("#define " + name + " " + value +
79 (optionalComment != null ? ("// " + optionalComment) : ""));
80 }
81 @Override
82 public void endDefines() {}
83
84 @Override
85 public void beginFunctions(final TypeDictionary typedefDictionary,
86 final TypeDictionary structDictionary,
87 final Map<Type, Type> canonMap,
88 List<FunctionSymbol> cFunctions) {
89 final Set<String> keys = typedefDictionary.keySet();
90 for (final String key: keys) {
91 final Type value = typedefDictionary.get(key);
92 System.out.println("typedef " + value + " " + key + ";");
93 }
94 }
95
96 @Override
97 public Iterator<FunctionSymbol> emitFunctions(final List<FunctionSymbol> originalCFunctions) throws Exception {
98 for (final FunctionSymbol sym : originalCFunctions) {
100 }
101 return originalCFunctions.iterator();
102 }
103 public void emitSingleFunction(final FunctionSymbol sym) {
104 System.out.println(sym);
105 System.out.println(" -> " + sym.toString());
106 }
107 @Override
108 public void endFunctions() {}
109
110 @Override
111 public void beginStructLayout() throws Exception {}
112 @Override
113 public void layoutStruct(final CompoundType t) throws Exception {}
114 @Override
115 public void endStructLayout() throws Exception {}
116
117 @Override
118 public void beginStructs(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, final Map<Type, Type> canonMap) {
119 }
120
121 @Override
122 public void emitStruct(final CompoundType t, final Type typedefType) {
123 String name = t.getName();
124 if (name == null && typedefType != null) {
125 name = typedefType.getName();
126 }
127
128 System.out.println("Referenced type \"" + name + "\"");
129 }
130
131 @Override
132 public void endStructs() {}
133
134 /**
135 * Create the object that will read and store configuration information for
136 * this JavaEmitter.
137 */
139 return new JavaConfiguration();
140 }
141
142}
Represents a [native] constant expression, comprises the [native] expression, see getNativeExpr() and...
String getNativeExpr()
Returns the original [native] expression.
Debug emitter which prints the parsing results to standard output.
Iterator< FunctionSymbol > emitFunctions(final List< FunctionSymbol > originalCFunctions)
Emit glue code for the list of FunctionSymbols.
void beginStructLayout()
Begins the process of computing field offsets and type sizes for the structs to be emitted.
void emitDefine(final ConstantDefinition def, final String optionalComment)
void emitSingleFunction(final FunctionSymbol sym)
void beginEmission(final GlueEmitterControls controls)
Begin the emission of glue code.
void readConfigurationFile(final String filename)
void beginStructs(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, final Map< Type, Type > canonMap)
void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, final Map< Type, Type > canonMap, List< FunctionSymbol > cFunctions)
void emitStruct(final CompoundType t, final Type typedefType)
Emit glue code for the given CompoundType.
void endStructLayout()
Finishes the struct layout process.
void endEmission()
Finish the emission of glue code.
JavaConfiguration createConfig()
Create the object that will read and store configuration information for this JavaEmitter.
void layoutStruct(final CompoundType t)
Lays out one struct which will be emitted later.
JavaConfiguration getConfig()
Parses and provides access to the contents of .cfg files for the JavaEmitter.
final void read(final String filename)
Reads the configuration file.
String getName()
Return the current-name, which is the last renamed-name if issued, or the original-name.
Models all compound types, i.e., those containing fields: structs and unions.
Describes a function symbol, which includes the name and type.
Utility class for recording names of typedefs and structs.
Type get(final String name)
Get the type corresponding to the given name.
Set< String > keySet()
Get all the names that map to Types.
final String getName()
Returns the name of this type.
Definition: Type.java:142
Specifies the interface by which a GlueEmitter can request additional information from the glue gener...
Specifies the interface by which GlueGen requests glue code to be generated.
String getName()
Return the current-name, which is the last renamed-name if issued, or the original-name.