Debian Codegraph @

src/core/ulib_doc.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // file: ulib_doc.h
28 // desc: class library and API for built-in CKDoc documentation system
29 // based on the OG 'ckdoc' utility by Spencer Salazar
30 //
31 // author: Spencer Salazar ([email protected])
32 // Ge Wang ([email protected] | [email protected])
33 // date: Spring 2023
34 //-----------------------------------------------------------------------------
35 #ifndef __ULIB_DOC_H__
36 #define __ULIB_DOC_H__
37
38 #include "chuck_dl.h"
39 #include "chuck_absyn.h"
40
41 // ckdoc query
42 DLL_QUERY ckdoc_query( Chuck_DL_Query * QUERY );
43
44
45 // forward reference
46 struct Chuck_VM;
47 struct Chuck_Type;
48 struct ChucK_Func;
49 struct Chuck_Value;
50 struct CKDocGroup;
51 class CKDocHTMLOutput;
52
53 // URL to the chuck examples hosted @ Stanford
54 static std::string EXAMPLES_URL_BASE = "https://chuck.stanford.edu/doc/";
55
56
57
58 //-----------------------------------------------------------------------------
59 // name: class CKDocOutput | 1.5.0.0 (based on Spencer's ckdoc Output class)
60 // desc: abstract base class for doc output
61 //-----------------------------------------------------------------------------
62 class CKDocOutput
63 {
64 public:
65 // base constructor
66 CKDocOutput() { }
67 // virtual destructor
68 virtual ~CKDocOutput() { }
69
70 public:
71 // clear output string
72 void clear() { m_outputStr = ""; }
73 // get output string
74 const std::string & str() const { return m_outputStr; }
75 // get file name: ".html", ".txt", etc.
76 virtual std::string fileExtension() const { return ""; }
77 // render index
78 virtual std::string renderIndex( const std::string & indexTitle, const std::vector<CKDocGroup *> & groups ) { return ""; };
79
80 public:
81 virtual void begin(const std::string &title) = 0;
82 virtual void heading() = 0;
83 virtual void end() = 0;
84
85 // body
86 virtual void begin_body() = 0;
87 virtual void end_body() = 0;
88
89 // toc
90 virtual void begin_toc() = 0;
91 virtual void toc_class(Chuck_Type * type) = 0;
92 virtual void end_toc() = 0;
93
94 // classes
95 virtual void begin_classes( CKDocGroup * group ) = 0;
96 virtual void end_classes() = 0;
97
98 // one class
99 virtual void begin_class( Chuck_Type * type, const std::vector<CKDocGroup *> & groups ) = 0;
100
101 // examples
102 virtual void begin_examples() = 0;
103 virtual void example( const std::string & name, const std::string & url ) = 0;
104 virtual void end_examples() = 0;
105
106 // class variables
107 virtual void begin_static_member_vars() = 0;
108 virtual void end_static_member_vars() = 0;
109 virtual void begin_member_vars() = 0;
110 virtual void end_member_vars() = 0;
111
112 // class functions
113 virtual void begin_static_member_funcs() = 0;
114 virtual void end_static_member_funcs() = 0;
115 virtual void begin_ctors() = 0;
116 virtual void end_ctors() = 0;
117 virtual void begin_member_funcs() = 0;
118 virtual void end_member_funcs() = 0;
119
120 // individual vars
121 virtual void static_member_var( Chuck_Value * var ) = 0;
122 virtual void member_var( Chuck_Value * var ) = 0;
123
124 // individual funs
125 virtual void begin_static_member_func(Chuck_Func * func) = 0;
126 virtual void end_static_member_func() = 0;
127 virtual void begin_member_func(Chuck_Func * func) = 0;
128 virtual void end_member_func() = 0;
129 virtual void begin_ctor( Chuck_Func * func ) = 0;
130 virtual void end_ctor() = 0;
131
132 // func arguments
133 virtual void func_arg( a_Arg_List arg ) = 0;
134
135 // end class
136 virtual void end_class() = 0;
137
138 protected:
139 // output string
140 std::string m_outputStr;
141 };
142
143
144
145
146 //-----------------------------------------------------------------------------
147 // name: class CKDoc | 1.5.0.0 (ge, spencer)
148 // desc: CKDoc internal implementation, based on Spencer's CKDoc utility
149 //-----------------------------------------------------------------------------
150 class CKDoc
151 {
152 public:
153 // constructor
154 CKDoc( Chuck_VM * vm );
155 // destructor
156 ~CKDoc();
157
158 public:
159 // clear all added groups
160 void clearGroups();
161 // clear output generator
162 void clearOutput();
163 // add a group of types to document (Type A)
164 t_CKBOOL addGroup( const std::vector<Chuck_Type *> & types,
165 const std::string & name,
166 const std::string & shortName,
167 const std::string & description );
168 // add an external group of types to document (Type B) | 1.5.2.4 (ge) added
169 t_CKBOOL addGroupExt( const std::string & name,
170 const std::string & URL,
171 const std::string & description,
172 const std::string & longDesc );
173 // get number of groups
174 t_CKINT numGroups() const;
175 // set output format: CKDoc.HTML, CKDoc.TEXT, CKDoc.MARKDOWN, CKDoc.JSON
176 t_CKBOOL setOutputFormat( t_CKINT which );
177 // get output format
178 t_CKINT getOutputFormat() const;
179 // set base examples root path
180 void setExamplesRoot( const std::string & path );
181 // get base examples root path
182 std::string getExamplesRoot() const;
183
184 public:
185 // generate everything as files into the output directory
186 t_CKBOOL outputToDir( const std::string & outputDir, const std::string & indexTitle );
187 // generate top-level index file; return as string
188 std::string genIndex( const std::string & title );
189 // generate CSS; return as string
190 std::string genCSS();
191 // generate all added groups, return each in a separate entry
192 void genGroups( std::vector<std::string> & results );
193 // generate documentation for a group
194 std::string genGroup( CKDocGroup * group, t_CKBOOL clearOutput = TRUE );
195 // generate documentation for a single Type
196 std::string genType( Chuck_Type * type, t_CKBOOL clearOutput = TRUE );
197
198 public:
199 // whether to skip an entry in the final output | 1.5.4.5 (ge) added
200 static t_CKBOOL shouldSkip( const std::string & docStr );
201 // whether to skip a function in the final output | 1.5.4.5 (ge) added
202 static t_CKBOOL shouldSkip( const Chuck_Func * func );
203 // whether to skip an entry in the final output | 1.5.4.5 (ge) added
204 static t_CKBOOL shouldSkip( const Chuck_Value * var );
205
206 public:
207 // sort functions and variables | 1.5.2.5 (@kellyyyyyyyyyyyyyyyy @azaday) added
208 t_CKBOOL m_sort_entries;
209
210 public:
211 // enumeration for output format types
212 static const t_CKINT FORMAT_NONE; // no output format
213 static const t_CKINT FORMAT_HTML; // default
214 static const t_CKINT FORMAT_TEXT; // same as help
215 static const t_CKINT FORMAT_MARKDOWN; // not implemented
216 static const t_CKINT FORMAT_JSON; // not implemented
217
218 protected:
219 // write string to file
220 t_CKBOOL outputToFile( const std::string & filename, const std::string & content );
221
222 protected:
223 // literally ckdoc.css
224 static std::string m_ckdocCSS;
225
226 protected:
227 // groups
228 std::vector<CKDocGroup *> m_groups;
229 // examples root path
230 std::string m_examplesRoot;
231 // format
232 t_CKINT m_format;
233 // output reference
234 CKDocOutput * m_output;
235 // chuck VM reference
236 Chuck_VM * m_vm_ref;
237 };
238
239
240
241
242 #endif
243 //
244 //
245 //public:
246 // // generate CSS file
247 // t_CKBOOL outputCSS( const std::string & cssFilename );
248 // // generate an HTML file containing documentation for a list of classes
249 // t_CKBOOL outputHTMLGroup( const std::vector<Chuck_Type *> & clasess,
250 // const std::string & title,
251 // const std::string & htmlFilename,
252 // const std::string & cssFilename );
253 // // generate an HTML file containing index for a list of classes
254 // t_CKBOOL outputHTMLIndex( const std::vector<std::string> & clasess,
255 // const std::string & htmlFilename,
256 // const std::string & cssFilename );
257 // // generate HTML for a type
258 // t_CKBOOL outputHTMLType( const std::string & typeName, std::string & output );
259 // // generate an Markdown file containing documentation for a list of classes
260 // t_CKBOOL outputMarkdownGroup( const std::vector<std::string> & clasess,
261 // const std::string & mdFilename );
262 // // does this even make sense for Markdown?
263 // t_CKBOOL outputMarkdownIndex( const std::vector<std::string> & clasess,
264 // const std::string & mdFilename );