Scaffold classes for type and reference analysis

This commit is contained in:
Simon Binder 2019-06-23 14:44:28 +02:00
parent b0649ee208
commit 5d1046ba3a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
7 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import 'package:meta/meta.dart';
part 'schema/column.dart';
part 'schema/references.dart';
part 'schema/table.dart';
part 'types/data.dart';
part 'types/resolution.dart';
part 'types/typeable.dart';

View File

@ -0,0 +1,7 @@
part of '../analysis.dart';
class Column with Referencable, Typeable {
final String name;
Column(this.name);
}

View File

@ -0,0 +1,38 @@
part of '../analysis.dart';
/// Mixin for classes which represent a reference.
mixin ReferenceOwner {}
/// Mixin for classes which can be referenced by a [ReferenceOwner].
mixin Referencable {}
/// Class which keeps track of references tables, columns and functions in a
/// query.
class ReferenceScope {
final ReferenceScope parent;
final Map<String, Referencable> _references = {};
ReferenceScope(this.parent);
ReferenceScope createChild() {
return ReferenceScope(this);
}
void register(String identifier, Referencable ref) {
_references[identifier.toUpperCase()] = ref;
}
Referencable resolve(String name) {
var scope = this;
final upper = name.toUpperCase();
while (scope != null) {
if (scope._references.containsKey(upper)) {
return scope._references[upper];
}
scope = scope.parent;
}
return null; // not found in any parent scope
}
}

View File

@ -0,0 +1,8 @@
part of '../analysis.dart';
class Table with Referencable {
final String name;
final List<Column> columns;
Table({@required this.name, @required this.columns});
}

View File

@ -0,0 +1,23 @@
part of '../analysis.dart';
/// A type that sql expressions can have at runtime.
abstract class SqlType {}
class NullType extends SqlType {}
class IntegerType extends SqlType {}
class RealType extends SqlType {}
class TextType extends SqlType {}
class BlobType extends SqlType {}
/// Provides more precise hints than the [SqlType]. For instance, booleans are
/// stored as ints in sqlite, but it might be desirable to know whether an
/// expression will actually be a boolean.
abstract class TypeHint {}
class IsBoolean extends TypeHint {}
class IsDateTime extends TypeHint {}

View File

@ -0,0 +1,3 @@
part of '../analysis.dart';
class TypeResolutionState {}

View File

@ -0,0 +1,6 @@
part of '../analysis.dart';
/// Something that has a type.
mixin Typeable {
TypeResolutionState resolutionState;
}