Platform system, used to customize the behavior of the compiler.

Customisation is done accordingly to the target platform. Also detects conflicts between targeted platforms.

Introduced classes

class Platform

nitc :: Platform

Sub-classes of Platform represent the target platform of a compilation
private class PlatformPhase

nitc :: PlatformPhase

Redefined classes

redef class MModule

nitc :: platform $ MModule

A Nit module is usually associated with a Nit source file.
redef class ToolContext

nitc :: platform $ ToolContext

Global context for tools

All class definitions

redef class MModule

nitc :: platform $ MModule

A Nit module is usually associated with a Nit source file.
class Platform

nitc $ Platform

Sub-classes of Platform represent the target platform of a compilation
private class PlatformPhase

nitc $ PlatformPhase

redef class ToolContext

nitc :: platform $ ToolContext

Global context for tools
package_diagram nitc::platform platform nitc\>modelize\> modelize nitc::platform->nitc\>modelize\> nitc::parser_util parser_util nitc::platform->nitc::parser_util nitc nitc nitc\>modelize\>->nitc nitc\>parser\> parser nitc::parser_util->nitc\>parser\> nitc::toolcontext toolcontext nitc::parser_util->nitc::toolcontext ...nitc ... ...nitc->nitc ...nitc\>parser\> ... ...nitc\>parser\>->nitc\>parser\> ...nitc::toolcontext ... ...nitc::toolcontext->nitc::toolcontext nitc::c_compiler_options c_compiler_options nitc::c_compiler_options->nitc::platform nitc::abstract_compiler abstract_compiler nitc::abstract_compiler->nitc::platform nitc::java java nitc::java->nitc::c_compiler_options nitc::java... ... nitc::java...->nitc::java nitc::separate_compiler separate_compiler nitc::separate_compiler->nitc::abstract_compiler nitc::global_compiler global_compiler nitc::global_compiler->nitc::abstract_compiler nitc::light light nitc::light->nitc::abstract_compiler nitc::memory_logger memory_logger nitc::memory_logger->nitc::abstract_compiler nitc::compiler_serialization compiler_serialization nitc::compiler_serialization->nitc::abstract_compiler nitc::android android nitc::android->nitc::abstract_compiler nitc::emscripten emscripten nitc::emscripten->nitc::abstract_compiler nitc::xcode_templates xcode_templates nitc::xcode_templates->nitc::abstract_compiler nitc::separate_compiler... ... nitc::separate_compiler...->nitc::separate_compiler nitc::global_compiler... ... nitc::global_compiler...->nitc::global_compiler nitc::light... ... nitc::light...->nitc::light nitc::memory_logger... ... nitc::memory_logger...->nitc::memory_logger nitc::compiler_serialization... ... nitc::compiler_serialization...->nitc::compiler_serialization nitc::android... ... nitc::android...->nitc::android nitc::emscripten... ... nitc::emscripten...->nitc::emscripten nitc::xcode_templates... ... nitc::xcode_templates...->nitc::xcode_templates

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module annotation

nitc :: annotation

Management and utilities on annotations
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module literal

nitc :: literal

Parsing of literal values in the abstract syntax tree.
module loader

nitc :: loader

Loading of Nit source files
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module mmodule_data

nitc :: mmodule_data

Define and retrieve data in modules
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module modelize_class

nitc :: modelize_class

Analysis and verification of class definitions to instantiate model element
module modelize_property

nitc :: modelize_property

Analysis and verification of property definitions to instantiate model element
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module modelize

nitc :: modelize

Create a model from nit source files
module parser_util

nitc :: parser_util

Utils and tools related to parsers and AST

Children

module abstract_compiler

nitc :: abstract_compiler

Abstract compiler
module c_compiler_options

nitc :: c_compiler_options

Offers the annotations cflags and ldflags to specify

Descendants

module a_star-m

a_star-m

module android

nitc :: android

Compile program for the Android platform
module compiler

nitc :: compiler

Compilation to C
module compiler_ffi

nitc :: compiler_ffi

Full FFI support for the compiler
module compiler_serialization

nitc :: compiler_serialization

Serialization support for the compiler
module dynamic_loading_ffi

nitc :: dynamic_loading_ffi

Execute FFI code by creating and loading shared libraries
module emscripten

nitc :: emscripten

Compile to JavaScript using the Emscripten SDK
module extra_java_files

nitc :: extra_java_files

Intro the annotation extra_java_files to compile extra java files
module ffi

nitc :: ffi

Full FFI support, independent of the compiler
module global_compiler

nitc :: global_compiler

Global compilation of a Nit program
module interpreter

nitc :: interpreter

Interpretation of Nit programs
module ios

nitc :: ios

Compile programs for the iOS platform
module java

nitc :: java

FFI support for the Java language
module light

nitc :: light

Light FFI support for the compiler
module light_only

nitc :: light_only

Compiler support for the light FFI only, detects unsupported usage of callbacks
module memory_logger

nitc :: memory_logger

Extension to inject memory-tracing instrumentation in code generated by nitc.
module nit

nitc :: nit

A naive Nit interpreter
module nitc

nitc :: nitc

A Nit compiler
module nith

nitc :: nith

A ligHt Nit compiler
module on_demand_compiler

nitc :: on_demand_compiler

Compiles extern code within a module to a static library, as needed
module separate_compiler

nitc :: separate_compiler

Separate compilation of a Nit program
module separate_erasure_compiler

nitc :: separate_erasure_compiler

Separate compilation of a Nit program with generic type erasure
module test_astbuilder

nitc :: test_astbuilder

Program used to test the clone method of the astbuilder tool
module xcode_templates

nitc :: xcode_templates

Templates and other services to create XCode projects
# Platform system, used to customize the behavior of the compiler.
#
# Customisation is done accordingly to the target platform.
# Also detects conflicts between targeted platforms.
module platform

import modelize
private import parser_util
private import annotation

redef class ToolContext
	# Detects the `platform` annotation to set a mobile target platform
	var platform_phase: Phase = new PlatformPhase(self, [modelize_property_phase])

	# Get platform compilation settings from its `name`
	protected fun platform_from_name(name: String): nullable Platform
	do
		return null
	end
end

private class PlatformPhase
	super Phase

	redef fun process_annotated_node(nmoduledecl, nat)
	do
		var annotation_name = "platform"

		# Skip if we are not interested
		if nat.name != annotation_name then return

		# Do some validity checks and print errors if the annotation is used incorrectly
		var modelbuilder = toolcontext.modelbuilder
		if not nmoduledecl isa AModuledecl then
			modelbuilder.error(nat, "Syntax Error: only the declaration of modules may use `{annotation_name}`.")
			return
		end

		var args = nat.n_args
		var platform_name
		if args.length > 1 then
			modelbuilder.error(nat, "Syntax Error: `{annotation_name}` expects at most a single argument.")
			return
		else if args.is_empty then
			platform_name = nmoduledecl.n_name.collect_text
		else
			platform_name = args.first.as_string
			if platform_name == null then
				var format_error = "Syntax Error: `{annotation_name}` expects its argument to be the name of the target platform as a String literal."
				modelbuilder.error(nat, format_error)
				return
			end
		end

		var nmodule = nmoduledecl.parent.as(AModule)
		var mmodule = nmodule.mmodule

		var platform = toolcontext.platform_from_name(platform_name)
		if platform == null then
			toolcontext.error(nat.location, "Error: target platform `{platform_name}` unknown.")
			return
		end

		var previous_target_platform = mmodule.target_platform
		if previous_target_platform != null and previous_target_platform != platform then
			modelbuilder.error(nat, "Syntax Error: a target platform has already been defined as `{previous_target_platform}`.")
		end

		mmodule.local_target_platform = platform
	end
end

redef class MModule
	private var local_target_platform: nullable Platform = null

	# Recursively get the platform targeted by this module or imported modules
	fun target_platform: nullable Platform
	do
		var ltp = local_target_platform
		if ltp != null then return ltp

		for mmodule in in_importation.greaters do
			ltp = mmodule.local_target_platform
			if ltp != null then return ltp
		end

		return null
	end
end

# Sub-classes of `Platform` represent the target platform of a compilation
#
# Services will be added to this class in other modules.
class Platform

	# Simple lower-case name of the platform
	fun name: nullable String do return null

	# Does the platform provide and support the library `unwind`?
	fun supports_libunwind: Bool do return true

	# Does the platform provide and supports the Boehm's GC library?
	fun supports_libgc: Bool do return true

	# Does this platform declare its own main function? If so, we won't generate one in Nit.
	fun no_main: Bool do return false

	# Does the platform accepts linker scripts?
	fun supports_linker_script: Bool do return true
end
src/platform/platform.nit:15,1--124,3