Skip to content

Commit d15d0a4

Browse files
Stamps for mathematical optrations, to be used while building ASTree
1 parent 9b88053 commit d15d0a4

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

blobstamper/blobstamper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
#include "galley.h"
2525
#include "stamp_enumerator.h"
2626
#include "stamp_lottery.h"
27+
#include "stamp_math_op.h"

blobstamper/stamp_lottery.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*
1717
******************************************************************************/
1818

19+
#ifndef STAMP_LOTTERY_H
20+
#define STAMP_LOTTERY_H
21+
1922
template<class StampT> class StampLottery: public StampT
2023
{
2124
protected:
@@ -225,3 +228,5 @@ StampLottery<StampT>::Append(StampT & stamp)
225228
stamps.push_back(stamp);
226229
oracle_size = init_oracle_size(stamps);
227230
}
231+
232+
#endif // STAMP_LOTTERY_H

blobstamper/stamp_math_op.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
******************************************************************************/
18+
19+
#include <string>
20+
#include"stamp_math_op.h"
21+
22+
std::string
23+
StampMathUnaryOp::ExtractStr(Blob &blob)
24+
{
25+
return op_name + "(" + stamp.ExtractStr(blob) + ")";
26+
}
27+
28+
29+
std::string
30+
StampMathBinaryOp::ExtractStr(Blob &blob)
31+
{
32+
std::vector<Blob> blobs = extract_internal(blob);
33+
return (std::string)"(" + stamp1.ExtractStr(blobs[0]) + " "+ op_name + " " + stamp2.ExtractStr(blobs[1]) + ")";
34+
}
35+

blobstamper/stamp_math_op.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
******************************************************************************/
18+
19+
#ifndef STAMP_MATH_OP_H
20+
#define STAMP_MATH_OP_H
21+
22+
#include"blob.h"
23+
#include"stamp.h"
24+
#include"galley.h"
25+
26+
27+
class StampMathUnaryOp: public StampBaseStr
28+
{
29+
protected:
30+
std::string op_name;
31+
StampBaseStr &stamp;
32+
public:
33+
virtual std::string ExtractStr(Blob &blob) override;
34+
StampMathUnaryOp(std::string arg_op_name, StampBaseStr& arg_stamp) : op_name(arg_op_name), stamp(arg_stamp) {};
35+
virtual int maxSize() override {return -1;};
36+
virtual int minSize() override {return stamp.minSize();};
37+
};
38+
39+
40+
41+
class StampMathBinaryOp: public StampBaseStr, public GalleySetBase
42+
{
43+
protected:
44+
std::string op_name;
45+
StampBaseStr &stamp1;
46+
StampBaseStr &stamp2;
47+
public:
48+
virtual std::string ExtractStr(Blob &blob) override;
49+
StampMathBinaryOp(std::string arg_op_name, StampBaseStr& arg_stamp1, StampBaseStr& arg_stamp2) :
50+
GalleySetBase({arg_stamp1, arg_stamp2}),
51+
op_name(arg_op_name),
52+
stamp1(arg_stamp1),
53+
stamp2(arg_stamp2) {};
54+
virtual int maxSize() override {return -1;};
55+
56+
};
57+
58+
#endif // STAMP_MATH_OP_H

0 commit comments

Comments
 (0)