Skip to content

Commit

Permalink
XX
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Nov 5, 2023
1 parent bbdd8a1 commit 2e8e485
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 78 deletions.
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Default",
"includePath": [
"${default}",
"packages/debug-mgr/src/include",
"src/include",
"tests/src",
"build/zsp_ast/src/include"
Expand Down
3 changes: 2 additions & 1 deletion src/MarkerCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ MarkerCollector::~MarkerCollector() {
}

void MarkerCollector::marker(const IMarker *m) {
fprintf(stderr, "NOTE: Add marker \"%s\" with level %d\n", m->msg().c_str(), m->severity());
fprintf(stdout, "NOTE: Add marker \"%s\" with level %d\n", m->msg().c_str(), m->severity());
m_markers.push_back(IMarkerUP(m->clone()));
m_count[static_cast<uint32_t>(m->severity())]++;
fflush(stdout);
}

bool MarkerCollector::hasSeverity(MarkerSeverityE s) {
Expand Down
94 changes: 94 additions & 0 deletions src/TaskResolveEnumRef.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* TaskResolveEnumRef.cpp
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#include "dmgr/impl/DebugMacros.h"
#include "TaskResolveEnumRef.h"


namespace zsp {
namespace parser {


TaskResolveEnumRef::TaskResolveEnumRef(IFactory *factory) {
DEBUG_INIT("zsp::parser::TaskResolveEnumRef", factory->getDebugMgr());

}

TaskResolveEnumRef::~TaskResolveEnumRef() {

}

ast::ISymbolRefPath *TaskResolveEnumRef::resolve(
ISymbolTableIterator *scope,
const ast::IExprId *id) {
DEBUG_ENTER("resolve");
m_scope = scope;
m_id = id;
m_ref = 0;

for (std::vector<ast::IScopeChild *>::const_iterator
it=scope->getScope()->getChildren().begin();
it!=scope->getScope()->getChildren().end(); it++) {
(*it)->accept(m_this);
}

DEBUG_LEAVE("resolve");
return m_ref;
}

void TaskResolveEnumRef::visitSymbolEnumScope(ast::ISymbolEnumScope *i) {
DEBUG_ENTER("visitSymbolEnumScope %s (looking for %s)",
i->getName().c_str(),
m_id->getId().c_str());
std::map<std::string, int32_t>::const_iterator it =
i->getSymtab().find(m_id->getId());
if (it != i->getSymtab().end()) {
DEBUG("Found symbol %s", m_id->getId().c_str());
m_ref = m_scope->getScopeSymbolPath();

m_ref->getPath().push_back({
ast::SymbolRefPathElemKind::ElemKind_ChildIdx,
i->getId()
});

m_ref->getPath().push_back({
ast::SymbolRefPathElemKind::ElemKind_ChildIdx,
it->second
});
DEBUG("Path");
for (std::vector<ast::SymbolRefPathElem>::const_iterator
it=m_ref->getPath().begin();
it!=m_ref->getPath().end(); it++) {
DEBUG(" Elem: %d", it->idx);
}
fflush(stdout);
}
for (std::vector<ast::IScopeChild *>::const_iterator
it=i->getChildren().begin();
it!=i->getChildren().end(); it++) {
(*it)->accept(m_this);
}
DEBUG_LEAVE("visitSymbolEnumScope %s", i->getName().c_str());
}

dmgr::IDebug *TaskResolveEnumRef::m_dbg = 0;

}
}
53 changes: 53 additions & 0 deletions src/TaskResolveEnumRef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* TaskResolveEnumRef.h
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#pragma once
#include "zsp/parser/IFactory.h"
#include "zsp/ast/impl/VisitorBase.h"

namespace zsp {
namespace parser {



class TaskResolveEnumRef : public virtual ast::VisitorBase {
public:
TaskResolveEnumRef(IFactory *factory);

virtual ~TaskResolveEnumRef();

ast::ISymbolRefPath *resolve(
ISymbolTableIterator *scope,
const ast::IExprId *id);

void visitSymbolEnumScope(ast::ISymbolEnumScope *i);

private:
static dmgr::IDebug *m_dbg;
const ast::IExprId *m_id;
const ISymbolTableIterator *m_scope;
ast::ISymbolRefPath *m_ref;

};

}
}


69 changes: 2 additions & 67 deletions src/TaskResolveRootRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "dmgr/impl/DebugMacros.h"
#include "zsp/ast/IPackageImportStmt.h"
#include "TaskResolveRootRef.h"
#include "TaskResolveEnumRef.h"


namespace zsp {
Expand Down Expand Up @@ -62,24 +63,6 @@ ast::ISymbolRefPath *TaskResolveRootRef::resolve(
return m_ref;
}

void TaskResolveRootRef::visitEnumDecl(ast::IEnumDecl *i) {
DEBUG_ENTER("visitEnumDecl");
for (std::vector<ast::IEnumItemUP>::const_iterator
it=i->getItems().begin();
it!=i->getItems().end(); it++) {
DEBUG("Enum Item: %s", (*it)->getName()->getId().c_str());
if ((*it)->getName()->getId() == m_id->getId()) {
DEBUG("Found!!");
break;
}
}
DEBUG_LEAVE("visitEnumDecl");
}

void TaskResolveRootRef::visitEnumItem(ast::IEnumItem *i) {

}

void TaskResolveRootRef::visitSymbolScope(ast::ISymbolScope *i) {
DEBUG_ENTER("visitSymbolScope id=%s (%s)",
m_id->getId().c_str(), i->getName().c_str());
Expand All @@ -91,7 +74,7 @@ void TaskResolveRootRef::visitSymbolScope(ast::ISymbolScope *i) {

// Now, add in the child element that we just found
m_ref->getPath().push_back({ast::SymbolRefPathElemKind::ElemKind_ChildIdx, it->second});
} else if ((m_ref=searchEnums(i, m_id))) {
} else if ((m_ref=TaskResolveEnumRef(m_factory).resolve(m_scope.get(), m_id))) {
// Found in this scope
} else if (m_search_imp && i->getImports() && (m_ref=searchImports(m_id, i->getImports()))) {
// Found in imports
Expand All @@ -100,41 +83,6 @@ void TaskResolveRootRef::visitSymbolScope(ast::ISymbolScope *i) {
DEBUG_LEAVE("visitSymbolScope");
}

void TaskResolveRootRef::visitSymbolEnumScope(ast::ISymbolEnumScope *i) {
DEBUG_ENTER("visitSymbolEnumScope %s (looking for %s)",
i->getName().c_str(),
m_id->getId().c_str());
std::map<std::string, int32_t>::const_iterator it =
i->getSymtab().find(m_id->getId());
if (it != i->getSymtab().end()) {
DEBUG("Found symbol %s", m_id->getId().c_str());
m_ref = m_scope->getScopeSymbolPath();

m_ref->getPath().push_back({
ast::SymbolRefPathElemKind::ElemKind_ParamIdx,
i->getIndex()
});

m_ref->getPath().push_back({
ast::SymbolRefPathElemKind::ElemKind_ParamIdx,
it->second
});
DEBUG("Path");
for (std::vector<ast::SymbolRefPathElem>::const_iterator
it=m_ref->getPath().begin();
it!=m_ref->getPath().end(); it++) {
DEBUG(" Elem: %d", it->idx);
}
fflush(stdout);
}
for (std::vector<ast::IScopeChild *>::const_iterator
it=i->getChildren().begin();
it!=i->getChildren().end(); it++) {
(*it)->accept(m_this);
}
DEBUG_LEAVE("visitSymbolEnumScope %s", i->getName().c_str());
}

void TaskResolveRootRef::visitSymbolExecScope(ast::ISymbolExecScope *i) {
DEBUG_ENTER("visitSymbolExecScope");

Expand Down Expand Up @@ -258,19 +206,6 @@ ast::ISymbolRefPath *TaskResolveRootRef::searchImport(
return ret;
}

ast::ISymbolRefPath *TaskResolveRootRef::searchEnums(
ast::ISymbolScope *i,
const ast::IExprId *id) {
DEBUG_ENTER("searchEnums %s", id->getId().c_str());
for (std::vector<ast::IScopeChild *>::const_iterator
it=i->getChildren().begin();
it!=i->getChildren().end(); it++) {
(*it)->accept(m_this);
}
DEBUG_LEAVE("searchEnums %s", id->getId().c_str());
return 0 /*m_ref*/;
}

dmgr::IDebug *TaskResolveRootRef::m_dbg = 0;

}
Expand Down
10 changes: 0 additions & 10 deletions src/TaskResolveRootRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ class TaskResolveRootRef : public ast::VisitorBase {
const ISymbolTableIterator *scope,
const ast::IExprId *id);

virtual void visitEnumDecl(ast::IEnumDecl *i) override;

virtual void visitEnumItem(ast::IEnumItem *i) override;

virtual void visitSymbolScope(ast::ISymbolScope *i) override;

virtual void visitSymbolEnumScope(ast::ISymbolEnumScope *i) override;

virtual void visitSymbolExecScope(ast::ISymbolExecScope *i) override;

virtual void visitSymbolTypeScope(ast::ISymbolTypeScope *i) override;
Expand All @@ -65,10 +59,6 @@ class TaskResolveRootRef : public ast::VisitorBase {
const ast::IExprId *id,
ast::IPackageImportStmt *imp);

ast::ISymbolRefPath *searchEnums(
ast::ISymbolScope *i,
const ast::IExprId *id);

private:
static dmgr::IDebug *m_dbg;
IMarkerUP m_marker;
Expand Down

0 comments on commit 2e8e485

Please sign in to comment.