📄 language.values.html
字号:
>If an option is enabled then any references to that option in <SPANCLASS="APPLICATION">CDL</SPAN>expressions will evaluate to the option's data part. For two of theflavors, <TTCLASS="LITERAL">none</TT> and <TTCLASS="LITERAL">bool</TT>, thisdata part is fixed to the constant <TTCLASS="LITERAL">1</TT> whichgenerally has the expected result.</P></LI><LI><P>If a component or package is disabled then all sub-components andoptions immediately below it in the hierarchy are inactive. By aprocess of recursion this will affect all the nodes in the subtree.</P></LI><LI><P>If an option is disabled then it can impose no constraints on the restof the configuration, in particular <SPANCLASS="PROPERTY">requires</SPAN> and <SPANCLASS="PROPERTY">legal_values</SPAN>properties will be ignored. If an option is enabled then itsconstraints should be satisfied, or the component framework willreport various conflicts. Note that the <SPANCLASS="PROPERTY">legal_values</SPAN> constraint onlyapplies to the data part of the option's value, so it is only usefulwith the <TTCLASS="LITERAL">data</TT> and <TTCLASS="LITERAL">booldata</TT>flavors. Options with the <TTCLASS="LITERAL">none</TT> and<TTCLASS="LITERAL">data</TT> flavors are always enabled so theirconstraints always have to be satisfied (assuming the option isactive). </P></LI><LI><P>If an option is disabled then it has no direct consequences atbuild-time: no <TTCLASS="LITERAL">#define</TT> will be generated, no fileswill get compiled, and so on. If an option is active and enabled thenall the consequences take effect. The option name and data part areused to generate the <TTCLASS="LITERAL">#define</TT> in the appropriateconfiguration header file, subject to various properties such as<SPANCLASS="PROPERTY">no_define</SPAN>, but the data part has no other effects on the buildsystem. </P></LI></OL><P>By default all options and components have the <TTCLASS="LITERAL">bool</TT>flavor: most options are boolean in nature, so making this the defaultallows for slightly more compact <SPANCLASS="APPLICATION">CDL</SPAN> scripts. Packages have the<TTCLASS="LITERAL">booldata</TT> flavor, where the data part alwayscorresponds to the version of the package that is loaded into theconfiguration: changing this value corresponds to unloading the oldversion and loading in a different one.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B><SPANCLASS="APPLICATION">CDL</SPAN> Flavors: </B>The concept of <SPANCLASS="APPLICATION">CDL</SPAN> flavors tends to result in various discussionsabout why it is unnecessarily complicated, and would it not have beeneasier to do … However there are very good reasons why CDLworks the way it does.</P><P>The first common suggestion is that there is no need to have separateflavors <TTCLASS="LITERAL">bool</TT>, <TTCLASS="LITERAL">data</TT>, and so on. Aboolean option could just be handled as a data option with legalvalues <TTCLASS="LITERAL">0</TT> and <TTCLASS="LITERAL">1</TT>. The counterarguments are as follows:</P><P></P><OLTYPE="1"><LI><P>It would actually make <SPANCLASS="APPLICATION">CDL</SPAN> scripts more verbose. By default alloptions and components have the <TTCLASS="LITERAL">bool</TT> flavor, sincemost options are boolean in nature. Without a <TTCLASS="LITERAL">bool</TT>flavor it would be necessary to indicate explicitly what the legalvalues are somehow, e.g. with a <SPANCLASS="PROPERTY">legal_values</SPAN> property.</P></LI><LI><P>The boolean part of an option's value has a very different effect fromthe data part. If an option is disabled then it has no consequences atbuild time, and can impose no constraints. A <TTCLASS="LITERAL">data</TT>option always has consequences and can impose constraints. To get thedesired effect it would be necessary to add <SPANCLASS="APPLICATION">CDL</SPAN> data indicating thata value of <TTCLASS="LITERAL">0</TT> should be treated specially. Arguablythis could be made built-in default behavior, although that wouldcomplicate options where <TTCLASS="LITERAL">0</TT> is a perfectly legalnumber, for example<TTCLASS="VARNAME">CYGNUM_LIBC_TIME_STD_DEFAULT_OFFSET</TT>. </P></LI><LI><P>There would no replacement for a <TTCLASS="LITERAL">booldata</TT> optionfor which <TTCLASS="LITERAL">0</TT> is a valid value. Again some additional<SPANCLASS="APPLICATION">CDL</SPAN> syntax would be needed to express such a concept.</P></LI></OL><P>Although initially it may seem confusing that an option's value hasboth a boolean and a data part, it is an accurate reflection of howconfiguration options actually work. The various alternatives wouldall make it harder to write <SPANCLASS="APPLICATION">CDL</SPAN> scripts.</P><P>The next common suggestion is that the data part of a value should betyped in much the same way as C or C++ data types. For example itshould be possible to describe<TTCLASS="VARNAME">CYGNUM_LIBC_STDIO_BUFSIZE</TT> as an integer value,rather than imposing <SPANCLASS="PROPERTY">legal_values</SPAN> constraints. Again there are verygood reasons why this approach was not taken:</P><P></P><OLTYPE="1"><LI><P>The possible legal values for an integer are rarely correct for a<SPANCLASS="APPLICATION">CDL</SPAN> option. A constraint such as<TTCLASS="LITERAL">1 to 0x7fffffff</TT> is a bit more accurate,although if this option indicates a buffer size it is still notparticularly good — very few targets will have enoughmemory for such a buffer. Forcing <SPANCLASS="APPLICATION">CDL</SPAN> writers to list the<SPANCLASS="PROPERTY">legal_values</SPAN> constraints explicitly should make them think a bitmore about what values are actually sensible. For example<TTCLASS="VARNAME">CYGNUM_LIBC_TIME_DST_DEFAULT_OFFSET</TT> has legalvalues in the range <TTCLASS="LITERAL">-90000 to 90000</TT>,which helps the user to set a sensible value.</P></LI><LI><P>Not all options correspond to simple data types such as integers.<TTCLASS="VARNAME">CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE</TT> is a C string,and would have to be expressed using something like<TTCLASS="LITERAL">char []</TT>. This introduces plenty ofopportunities for confusion, especially since square brackets may getprocessed by the <SPANCLASS="APPLICATION">Tcl</SPAN> interpreter for command substitution.</P></LI><LI><P>Some configuration options can get very complicated indeed, forexample the default value of<TTCLASS="VARNAME">CYGDAT_UITRON_TASK_INITIALIZERS</TT> is:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">CYG_UIT_TASK( "t1", 1, task1, &stack1, CYGNUM_UITRON_STACK_SIZE ), \CYG_UIT_TASK( "t2", 2, task2, &stack2, CYGNUM_UITRON_STACK_SIZE ), \ CYG_UIT_TASK( "t3", 3, task3, &stack3, CYGNUM_UITRON_STACK_SIZE ), \CYG_UIT_TASK( "t4", 4, task4, &stack4, CYGNUM_UITRON_STACK_SIZE )</PRE></TD></TR></TABLE><P>This would require <SPANCLASS="APPLICATION">CDL</SPAN> knowing about C macros, structures, arrays,static initializers, and so on. Adding such detailed knowledge aboutthe C language to the component framework is inappropriate.</P></LI><LI><P><SPANCLASS="APPLICATION">CDL</SPAN> needs to be usable with languages other than C. At present thisincludes C++, in future it may include languages such as Java. Eachlanguage adds new data types and related complications, for exampleC++ classes and inheritance. Making <SPANCLASS="APPLICATION">CDL</SPAN> support a union of all datatypes in all possible languages is not sensible.</P></LI></OL><P>The <SPANCLASS="APPLICATION">CDL</SPAN> approach of treating all data as a sequence of characters,possibly constrained by a <SPANCLASS="PROPERTY">legal_values</SPAN> property or other means, hasthe great advantage of simplicity. It also fits in with the <SPANCLASS="APPLICATION">Tcl</SPAN>language that underlies <SPANCLASS="APPLICATION">CDL</SPAN>.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="SECT3"><H3CLASS="SECT3"><ANAME="LANGUAGE.VALUES.VALUE.EXAMPLES">Some Examples</H3><P>The following excerpt from the C library's <SPANCLASS="APPLICATION">CDL</SPAN> scripts can be usedto illustrate how values and flavors work in practice:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_component CYGPKG_LIBC_RAND { flavor none compile stdlib/rand.cxx cdl_option CYGSEM_LIBC_PER_THREAD_RAND { requires CYGVAR_KERNEL_THREADS_DATA default_value 0 } cdl_option CYGNUM_LIBC_RAND_SEED { flavor data legal_values 0 to 0x7fffffff default_value 1 } cdl_option CYGNUM_LIBC_RAND_TRACE_LEVEL { flavor data legal_values 0 to 1 default_value 0 }}</PRE></TD></TR></TABLE><P>If the application does not require any C library functionality thenit is possible to have a configuration where the C library is notloaded. This can be achieved by starting with the minimal template, orby starting with another template such as the default one and thenexplicitly unloading the C library package. If this package is notloaded then any references to the <TTCLASS="VARNAME">CYGPKG_LIBC_RAND</TT>component or any of its options will have a value of<TTCLASS="LITERAL">0</TT> for the purposes of expression evaluation. No<TTCLASS="LITERAL">#define's</TT> will be generated for the component orany of its options, and the file <TTCLASS="FILENAME">stdlib/rand.cxx</TT>will not get compiled. There is nothing special about the C libraryhere, exactly the same would apply for say a device driver that doesnot correspond to any of the devices on the target hardware.</P><P>Assuming the C library is loaded, the next thing to consider iswhether or not the component and its options are active. The componentis layered immediately below the C library package itself, so if thepackage is loaded then it is safe to assume that the package is alsoenabled. Therefore the parent of <TTCLASS="VARNAME">CYGPKG_LIBC_RAND</TT>is active and enabled, and in the absence of any <SPANCLASS="PROPERTY">active_if</SPAN>properties <TTCLASS="VARNAME">CYGPKG_LIBC_RAND</TT> will be active as well.</P><P>The component <TTCLASS="VARNAME">CYGPKG_LIBC_RAND</TT> has the flavor<TTCLASS="LITERAL">none</TT>. This means the component cannot be disabled.Therefore all the options in this component have an active and enabledparent, and in the absence of any <SPANCLASS="PROPERTY">active_if</SPAN> properties they are allactive as well.</P><P>The component's flavor <TTCLASS="LITERAL">none</TT> serves to grouptogether all of the configuration options related to random numbergeneration. This is particularly useful in the context of thegraphical configuration tool, but it also helps when it comes tonaming the options: all of the options begin with<TTCLASS="LITERAL">CYGxxx_LIBC_RAND</TT>, giving a clear hint about boththe package and the component within that package. The flavor meansthat the component is always enabled and has the value<TTCLASS="LITERAL">1</TT> for the purposes of expression evaluation. Therewill always be a single <TTCLASS="LITERAL">#define</TT> of the form:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYGPKG_LIBC_RAND 1</PRE></TD></TR></TABLE><P>In addition the file <TTCLASS="FILENAME">stdlib/rand.cxx</TT> will alwaysget built. If the component had the default <TTCLASS="LITERAL">bool</TT>flavor then users would be able to disable the whole component,and one less file would need to be built. However random numbergeneration is relatively simple, so the impact on eCos build times aresmall. Furthermore by default the code has no dependencies on otherparts of the system, so compiling the code has no unexpected sideeffects. Even if it was possible to disable the component, thesensible default for most applications would still leave it enabled.The net result is that the flavor <TTCLASS="LITERAL">none</TT> is probablythe most sensible one for this component. For other components thedefault <TTCLASS="LITERAL">bool</TT> flavor or one of the other flavorsmight be more appropriate.</P><P>Next consider option <TTCLASS="VARNAME">CYGSEM_LIBC_PER_THREAD_RAND</TT>which can be used to get a per-thread random number seed, possiblyuseful if the application needs a consistent sequence of randomnumbers. In the absence of a <SPANCLASS="PROPERTY">flavor</SPAN> property this option will beboolean, and the <SPANCLASS="PROPERTY">default_value</SPAN> property means that it is disabled bydefault — reasonable since few applications need thisparticular functionality, and it does impose a constraint on the restof the system. If the option is left disabled then no<TTCLASS="LITERAL">#define</TT> will be generated, and if there were any<SPANCLASS="PROPERTY">compile</SPAN> or similar properties these would not take effect. If theoption is enabled then a <TTCLASS="LITERAL">#define</TT> will be generated,using the option's data part which is fixed at <TTCLASS="LITERAL">1</TT>:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYGSEM_LIBC_PER_THREAD_RAND 1</PRE></TD></TR></TABLE><P>The <TTCLASS="VARNAME">CYGSEM_LIBC_PER_THREAD_RAND</TT> option has a<SPANCLASS="PROPERTY">requires</SPAN> constraint on<TTCLASS="VARNAME">CYGVAR_KERNEL_THREADS_DATA</TT>. If the C library optionis enabled then the constraint should be satisfied, or else theconfiguration contains a conflict. If the configuration does notinclude the kernel package then<TTCLASS="VARNAME">CYGVAR_KERNEL_THREADS_DATA</TT> will evaluate to<TTCLASS="LITERAL">0</TT> and the constraint is not satisfied. Similarly ifthe option is inactive or disabled the constraint will not besatisfied.</P><P><TTCLASS="VARNAME">CYGNUM_LIBC_RAND_SEED</TT> and<TTCLASS="VARNAME">CYGNUM_LIBC_RAND_TRACE_LEVEL</TT> both have the<TT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -