c2hal: Comment out lone declarations.
Test: `make c2hal` and examine the result for c2hal/test/test.h
Change-Id: I1a72ecaddf6215b94bd76f3e8b09ed6def9aadcc
diff --git a/c2hal/AST.cpp b/c2hal/AST.cpp
index f803cc1..e2ae13c 100644
--- a/c2hal/AST.cpp
+++ b/c2hal/AST.cpp
@@ -21,8 +21,10 @@
#include "Scope.h"
#include "Declaration.h"
#include "CompositeDeclaration.h"
+#include "VarDeclaration.h"
#include "Define.h"
#include "Include.h"
+#include "Note.h"
#include <string>
#include <algorithm>
@@ -85,6 +87,13 @@
}
void AST::setDeclarations(std::vector<Declaration *> *declarations) {
+ // on the top level, no var declarations are allowed.
+ for(size_t i = 0; i < declarations->size(); i++) {
+ if(declarations->at(i)->decType() == VarDeclaration::type()) {
+ declarations->at(i) = new Note(declarations->at(i));
+ }
+ }
+
mDeclarations = declarations;
}
@@ -336,4 +345,4 @@
return mOutputDir;
}
-} // namespace android
\ No newline at end of file
+} // namespace android
diff --git a/c2hal/Note.cpp b/c2hal/Note.cpp
index 947c1ea..292bb79 100644
--- a/c2hal/Note.cpp
+++ b/c2hal/Note.cpp
@@ -22,22 +22,37 @@
: Declaration(name)
{}
-Note::~Note() {}
+Note::Note(Declaration *decl)
+ : Declaration(""),
+ mDecl(decl)
+ {}
+
+Note::~Note() {
+ if(mDecl) {
+ delete mDecl;
+ }
+}
void Note::generateSource(Formatter &out) const {
out.setLinePrefix("//");
out << "NOTE:\n";
out.indent();
- out << getName();
+ if(mDecl) {
+ mDecl->generateSource(out);
+ } else {
+ out << getName();
+ }
out.unindent();
out.unsetLinePrefix();
out << "\n";
}
-void Note::processContents(AST &) {
- // nothing to do
+void Note::processContents(AST &ast) {
+ if (mDecl) {
+ mDecl->processContents(ast);
+ }
}
-} //namespace android
\ No newline at end of file
+} //namespace android
diff --git a/c2hal/Note.h b/c2hal/Note.h
index 7870191..ebdcd49 100644
--- a/c2hal/Note.h
+++ b/c2hal/Note.h
@@ -30,6 +30,8 @@
*/
struct Note : Declaration {
Note(const std::string &name);
+ // assume ownership on decl
+ Note(Declaration *decl);
~Note();
static std::string type() { return "note"; }
@@ -39,7 +41,7 @@
void processContents(AST &ast) override;
private:
- std::string mExpression;
+ Declaration *mDecl = nullptr;
DISALLOW_COPY_AND_ASSIGN(Note);
};