summaryrefslogtreecommitdiff
path: root/src/declare.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-07-04 13:23:21 +0700
committerAdrian Thurston <thurston@colm.net>2018-07-04 13:23:21 +0700
commit00b1dd7777079036321afb8b3dcff0a229815517 (patch)
tree74f4d3acf8c043b03b1182e0453659cd8dca4f8a /src/declare.cc
parente87efd2f55958dc4f915890091ecf436d33d8c4f (diff)
downloadcolm-00b1dd7777079036321afb8b3dcff0a229815517.tar.gz
reusing stream impls when parsing from 'input'
To detect parsing from a top level input and to avoid appending it to a parser's top level (thus creating a tree), added a new type for input so we can replace the parser's top level. This change forces us to a two level structure where stream seq is at the top and stream data underneath. Requires us to hack the destructor so that we don't multiple delete the stream impl.
Diffstat (limited to 'src/declare.cc')
-rw-r--r--src/declare.cc39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/declare.cc b/src/declare.cc
index 0bd98e8b..b2efc2b0 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -38,6 +38,7 @@ void Compiler::initUniqueTypes( )
uniqueTypeIgnore = new UniqueType( TYPE_TREE, ignoreLangEl );
uniqueTypeAny = new UniqueType( TYPE_TREE, anyLangEl );
+ uniqueTypeInput = new UniqueType( TYPE_STRUCT, inputSel );
uniqueTypeStream = new UniqueType( TYPE_STRUCT, streamSel );
uniqeTypeMap.insert( uniqueTypeNil );
@@ -761,7 +762,7 @@ void Compiler::addMatchText( ObjectDef *frame, LangEl *lel )
void Compiler::addInput( ObjectDef *frame )
{
/* Make the type ref. */
- TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeStream );
+ TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeInput );
/* Create the field and insert it into the map. */
ObjectField *el = ObjectField::cons( internal,
@@ -842,6 +843,19 @@ void Compiler::declareStrFields( )
addLengthField( strObj, IN_STR_LENGTH );
}
+void Compiler::declareInputField( ObjectDef *objDef, code_t getLength )
+{
+ /* Create the "length" field. */
+ TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeStr );
+ ObjectField *el = ObjectField::cons( internal,
+ ObjectField::InbuiltFieldType, typeRef, "tree" );
+ el->isConst = true;
+ el->inGetR = IN_GET_COLLECT_STRING;
+ el->inGetValR = IN_GET_COLLECT_STRING;
+
+ objDef->rootScope->insertField( el->name, el );
+}
+
void Compiler::declareStreamField( ObjectDef *objDef, code_t getLength )
{
/* Create the "length" field. */
@@ -855,6 +869,28 @@ void Compiler::declareStreamField( ObjectDef *objDef, code_t getLength )
objDef->rootScope->insertField( el->name, el );
}
+void Compiler::declareInputFields( )
+{
+ inputObj = inputSel->structDef->objectDef;
+
+ initFunction( uniqueTypeStr, inputObj, ObjectMethod::Call, "pull",
+ IN_INPUT_PULL_WV, IN_INPUT_PULL_WC, uniqueTypeInt, false );
+
+ initFunction( uniqueTypeStr, inputObj, ObjectMethod::Call, "push",
+ IN_INPUT_PUSH_WV, IN_INPUT_PUSH_WV, uniqueTypeAny, false );
+
+ initFunction( uniqueTypeStr, inputObj, ObjectMethod::Call, "push_ignore",
+ IN_INPUT_PUSH_IGNORE_WV, IN_INPUT_PUSH_IGNORE_WV, uniqueTypeAny, false );
+
+ initFunction( uniqueTypeStr, inputObj, ObjectMethod::Call, "push_stream",
+ IN_INPUT_PUSH_STREAM_WV, IN_INPUT_PUSH_STREAM_WV, uniqueTypeStream, false );
+
+ initFunction( uniqueTypeVoid, inputObj, ObjectMethod::Call, "close",
+ IN_INPUT_CLOSE_WC, IN_INPUT_CLOSE_WC, false );
+
+ declareInputField( inputObj, 0 );
+}
+
void Compiler::declareStreamFields( )
{
streamObj = streamSel->structDef->objectDef;
@@ -1536,6 +1572,7 @@ void Compiler::declarePass()
declareIntFields();
declareStrFields();
+ declareInputFields();
declareStreamFields();
declareTokenFields();
declareGlobalFields();