Giter Site home page Giter Site logo

Treatment of #define about dstep HOT 7 CLOSED

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024
Treatment of #define

from dstep.

Comments (7)

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024

DStep doesn't currently handle anything from the preprocessor at all.

from dstep.

russel avatar russel commented on July 2, 2024

So how does dstep get the 4 for the "char[4] a" if it hasn't at least remembered the value of LENGTH in some way?

from dstep.

UplinkCoder avatar UplinkCoder commented on July 2, 2024

dstep does not.
clang does run the preprocessor.

I do not think it is a good idea to handle preprocessor stuff in step...
it is best left to clang

from dstep.

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024

So how does dstep get the 4 for the "char[4] a" if it hasn't at least remembered the value of LENGTH in some way?

It just calls the libclang function clang_getArraySize.

from dstep.

mihails-strasuns avatar mihails-strasuns commented on July 2, 2024

@russel it is important to remember that in C pre-processing and compiling are done in two completely separate steps. By the time source code gets to compiler (and thus to dstep which is built on top of libclang) it already looks like char[4] a with all macros expanded.

To do what you want one needs to either plug into preprocessor and pass some state to compiler parser from it or write your own C pre-processor which replaces numeric defines with enum instead of doing actual text substitution. Or something similar.

from dstep.

russel avatar russel commented on July 2, 2024

@Dicebot Ah, OK, crucial bit of information: DStep is working on the abstract syntax tree form of the code not the source itself. Sounds like a pre-pre-processor which converted #defines into either inline functions or constexpr values would be needed to solve the problem I have here.

from dstep.

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024

@Dicebot Clang retains the full source information, that's the whole point of Clang. They tried create tools based GCC but it was difficult/impossible because it did not retain the complete source information. For example, the parser did some forms of const folding. Something like const int a = 3 + 1; looked like const int a = 4; in the AST.

The necessary information should be available in Clang. When I started with DStep libclang did not have an API to interact with the preprocessor. It still doesn't, but I recently noticed that they provide a translation unit flag CXTranslationUnit_DetailedPreprocessingRecord that seems to be interesting.

from dstep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.