The CMake documentation on generator expressions is fairly clear that "A common mistake is to try to split a generator expression across multiple lines with indenting". Here is the example they give:
# WRONG: New lines and spaces all treated as argument separators, so the
# generator expression is split and not recognized correctly.
target_compile_definitions(tgt PRIVATE
$<$<AND:
$<CXX_COMPILER_ID:GNU>,
$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,5>
>:HAVE_5_OR_LATER>
)
My experience is that using multiple lines with indenting works exactly as I'd hope. For example, the following code produces the exact results I would naively expect with the use of whitespace and indentation:
target_compile_options(common_interface INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:
/W4 # Turn on warnings
/WX # Turn warnings into errors
>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:
-Wall # Turn on warnings
-Wextra # Turn on warnings
-Werror # Turn warnings into errors
>
)
As I understand the CMake documentation, each line here would be added as a separate compile option (e.g., $<$<CXX_COMPILER_ID:MSVC>:), but that is clearly not the case since the generated build files show the flags come through correctly.
My questions are:
What am I missing? Is the issue only with certain types of expressions (e.g., logical operators)? Has the behavior changed and the documentation is out of date? or maybe the documentation needs to be enhanced to clarify the restrictions and expected behavior?
Is it safe to continue using whitespace and indentation in some circumstances?
My suspicion is that the resulting true_string (or false_string in $<IF:condition,true_string,false_string>) of a conditional expression may contain whitespace, but the other arguments of an expression cannot be broken.
Tsyvarev's comments to the question are on the money, but I'll give a more formal answer as both one of the CMake maintainers and the author of the generator expression documentation you linked to. The TLDR version is "The docs describe what you can rely on. Don't rely on implementation details that are outside that and which may change.".
The documentation makes clear where you are required to use quoting to ensure robust behavior. Splitting a genex across multiple lines or whitespace has never been officially supported. Sometimes it might appear to work, but that is by coincidence, not by design. Just because you found a case that happens to work in some range of CMake versions, you shouldn't assume that is supported behavior, especially when the documentation now explicitly calls that out as unsupported. There is no promise that such unsupported behavior will continue to work in future releases.
To be absolutely clear, the direct answers to your questions are:
What am I missing? Is the issue only with certain types of expressions (e.g., logical operators)? Has the behavior changed and the documentation is out of date? or maybe the documentation needs to be enhanced to clarify the restrictions and expected behavior?
The documentation is up to date, and I don't know how to make things clearer than what the existing documentation already says. You're asking about things that go directly against that documentation. The aspects you're asking about are not things we intend to document because they are specifically not intended to be supported behavior! Furthermore, CMake's behavior in this area may well have changed over different versions, but it has never been promised to be stable, since it has never been part of CMake's documented API.
Is it safe to continue using whitespace and indentation in some circumstances?
No. The current documentation should make it very clear what's safe and what isn't. If you're asking if something that contradicts that documentation is safe, well, it should hopefully be clear that my answer is still "No". ;)
Footnote
People failing to quote their generator expressions has been one of the most frequently reported problems (or more accurately, the cause of reported problems) in the CMake forums and issue tracker. It kept biting people over and over, to the point where I wrote a Quoting In CMake blog article about quoting in general and I also added the Whitespace And Quoting section to the generator expressions manual in the official CMake docs (that update appeared with CMake 3.24).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
What I am trying to do is setup Visual Studio 2017 Enterprise to have it help me keep track of my code architecture better. I am running on Windows 8.1 if that makes any difference. An example will (hopefully) demonstrate what I mean:
If I want to use the sine function, Visual Studio insists that I pre-pend Math. in front of it: Rise = Math.sin(Angle)
What I want to do is have the same behavior for libraries that I have created. I have created a class called K2Math (called out as Public Class K2Math) and in it are functions like: Public Shared Function CheckForCollinear( . . . ) as Boolean. I have bundled it up into a separate DLL.
In my caller code, in the project references I have a reference to K2Math.DLL. As the functions are Public Shared, I don't have to use 'New K2Math' setup call like I would with a more conventional DLL. However, in the caller program I can use the CheckForCollinear function without having to pre-pend K2Math. I can also call it using K2Math.CheckForCollinear and the compiler doesn't complain.
What I would like the compiler to do is complain and force me to pre-pend the K2Math. This would help to make it obvious to me or whoever is reading my code how the code is architected and segregated.
But I can't seem to figure out how to do that. Also, I haven't figured out how to succinctly pose the question to do a proper Google search.
If I am being unclear, please so note that and I'll try to clear things up.
Create a Library lets say CustomizedMathLibrary
In that create a class K2Math. WRAP in a NAME SPACE (This is important)
Build and Use It by Importing name space in your code.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Is there a simple explanation for why the latex / pdflatex compiler is funky in the following two ways:
1) N multiple compiles are necessary until you reach a "steady state" version. N seems to grow up to around 5 or 6 if I use many packages and references.
2) Error messages are almost always worthless. The actual error is not flagged. Example:
\begin{itemize} % Line 499
\begin{enumerate}
% Comment: error: forgot to close the enumerate block
\item This is a bullet point.
\end{itemize} % Line 503
result: "Error on line 1 while scanning \begin{document}", not very useful.
I realize there is a separate "tex exchange" but I'm wondering if someone knowledgeable about c++, java, or other compilers can provide some insight on how those seem to support single-compile and proper error localization.
Edit: this document seems like a rant justifying the hacks in latex's implementation, but what about latex's syntax/language properties make the weird implementation necessary? http://tug.org/texlive/Contents/live/texmf-dist/doc/generic/knuth/tex/tex.pdf
From a LaTeX point of view:
You should at most require 3 (...maybe 4) to reach a steady state. This depends not on the number of packages, but possible layout changes within your document. Layout changes cause references to move, and these references need to be correct (hence the recompile until they don't move).
Nesting of environments is allowed (although this does not address your problem directly). Also, macro definitions act as replacement text for your input. So, even though you write \end{itemize}, it is actually transformed into a bunch of other/different (primitive) macros, removing the obvious-to-humans structure and consequently also the bizarre error message. That's why some of the error messages are difficult to interpret.
wrt. point (2):
Considering that most of the errors are picked up while parsing macro defenitions that get expanded, My guess is that errors wouldn't be useful to the user even if they contained locale and specific causes, because they don't translate well into what you see when you view the code.
Still, it would be useful if they were just a little bit more explicit :/
Since upgrading from 4.7 to ECC6 the ABAP compiler has become a lot stricter on the use of certain statements in the OO context.
For instance you're not allowed to use the statement LIKE, but in stead have to use TYPE and internal tables does not have an implicit header line, etc.
These restrictions are explained in greater detail here
MY QUESTION: To what extent does this restriction affect your existing code-base?.
We have over a thousand "Classes" written since 1998 in OO as far as it was available at the time. For the most part each class is its own include in SE38, with the class definition and implementation together in this include.
Up to now, we could successfully change and activate these classes as long as the main program was pre-existing in 4.7. Now we are trying to use one of these older classes in a new main program for regression test purposes, and we are getting the following error:
"Within classes and interfaces, you can only use "TYPE" to refer to ABAP Dictionary types (not "LIKE" or "STRUCTURE")."
This error is valid as per the current definition of the SAP language.
I would like to know wheter the SAP interpreter continues to run old code with obsolete statements intentionally, or whether a future patch may correct this "feature" and cause these classes to stop compiling.
Each development object is tagged with a version corresponding to the SAP version it was developed on. You can see this in version management or table VRSD.
As I understand it, that is there specifically so that code with statements that have been made illegal in later versions will survive an upgrade and continue to run.
This is why, when you attach an include developed in 4.5b to a class that was developed in NW700, it won't compile. The compiler knows that this is new dev, and its applying the rules accordingly.
The ABAP community has been informed for a really long time (years) that LIKEs, work areas, RANGEs etc. are obsolete.
I don't think SAP will kill any old code, but I wouldn't count on it if I were in charge.
So can they cause it to stop compiling: yes, will they: probably not.
I am dabbling in PHP and getting my feet wet browsing SO, and feel compelled to ask a question that I've been wondering about for years:
When you write an entirely new programming language, what do you write it in?
It's to me a perplexing chicken & egg thing to me. What do you do? Say to yourself Today I'm going to invent a new language! and then fire up. Notepad? Are all compilers built on previously existing languages, such that were one to bother one could chart all programming languages ever devised onto one monstrous branching tree that eventually grounded out at... I don't know, something old?
It's not a stupid question. It's an excellent question.
As already answered the short answer is, "Another language."
Well that leads to some interesting questions? What if its the very first language written for
your particular piece of hardware? A very real problem for people who work on embedded devices. As already answered "a language on another computer". In fact some embedded devices will never get a compiler, their programs will always be compiled on a different computer.
But you can push it back even further. What about the first programs ever written?
Well the first compilers for "high level languages" would have been written in whats called "assembly language". Assembly language is a language where each instruction in the language corresponds to a single instruction to the CPU. Its very low level language and extremely verbose and very labor intensive to write in.
But even writing assembly language requires a program called an assembler to convert the assembly language into "machine language". We go back further. The very first assemblers were written in "machine code". A program consisting entirely of binary numbers that are a direct one-to-one correspondence with the raw language of the computer itself.
But it still doesn't end. Even a file with just raw numbers in it still needs translation. You still need to get those raw numbers in a file into the computer.
Well believe it or not the early computers had a row of switches on the front of them. You flipped the switches till they represented a binary number, then you flicked another switch and that loaded that single number into the computers memory. Then you kept going flicking switched until you had loaded a minimal computer program that could read programs from disk files or punch cards. You flicked another switch and it started the program running. When I went to university in the 80's I saw computers that had that capacity but never was given the job of loading in a program with the switches.
And even earlier than that computer programs had to be hard wired with plug boards!
The most common answer is C. Most languages are implemented in C or in a hybrid of C with callbacks and a "lexer" like Flex and parser generator like YACC. These are languages which are used for one purpose - to describe syntax of another language. Sometimes, when it comes to compiled languages, they are first implemented in C. Then the first version of the language is used to create a new version, and so on. (Like Haskell.)
A lot of languages are bootstrapped- that is written in themselves. As to why you would want to do this, it is often a good idea to eat your own dogfood.
The wikipedia article I refer to discusses the chicken and egg issue. I think you will find it quite interesting.
Pretty much any language, though using one suited to working with graphs and other complex data structures will make many things easier. Production compilers are often written in C or C++ for performance reasons, but languages such as OCaml, SML, Prolog, and Lisp are arguably better for prototyping the language.
There are also several "little languages" used in language design. Lex and yacc are used for specifying syntax and grammars, for example, and they compile to C. (There are ports for other languages, such as ocamllex / ocamlyacc, and many other similar tools.)
As a special case, new Lisp dialects are often built on existing Lisp implementations, since they can piggyback on most of the same infrastructure. Writing a Scheme interpreter can be done in Scheme in under a page of code, at which point one can easily add new features.
Fundamentally, compilers are just programs that read in something and translate it to something else - converting LaTeX source to DVI, converting C code to assembly and then to machine language, converting a grammar specification to C code for a parser, etc. Its designer specifies the structure of the source format (parsing), what those structures mean, how to simplify the data (optimizing), and the kind of output to generate. Interpreters read the source and execute it directly. (Interpreters are typically simpler to write, but much slower.)
"Writing a new programming language" technically doesn't involve any code. It's just coming up with a specification for what your language looks like and how it works. Once you have an idea of what your language is like, you can write translators and interpreters to actually make your language "work".
A translator inputs a program in one language and outputs an equivalent program in another language. An interpreter inputs a program in some language and runs it.
For example, a C compiler typically translates C source code (the input language) to an assembly language program (the output language). The assembler then takes the assembly language program and produces machine language. Once you have your output, you don't need the translators to run your program. Since you now have a machine language program, the CPU acts as the interpreter.
Many languages are implemented differently. For example, javac is a translator that converts Java source code to JVM bytecode. The JVM is an interpreter [1] that runs Java bytecode. After you run javac and get bytecode, you don't need javac anymore. However, whenever you want to run your program, you'll need the JVM.
The fact that translators don't need to be kept around to run a program is what makes it possible to "bootstrap" your language without having it end up running "on top of" layers and layers of other languages.
[1] Most JVMs do translation behind the scenes, but they're not really translators in that the interface to the JVM is not "input language -> output language".
Actually you can write in almost any language you like to. There's nothing that prevents you from writing a C compiler in Ruby. "All" you have to do is parse the program and emit the corresponding machine code. If you can read/write files, your programming language will probably suffice.
If you're starting from scratch on a new platform, you can do cross-compiling: write a compiler for your new platform, that runs in Java or natively on x86. Develop on your PC and then transfer the program to your new target platform.
The most basic compilers are probably Assembler and C.
Generally you can use just about whatever language you like. PHP was written in C, for example. If you have no access to any compiler whatsoever, you're going to have to resort to writing assembly language and compiling it to machine code by hand.
Many languages were first written in another available language and then reimplemented in itself and bootstrapped that way (or just kept the implementation in the foreign language, like PHP and perl), but some languages, like the first assembler was hand compiled to machine code like the first C-compiler was hand compiled to assembly.
I've been interested in bootstrapping ever since I read about it. To learn more I tried doing it myself by writing my own superset of BF, which i called EBF, in itself. the first version of EBF had 3 extra primitives and I hand compiled the first binary. I found a two step rhythm when doing so. I implemented a feature in the current language in one release and had a sweet release where I rewrote the code to utilize the implemented feature. The language was expressive enough to be used to make a LISP interpreter.
I have the hand compiled version together with the source in the first release tag and the code is quite small. The last version is 12 times bigger in size and the code and allows for more compact code so hand compiling the current version would be hard to get right.
Edmund Grimley Evans did something similar with his HEX language
One of the interesting things about doing this yourself is that you understand why some things are as they are. My code was product if small incremental adjustments an it looks more like it has evolved rather than been designed from scratch. I keep that in mind when reading code today which I think looks a little off.
Usually with a general-purpose programming language suitable for systems development, e.g. C, Haskell, ML, Lisp, etc., but the list of options is long. Also, usually with some domain-specific languages for language implementation, i.e. parser and lexical analyzer generators, intermediate languages like LLVM, etc. And probably some shell scripts, testing frameworks, and a build configuration system, e.g. autoconf.
Most compiler were wriiten C or a c like program if not c then assembly lang is the way to go However when writing a new lang from scratch and you do not have a macro lib or source code from a prototype language you have to define your own functions Now in What Language? You can just write a Form "of source code called psedocode to the machine it looks like a bnf grammar from the object oriented structured lang spec like Fortran basic algo lisp. So image writing a cross code resembling any of these language syntax That's psedo code
What are programming languages in general?
programming languages are a just a way to talk to computers. roughly speaking at first because computers could only understand zeros and ones (due to the fact that computers are made of transistors as switches which could only take two states, we call these two states 0 and 1) and working with 0,1 was hard for us as humans so computer scientists decided to do a one-to-one mapping from every instruction in binary(0,1) to a more human readable form which they called it assembly language.
for example if we had an instruction like:
11001101
in assembly it would be called:
LOAD_A 15
which means that load the content of register a into memory location 15. as i said it was just a convention like choosing 0 and 1 for two states of the transistors or anything else in the computer.in this way having a program with 50 instructions , remembering the assembly language would be easier . so the user would write the assembly code and some program (assembler in this case) would translate the codes to binary instructions or machine language as they call it.
but then with the computers getting improved every day there was room for more complicated programs with more instructions, say 10000.
in this case a one-to-one mapping like assembly wouldn't work, so other high level programming languages were created. they said for example if for a relation with I/O devices for printing something on the screen created by the user takes about 80 instructions , let us do something in here and we could package all this code into one library and call it for example printf and also create another program which could translate this printf in here to the related assembly code and from there the assembly would do the rest. so they call it compiler.
so now every user who wants to just print something on the screen he wouldn't have to write all the instructions in binary or assembly he just types printf("something") and all the programs like the compiler and assembler would do the rest. now later other longer codes would be packaged in the same way to just facilitate the work of other people as you see that you could just simplify a thousands line of code into one code in python and pack it for the use of other people.
so let's say that you have packed a lot of different codes in python and created a module(libray, package or anything that you want to call it) and you call that module mgh(just my name). now let's say we have created this mgh somehow that any one who says:
import mgh
mgh.connect(ip,port.data)...
could easily connect to a remote server with the ip and port number specified and send the data afterwards(or something like that). now people could do all of it using one single line, but what that happens is that a lot of codes are getting executed which have been retrieved from the mgh file. and packaging it has not been for speeding up the process of execution but rather facilitating other programmers works. so in here if someone wants to use your code first he should import the file and then the python interpreter would recognize all the code in it and so it could interpret the code.
now if you want to create a programming language and you want to execute it , first it needs a translation, for example let's say that you create a program which could understand the syntax and convert it to c , in this case after it has been translated to c , the rest would be taken care of , by the c compiler , then assembler , linker, ... .
even though you would have to pay the price of being slower since it has to be converted to c first.
now one other thing that you could do is to create a program which could translate all the code to the equivalent assembly language just like what happens with c but in this case the program could do it directly and from there the rest would be done by the linker. we know that this program is called compiler.
so what i am talking about is that, the only code that the system understands is 0,1 , so somehow you should convert you syntax to that, now in our operating systems a lot of different programs like assembler, linker and ... have been created to tell you that if you could convert your code to assembly they could take care of the rest or as i said you could even use other programming languages compilers by converting your code to that language.
Even further binary ,or assembly operations must be translated into functions, thats the assemblers/compilers job, then into object,from data and functions, if you don't have a source file to see" how these objects functionality should be represented in your language implementation ,Then you have to recognize "see" implement, or define your own functions ,procedures, and data structures, Which requires a lot of knowledge, you need to ask yourself what is a function.Your mind then becomes the language simulation.This Separate a Master programmer from the rest.
I too had this question few months back. And I read few articles and watched some videos which helped me to start writing my own language called soft. Its not complete yet but I learned a lot of stuff from this journey.
Basic things you should know is how compiler works when it has to execute a code snippet. Compiler has a lot of phases like lexical analysis, semantic analyzer, AST(Abstract Syntax Tree) etc.
What I did in my new language can be found here - http://www.singhajit.com/writing-a-new-programming-language/
If you are writing a language for first time then all the best and you have a long way to go.