# Copyright (c) Meta Platforms, Inc. and affiliates. schema csharp.1 { import src predicate Name: string # Lower case normalized names (for case-insensive search) predicate NameLowerCase: { nameLowercase: string , name: Name, } stored { prim.toLower Str, N } where N = Name Str predicate FullName: { name: Name , containingNamespace: Namespace } predicate Namespace: { name: Name , containingNamespace: maybe Namespace } # Represents a symbol (namespace, class, method, parameter, etc.) exposed by the # compiler (https://fburl.com/g1qzaga9) type Definition = { type: AType | method: Method | field: Field | parameter: Parameter | typeParameter: TypeParameter | local: Local | property: Property } # Represents a type (https://fburl.com/c0eftyms) type AType = { arrayType: ArrayType | namedType: NamedType | functionPointerType: FunctionPointerType | pointerType: PointerType | typeParameter: TypeParameter } # Represents a type other than an array, a pointer, a type parameter # (https://fburl.com/9sh8231c) type NamedType = { class_: Class | interface_: Interface | record_: Record | struct_: Struct } predicate Class: { name: FullName , baseType: maybe Class , typeParameters: [TypeParameter] , containingType: maybe NamedType , declaredAccessibility: Accessibility , isAbstract: bool , isStatic: bool , isSealed: bool } predicate Interface: { name: FullName , typeParameters: [TypeParameter] , containingType: maybe NamedType , declaredAccessibility: Accessibility , isStatic: bool } predicate Implements: { type: NamedType , interface_: Interface } predicate Record: { name: FullName , baseType: maybe Record , typeParameters: [TypeParameter] , containingType: maybe NamedType , declaredAccessibility: Accessibility , isAbstract: bool , isSealed: bool } predicate Struct: { name: FullName , typeParameters: [TypeParameter] , containingType: maybe NamedType , declaredAccessibility: Accessibility } # Enumeration for common accessibility combinations (https://fburl.com/bu2zzj2k) type Accessibility = enum { Friend | Internal | NotApplicable | Private | Protected | ProtectedAndFriend | ProtectedAndInternal | ProtectedOrFriend | ProtectedOrInternal | Public } # Represents a method or method-like symbol (including constructor, destructor, # operator, or property/event accessor) (https://fburl.com/n0hrd48z) predicate Method: { name: Name , containingType: NamedType , typeParameters: [TypeParameter] , parameters: [Parameter] , isStatic: bool , returnType: AType , declaredAccessibility: Accessibility } # Enumeration for possible kinds of method symbols # (https://fburl.com/yiw81ctn) type MethodKind = enum { AnonymousFunction | BuiltinOperator | Constructor | Conversion | DeclareMethod | DelegateInvoke | Destructor | EventAdd | EventRaise | EventRemove | ExplicitInterfaceImplementation | FunctionPointerSignature | LambdaMethod | LocalFunction | Ordinary | PropertyGet | PropertySet | ReducedExtension | SharedConstructor | StaticConstructor | UserDefinedOperator } # Represents a parameter of a method or property (https://fburl.com/1vhc37sw) predicate Parameter: { name: Name , type: AType , refKind: RefKind , isThis: bool , isParams: bool , isOptional: bool } # Denotes the kind of reference (https://fburl.com/t5jo5fe2) type RefKind = enum { In | None_ | Out | Ref | RefReadOnly } # An enumeration declaring the kinds of variance supported for generic type parameters (https://fburl.com/op4cyu1z) type Variance = enum { In | None_ | Out } # Represents a field in a class, struct or enum (https://fburl.com/s0t65fue) predicate Field: { name: Name , type: AType , containingType: NamedType , declaredAccessibility: Accessibility , isConst: bool , isReadonly: bool , isVirtual: bool } # Represents an array (https://fburl.com/u86l8jp9) predicate ArrayType: { elementType: AType , rank: byte } # Represents a pointer type such as "int *". Pointer types are used only in # unsafe code (https://fburl.com/rwnza2j5) predicate PointerType: { pointedAtType: AType } # Represents a function pointer type such as "delegate*" # (https://fburl.com/kx4v0t2w) predicate FunctionPointerType: { name: FullName , signature: Method } # Represents a type parameter in a generic type or generic method # (https://fburl.com/pt267xpp) predicate TypeParameter: { name: Name , variance: maybe Variance , hasNotNullConstraint: bool , hasReferenceTypeConstraint: bool , hasValueTypeConstraint: bool } # Represents a local variable in method body (https://fburl.com/ebmq9edn) predicate Local: { name: Name , type: AType , containingMethod: Method , refKind: RefKind , isConst: bool } # Represents a property or indexer (https://fburl.com/051tvt5t) predicate Property: { name: Name , containingType: NamedType , type: AType , parameters: [Parameter] , getMethod: maybe Method , setMethod: maybe Method , isStatic: bool , isIndexer: bool } type Location = { fileLocation: src.FileLocation , fileLines: src.FileLines } predicate DefinitionLocation: { definition: Definition , location: Location } predicate ObjectCreationLocation: { type: AType , constructor: Method , location: Location } predicate MethodInvocationLocation: { method: Method , location: Location , expression: maybe MethodInvocationExpression } type MethodInvocationExpression = { memberAccess: MemberAccessLocation } predicate MemberAccessLocation: { expression: MemberAccessExpression , location: Location } type MemberAccessExpression = { local: Local | parameter: Parameter | field: Field | property: Property | method: Method } predicate TypeLocation: { type: AType , location: Location } # A Horizon Unity platform package, e.g. apps/horizon # C# class: https://fburl.com/code/qwzlquxw # Wiki: https://fburl.com/wiki/bho3z437 predicate UnityPackage: { type: UnityPackageType , name: string } # Horizon Unity platform package type # C# PackageType enum: https://fburl.com/code/6bmqh86k # Wiki: https://fburl.com/wiki/bho3z437 type UnityPackageType = enum { Undefined | ThirdParty | Core | Runtime | Modules | Worlds | Apps | Clones | TestPackages } # FAST project-generator assembly-definition (asmdef) type # C# AssemblyDefinition.Type enum: https://fburl.com/code/d6jyrwd4 # Wiki: https://fburl.com/wiki/f4ju7ntu type UnityAssemblyType = enum { Package | Editor | Tests | TestsEditor | UnitTests | Internal | AllApis } # Uniquely identifies one of the projects generated by a given configuration of the FAST project-generator. # # One configuration of the project-generator (i.e. {package, assemblyType, projectTemplate}) may generate multiple # projects, i.e. there may be multiple facts for this predicate that differ only by projectBasename. # # The FAST project-generator ensures that the generated project's filenames are unique, so the information recorded # by this predicate is sufficient to both reconstruct the configuration of the project-generator, and to # single out one of the generated projects. predicate UnityProjectSource: { projectBasename: string # The basename (filename and extension) of the generated project , unityPackage: UnityPackage # Horizon Unity platform package type , assemblyType: UnityAssemblyType # FAST project-generator asmdef type , projectTemplate: src.File # A template file that exists in the repository } # An MSBuild project file (.csproj) that exists in the repository predicate MSBuildProjectSource: { src: src.File } # The information required to locate or generate an MSBuild project type ProjectSource = { unityProjectSource: UnityProjectSource | msbuildProjectSource: MSBuildProjectSource } # A "design time" MSBuild project, i.e. one that has been evaluated by MSBuild # for a given configuration, on a given host platform, with all conditions evaluated, # and imported projects expanded. predicate Project: { source: ProjectSource , platformTarget: maybe string , targetFramework: maybe string , sdk: maybe string , outputType: maybe string , assemblyName: maybe string , rootNamespace: maybe string } predicate UnityPackageToProject: { unityPackage: UnityPackage , project: Project } stored { Pkg, Proj } where Project { source = { unityProjectSource = { unityPackage = Pkg } } } = Proj; # Records that a given (fully-evaluated) MSBuild project included a given C# source file predicate ProjectToSourceFile: { project: Project , src: src.File } predicate SourceFileToProject: { src: src.File , project: Project } stored { Src, Proj } where ProjectToSourceFile { project = Proj, src = Src }; # An MSBuild solution file (.sln) that exists in the repository predicate Solution: { src: src.File } # Records that a given solution file includes a given project. We don't currently generate # any solution files predicate SolutionToProject: { solution: Solution , project: Project } predicate ProjectToSolution: { project: Project , solution: Solution } stored { Proj, Sln } where SolutionToProject { solution = Sln, project = Proj }; # # codemarkup compatibility layer # # some aliases for shorter names # # Re-index for file lookup # # file -> defn predicate FileDefinitions: { file: src.File, defn: Definition } stored { File, Defn } where DefinitionLocation { Defn, { fileLocation = Loc } }; { file = File } = Loc; # defn -> file, span , name predicate DefinitionLocationName: { decl: Definition, file: src.File, span: src.ByteSpan, name: string, } { Defn, File, Span, NameStr } where ( { type = TDefn } = Defn; { namedType = ADefn } = TDefn; # not all things have names yet ( { class_ = { name = FullName } } | { interface_ = { name = FullName } } | { record_ = { name = FullName } } | { struct_ = { name = FullName } } ) = ADefn; { name = Name } = FullName ) | ( ( { method = MDefn } = Defn; { name = Name } = MDefn ) | ( { field = FDefn } = Defn; { name = Name } = FDefn ) | ( { parameter = PDefn } = Defn; { name = Name } = PDefn ) | ( { typeParameter = PDefn } = Defn; { name = Name } = PDefn ) | ( { local = LDefn } = Defn; { name = Name } = LDefn ) | ( { property = PDefn } = Defn; { name = Name } = PDefn ); ); csharp.Name NameStr = Name; DefinitionLocation { Defn, { fileLocation = { File, Span }} }; # xrefs predicate FileEntityXRefs: { file: src.File, use: src.ByteSpan, target: csharp.Definition } stored { File, Span, Defn } where ( MethodInvocationLocation { MDefn, { fileLocation = SrcLoc }, _ }; { method = MDefn } = Defn; ) | ( ObjectCreationLocation { AType, _, { fileLocation = { File, Span }} }; { type = AType } = Defn; ) | ( MemberAccessLocation { expression = Expr, location = { fileLocation = SrcLoc } }; ( { local = Local } = Expr; { local = Local } = Defn ) | ( { parameter = Param } = Expr; { parameter = Param } = Defn ) | ( { field = Field } = Expr; { field = Field } = Defn ) | ( { property = Prop } = Expr; { property = Prop } = Defn ) | ( { method = Method } = Expr; { method = Method } = Defn ); ) | ( TypeLocation { AType, { fileLocation = { File, Span }} }; { type = AType } = Defn; ); { File, Span } = SrcLoc; # search # find definitions knowing the local identifier name predicate SearchByName: { name: Name, defn: Definition } { Name, Defn } where # things that use FullNames ( QName = csharp.FullName { name = Name }; TDefn = ( CDefn = Class { name = QName }; { class_ = CDefn } : NamedType ) | ( IDefn = Interface { name = QName }; { interface_ = IDefn } ) | ( RDefn = Record { name = QName }; { record_ = RDefn } ) | ( SDefn = Struct { name = QName }; { struct_ = SDefn } ); { type = { namedType = TDefn } } = Defn; # things that use Name only ) | ( MDefn = Method { name = Name }; { method = MDefn } = Defn ) | ( PDefn = Parameter { name = Name }; { parameter = PDefn } = Defn ) | ( FDefn = Field { name = Name }; { field = FDefn } = Defn ) | ( TDefn = TypeParameter { name = Name }; { typeParameter = TDefn } = Defn ) | ( LDefn = Local { name = Name }; { local = LDefn } = Defn ) | ( PDefn = Property { name = Name }; { property = PDefn } = Defn ) }