📄 language.naming.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>Option Naming Convention</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="The eCos Component Writer's Guide"HREF="cdl-guide.html"><LINKREL="UP"TITLE="The CDL Language"HREF="language.html"><LINKREL="PREVIOUS"TITLE="CDL Properties"HREF="language.properties.html"><LINKREL="NEXT"TITLE="An Introduction to Tcl"HREF="language.tcl.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">The <SPANCLASS="APPLICATION">eCos</SPAN> Component Writer's Guide</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="language.properties.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 3. The CDL Language</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="language.tcl.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="LANGUAGE.NAMING">Option Naming Convention</H1><P>All the options in a given configuration live in the same namespace.Furthermore it is not possible for two separate options to have thesame name, because this would make any references to those options in<SPANCLASS="APPLICATION">CDL</SPAN> expressions ambiguous. A naming convention exists to avoidproblems. It is recommended that component writers observe some or allof this convention to reduce the probability of name clashes withother packages.</P><P>There is an important restriction on option names. Typically thecomponent framework will output a <TTCLASS="LITERAL">#define</TT> for everyactive and enabled option, using the name as the symbol being defined.This requires that all names are valid C preprocessor symbols, alimitation that is enforced even for options which have the<SPANCLASS="PROPERTY">no_define</SPAN> property. Preprocessor symbols can be any sequence oflower case letters <TTCLASS="LITERAL">a</TT>-<TTCLASS="LITERAL">z</TT>, uppercase letters, <TTCLASS="LITERAL">A</TT>-<TTCLASS="LITERAL">Z</TT>, theunderscore character <TTCLASS="LITERAL">_</TT>, and the digits<TTCLASS="LITERAL">0</TT>-<TTCLASS="LITERAL">9</TT>. The first character must bea non-digit. Using an underscore as the first character isdiscouraged, because that may clash with reserved languageidentifiers. In addition there is a convention that preprocessorsymbols only use upper case letters, and some component writers maywish to follow this convention.</P><P>A typical option name could be something like<TTCLASS="VARNAME">CYGSEM_KERNEL_SCHED_BITMAP</TT>. This name consists ofseveral different parts:</P><P></P><OLTYPE="1"><LI><P>The first few characters, in this case the three letters<TTCLASS="LITERAL">CYG</TT>, are used to identify the organization thatproduced the package. For historical reasons packages produced by RedHat tend to use the prefix <TTCLASS="LITERAL">CYG</TT> rather than<TTCLASS="LITERAL">RHAT</TT>. Component writers should use their ownprefix: even when cutting and pasting from an existing <SPANCLASS="APPLICATION">CDL</SPAN> scriptthe prefix should be changed to something appropriate to theirorganization. </P><P>It can be argued that a short prefix, often limited to upper caseletters, is not sufficiently long to eliminate the possibility ofname clashes. A longer prefix could be used, for example one based oninternet domain names. However the C preprocessor has no concept ofnamespaces or <TTCLASS="LITERAL">import</TT> directives, so it would alwaysbe necessary to use the full option name in component source codewhich gets tedious - option names tend to be long enough as it is.There is a small increased risk of name clashes, but this risk is feltto be acceptable.</P></LI><LI><P>The next three characters indicate the nature of the option, forexample whether it affects the interface or just the implementation. Alist of common tags is given below.</P></LI><LI><P>The <TTCLASS="LITERAL">KERNEL_SCHED</TT> part indicates the location of theoption within the overall hierarchy. In this case the option is part ofthe scheduling component of the kernel package. Having the hierarchydetails as part of the option name can help in understandingconfigurable code and further reduces the probability of a name clash.</P></LI><LI><P>The final part, <TTCLASS="LITERAL">BITMAP</TT>, identifies the optionitself. </P></LI></OL><P>The three-character tag is intended to provide some additionalinformation about the nature of the option. There are a number ofpre-defined tags. However for many options there is a choice:options related to the platform should normally use<TTCLASS="LITERAL">HWR</TT>, but numerical options should normally use<TTCLASS="LITERAL">NUM</TT>; a platform-related numerical option such asthe size of an interrupt stack could therefore use either tag.There are no absolute rules, and it is left to component writers tointerpret the following guidelines:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">xxxARC_</TT></DT><DD><P>The <TTCLASS="LITERAL">ARC</TT> tag is intended for options relatedto the processor architecture. Typically such options will only occurin architectural or variant HAL packages.</P></DD><DT><TTCLASS="LITERAL">xxxHWR_</TT></DT><DD><P>The <TTCLASS="LITERAL">HWR</TT> tag is intended for options related tothe specific target board. Typically such options will only occur inplatform HAL packages.</P></DD><DT><TTCLASS="LITERAL">xxxPKG_</TT></DT><DD><P>This tag is intended for packages or components, in other wordsoptions which extend the configuration hierarchy. Arguably a<TTCLASS="LITERAL">COM</TT> tag would be more appropriate forcomponents, but this could be confusing because of the considerablenumber of computing terms that begin with com.</P></DD><DT><TTCLASS="LITERAL">xxxGLO_</TT></DT><DD><P>This is intended for global configuration options, especiallypreferences.</P></DD><DT><TTCLASS="LITERAL">xxxDBG_</TT></DT><DD><P>The <TTCLASS="LITERAL">DBG</TT> tag indicates that the option is insome way related to debugging, for example it may enable assertions insome part of the system.</P></DD><DT><TTCLASS="LITERAL">xxxTST_</TT></DT><DD><P>This tag is for testing-related options. Typically these do notaffect actual application code, instead they control the interactionbetween target-side test cases and a host-side testing infrastructure.</P></DD><DT><TTCLASS="LITERAL">xxxFUN_</TT></DT><DD><P>This is for configuration options which affect the interface of apackage. There are a number of related tag which are alsointerface-related. <TTCLASS="LITERAL">xxxFUN_</TT> is intended primarilyfor options that control whether or not one or more functions areprovided by the package, but can also be used if none of the otherinterface-related tags is applicable.</P></DD><DT><TTCLASS="LITERAL">xxxVAR_</TT></DT><DD><P>This is analogous to <TTCLASS="LITERAL">FUN</TT> but controls the presenceor absence of one or more variables or objects.</P></DD><DT><TTCLASS="LITERAL">xxxCLS_</TT></DT><DD><P>The <TTCLASS="LITERAL">CLS</TT> tag is intended only for packages thatprovide an object-oriented interface, and controls the presence orabsence of an entire class.</P></DD><DT><TTCLASS="LITERAL">xxxMFN_</TT></DT><DD><P>This is also for object-orientated interfaces, and indicates thepresence or absence of a member function rather than an entire class.</P></DD><DT><TTCLASS="LITERAL">xxxSEM_</TT></DT><DD><P>A <TTCLASS="LITERAL">SEM</TT> option does not affect the interface (or ifdoes affect the interface, this is incidental). Instead it is used foroptions which have a fundamental effect on the semantic behavior of apackage. For example the choice of kernel schedulers is semantic innature: it does not affect the interface, in particular the function<TTCLASS="FUNCTION">cyg_thread_create</TT> exists irrespective of whichscheduler has been selected. However it does have a major impact onthe system's behavior.</P></DD><DT><TTCLASS="LITERAL">xxxIMP_</TT></DT><DD><P><TTCLASS="LITERAL">IMP</TT> is for implementation options. These do notaffect either the interface or the semantic behavior (with thepossible exception of timing-related changes). A typicalimplementation option controls whether or not a particular function orset of functions should get inlined.</P></DD><DT><TTCLASS="LITERAL">xxxNUM_</TT></DT><DD><P>This tag is for numerical options, for example the number ofscheduling priority levels.</P></DD><DT><TTCLASS="LITERAL">xxxDAT_</TT></DT><DD><P>This is for data items that are not numerical in nature, for example adevice name.</P></DD><DT><TTCLASS="LITERAL">xxxBLD_</TT></DT><DD><P>The <TTCLASS="LITERAL">BLD</TT> tag indicates an option that affectsthe build process, for example compiler flag settings.</P></DD><DT><TTCLASS="LITERAL">xxxINT_</TT></DT><DD><P>This should normally be used for <SPANCLASS="APPLICATION">CDL</SPAN> interfaces, which is a languageconstruct that is largely independent from the interface exported by apackage via its header files. For more details of <SPANCLASS="APPLICATION">CDL</SPAN> interfacessee <AHREF="language.interface.html">the Section called <I>Interfaces</I></A>.</P></DD><DT><TTCLASS="LITERAL">xxxPRI_</TT></DT><DD><P>This tag is not normally used for configuration options. Insteadit is used by <SPANCLASS="APPLICATION">CDL</SPAN> scripts to pass additional private information tothe source code via the configuration header files, typically inside a<SPANCLASS="PROPERTY">define_proc</SPAN> property.</P></DD><DT><TTCLASS="LITERAL">xxxSRC_</TT></DT><DD><P>This tag is not normally used for configuration options. Insteadit can be used by package source code to interact with such options,especially in the context of the <SPANCLASS="PROPERTY">if_define</SPAN> property.</P></DD></DL></DIV><P>There is one special case of a potential name clash that is worthmentioning here. When the component framework generates aconfiguration header file for a given package, by default it will usea name derived from the package name (the <SPANCLASS="PROPERTY">define_header</SPAN> property canbe used to override this). The file name is constructed from thepackage name by removing everything up to and including the firstunderscore, converting the remainder of the name to lower case, andappending a <TTCLASS="LITERAL">.h</TT> suffix. For example the kernelpackage <TTCLASS="VARNAME">CYGPKG_KERNEL</TT> will involve a header file<TTCLASS="FILENAME">pkgconf/kernel.h</TT>. If aconfiguration contained some other package<TTCLASS="VARNAME">XYZPKG_KERNEL</TT> then this would attempt to use thesame configuration header file, with unfortunate effects. Casesensitivity could introduce problems as well, so a package<TTCLASS="VARNAME">xyzpkg_kernel</TT> would involve the same problem. Evenif the header file names preserved the case of the package name, notall file systems are case sensitive. There is no simple solution tothis problem. Changing the names of the generated configuration headerfiles would involve a major incompatible change to the interface, tosolve a problem which is essentially hypothetical in nature.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="language.properties.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="cdl-guide.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="language.tcl.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">CDL Properties</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="language.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">An Introduction to Tcl</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -