Giter Site home page Giter Site logo

Comments (7)

AndreyG avatar AndreyG commented on July 28, 2024 1

Ok, let's add containing_file(). I'm definitely against name owning_module() firstly because of global module, and secondly because of partitions:

export module M;
export import :part1;
export import :part2;

export module M:part1;
export class X {};

export module M:part2;
export class Y {};

X and Y are attached to the same module M (i.e. M owns both of them), but containg_file() for them returns "part1.ixx" and "part2.ixx" respectively.

from ifc-reader.

AndreyG avatar AndreyG commented on July 28, 2024

If I understand your suggestion correctly, you are talking about method like Module owning_module() const. But I'm not sure how such method could be used?

from ifc-reader.

FireFlyForLife avatar FireFlyForLife commented on July 28, 2024

For me, it's to check if the given Declaration is fully visible from ModuleA where I'm generating code for.

Lets say there is a function like this:

bool is_module_imported_in_module(reflifc::Module to_check, reflifc::Module module_, ifc::Environment& environment, bool use_imported = true)
{
	if (to_check == module_) {
		return true;
	}

	if (use_imported) {
		for (auto imported_module : module_.imported_modules(environment)) {
			if (to_check == imported_module) {
				return true;
			}
		}
	}

	for (auto exported_module : module_.exported_modules(environment)) {
		if (is_module_imported_in_module(to_check, exported_module, environment, false)) {
			return true;
		}
	}

	return false;
}

With the added API owning_module(). I can use it to check if the decl is from a module that is fully exported:

bool is_decl_visible(reflifc::Declaration my_decl, reflifc::Module root_module) {
    const bool owning_module_visible = is_module_imported_in_module(my_decl.owning_module(), root_module, g_environment);
    const bool decl_self_visible = my_decl.specifiers() & yadayada;
    return owning_module_visible && self_visible;
}

This is my use case at the moment.

from ifc-reader.

AndreyG avatar AndreyG commented on July 28, 2024

Firstly, owning_module() makes sense only for declarations, but not for types. Secondly, what should owning_module() return for a declaration attached to global module? I suppose null?

from ifc-reader.

FireFlyForLife avatar FireFlyForLife commented on July 28, 2024

Maybe the wording is a bit confusing. But my understanding is that a ifc::File stores the types/decls & everything for 1 .ixx file. The global module fragments are still declared/included in that .ixx file and ends up in the ifc::File.

This is what I wanted to expose, which ifc::File the Decl/Type index belongs to. In this sense I was under the impression it made sense to also add owning_module() to Type and others.

Why do you say Types don't make sense to have a owning module?

from ifc-reader.

AndreyG avatar AndreyG commented on July 28, 2024

The global module fragments are still declared/included in that .ixx file and ends up in the ifc::File.

Right, but let's consider the following example

// ------ X.h ------
#pragma once

class X {};

// ----- M.ixx -----
module;
#include "X.h"
export module M;
export X g_x;
// `class X` is part exported from `M`, but it's attached not to module `M`, but to global module

// --- consumer.cpp ---
import M;
// `g_x` is visible here, but `X` is not

Why do you say Types don't make sense to have a owning module?

The only sort of types for which owning_module() makes sense is designated (which is plainly single declaration, see https://github.com/AndreyG/ifc-reader/blob/master/lib/core/include/ifc/Type.h#L98). But it doesn't make sense for all other sorts, i.e. Pointer/Reference/Array/QualifiedType/FunctionType/... and so on.

from ifc-reader.

FireFlyForLife avatar FireFlyForLife commented on July 28, 2024

I think you are right on the types point. It only makes sense for Declarations. From all of the related code I've written thus far that's the final thing I need to check for.

The Global Module fragment I'm not really worried about. It's still part of the same .ifc file as all the other declarations, they just have the BasicSpecifiers::IsMemberOfGlobalModule flag set.

To illustrate, say you have a reflifc::Module and you call .scope_declarations(), those declarations that are in the Global Module Fragment already show up anyway. So it makes sense to allow .owning_module() to make it symmetrical.

So my question now would be, would you be okay .owning_module() (or another name with the same functionality). for reflifc::Declaration and all the variations of it (eg, AliasDeclaration, ScopeDeclaration)?

from ifc-reader.

Related Issues (15)

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.