Re: C++ -> XSL -> XML -> XSL -> C++

From: Ira Baxter (idbaxter_at_semdesigns.com)
Date: 10/16/04


Date: Sat, 16 Oct 2004 16:46:31 -0500


"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:u3NNGAblEHA.3544@TK2MSFTNGP15.phx.gbl...
> Mark Jerde wrote:
> > I'm working with an XML-based "Assertion Definition Language" (ADL)
> > for testing software. As I've worked with the language it seems to
> > me the ADL is essentially a verbose subset of C++. To prove or
> > disprove that the ADL is a subset of C++ I'd like to have a pair of
> > XSL transforms that convert one form to the other. ISTM this sort of
> > thing has to have been done before but Googling hasn't found it yet.
> > This useful article solves half the problem but it would save a lot
> > of time if I could find a complete round-trip example. ;-)
> >
> > http://www.cuj.com/documents/s=8017/cuj0201georgesc/

If the assertion language is rich enough, it must of course include
a significant subset of C++: after all, you'll have to refer to arbitrary
data element, meaning arbitrary access paths and expressions.

If the assertion language is interesting enough, it will have to include
things that you can't say directly in C++. Typical example,
if you can supply pre and postcontions, you have to at least
refer, in the postcondition statement, to values that existed
as the precondition time. More interesting, you want to be
able to state various existential properties ("All data structures
that point *to* the returned result pass predicate P),
and various temporal properties ("eventually this allocated
buffer gets released").

So, the assertion langauge overlaps with that of C++.

That means to write an assertion, you don't want to do it in XML
(a C++ expression encoded in XML is an enormous pain in the ---).

You can't write it directly in C++ either, because the extra richness you
need.

> XSL really can't do the C++ -> XML conversion, since the input to XSL must
> already be XML. That's probably why you haven't seen any round-trip
> solutions.
>
> You'd have to use compiler/parser techniques to do the C++ -> XML
> conversion, while XSL could do the XML -> C++ conversion.

You could do this. But I contend what you want to do is to "extend"
C++ with the additional operators, and teach your compiler about them.
(A cheap trick is to put testing assertions in comments, thus the compiler
doesn't notice them at all). Then you need a full C++ front end
to parse that text, and extract the test assertions.

One set of machinery that could be used for this is our
DMS Software Reengineering Toolkit. It has a full
C++ front end usable for custom tasks.
See http://www.semanticdesigns.com/Products/FrontEnds/CppFrontend

-- 
Ira D. Baxter, Ph.D., CTO   512-250-1018
Semantic Designs, Inc.      www.semdesigns.com


Relevant Pages

  • Re: Cpp Considered Harmful
    ... arraythrows an exception for you if x is out of ... In a C language, you have the option to either cross your fingers ... provide an assertion that only compiles without NDEBUG activated. ... formats the expression's value as a string. ...
    (comp.lang.cpp)
  • Re: Question about Spanish
    ... It suggests that the language is somehow ... where is the data to support your assertion in the ... Or is this a case of PC dogma first, scientific evidence ... to use degrading vocabulary of fellow humans. ...
    (sci.lang)
  • Re: Son du tonnerre
    ... On ne retrouve nulle part cette assertion. ... the language of the Internet plus international ...
    (sci.physics)
  • Re: Rephrase - Could you sod off Spinoza
    ... Here p is the assertion that "C is a programming language" and q is ... programs written for older and noncompliant compilers are never ...
    (comp.programming)
  • Re: Son du tonnerre
    ... On ne retrouve nulle part cette assertion. ... the language of the Internet plus international ...
    (sci.physics)